Inspiration
Because I have seen people lose their lives because their medicine had no effect, I want to prove there is a solution. A diabetic patient's sugar level did not drop after taking insulin. Scans after chemotherapy showed no shrinkage in tumor size, but rather an increase in spread. This is due to the prevalence of drugs from unknown sources and smuggled medications. The application aims to prove that Artificial Intelligence can be used to help solve this widespread problem in Libya
What it does
SafeDose is a three-tier pharmaceutical security platform designed to combat counterfeit medicine The app connects Distributors, Pharmacies, and Patients through a unified, secure verification system.
For Distributors: Verified manufacturers register medicine batches to an immutable Firestore ledger, creating a "digital twin" for every physical product using its unique GTIN and serial number.
For Pharmacies: Pharmacists verify incoming shipments and mark medicines as "Sold" upon dispensing, preventing "Double-Scanning" attacks where counterfeiters reuse original packaging.
For Patients: A regular user can scan any medicine and receive instant verification. Beyond the barcode, SafeDose uses Gemini Vision AI to perform a "Visual Forensic" analysis—comparing the physical packaging in the user's photo against manufacturer designs to detect sophisticated counterfeits that a simple barcode check would miss. The AI also acts as a digital pharmacist, simplifying dosage instructions and translating labels into the user's native language.
How we built it
We built SafeDose Mobile app using Flutter for a cross-platform mobile experience and GetX for efficient state management and navigation. The secure backend is powered by Firebase, utilizing Firestore as an immutable ledger database and Firebase Auth with Google Sign-In for role-based access control (Distributor, Pharmacy, User).
The core innovation is the integration of the Gemini 2.5 Flash API. We send multi-modal prompts (text + image) to the model, asking it to perform a forensic comparison between the scanned barcode data, the ledger record, and the user's live photo. This allows us to detect visual discrepancies indicative of counterfeit packaging.
We also integrated the camera package for high-resolution photo capture and mobile_scanner for fast, reliable barcode detection supporting EAN-13, QR, and GS1 DataMatrix formats.
We built SafeDose Admin Web Interface using React + TypeScript with Vite for a fast, modern frontend experience. Firebase powers the backend, providing secure Google Authentication and a real-time Firestore database for managing distributors and pharmacies. The UI is fully responsive, crafted with CSS Modules and a premium design system featuring glassmorphism and gradient accents.
Challenges we ran into
Camera Resource Management: Managing concurrent camera access for the barcode scanner and the photo capture module was extremely challenging. We encountered persistent "BufferQueue has been abandoned" crashes when switching between screens. We solved this by implementing a strict lifecycle management system that pauses the camera preview before disposal and carefully sequences view mounting/unmounting with camera starts/stops.
Visual AI Reliability: Crafting the perfect prompt for Gemini to consistently detect subtle counterfeits (wrong font, slightly off colors) without generating false positives on legitimate products was an iterative process that required extensive testing and prompt engineering.
Role-Based Access Control: Ensuring that only verified distributors and pharmacies in the app could write to the ledger, while regular users could only read, required careful architectural planning in our Firestore security rules and authentication flow. Also for the web interface, the admin users are only allowed to manage distributor and pharmacy entities.
Accomplishments that we're proud of
We are most proud of creating a truly end-to-end solution that doesn't just verify a barcode but verifies the package. The combination of an immutable ledger with visual AI creates a security layer that is incredibly difficult for counterfeiters to bypass.
We also successfully implemented a complex, role-based multi-user system with distinct dashboards and permissions.
Finally, we are proud of the accessibility features we built for elderly users—including Text-to-Speech announcements of verification results and AI-powered label translation.
What we learned
Building SafeDose was a deep dive into global pharmaceutical security standards. We learned about initiatives like the EU Falsified Medicines Directive (FMD) and the US Drug Supply Chain Security Act (DSCSA), which mandate unique serial numbers on every medicine unit to enable end-to-end tracking. This "serialization" is the foundation of our GTIN-based ledger system.
On the product side, we learned that solving a real-world problem like counterfeit medicine requires understanding the entire supply chain, not just the end-user. This led us to design for Distributors and Pharmacies, not just patients.
We learned the power of multi-modal AI. Gemini's ability to reason across text and images opened up a verification paradigm that was simply not possible with previous technology.
What's next for SafeDose
Authority API Integration: We want to connect the "Report to Authorities" feature directly to official government health agency APIs (like the FDA or regional equivalents) for real-time reporting.
Offline Mode: To serve patients with limited connectivity, we are exploring on-device AI models for core verification features.
Built With
- auth)
- dart
- firebase-(auth-&-firestore)
- firebase-(firestore
- flutter
- getx
- google-gemini-2.5-flash-api
- gs1
- react
- typescript
- vite
Log in or sign up for Devpost to join the conversation.