QR code-based medicine traceability system to combat counterfeit drugs in Benin and West Africa. Features supply chain tracking, real-time fraud detection, and role-based access for distributors, pharmacies, and patients.
# MedTrace Benin
A QR code-based medicine traceability system to combat counterfeit drugs in Benin and West Africa.
## Features
- **QR code generation** — distributors register medicine batches and get unique per-unit QR codes
- **Instant verification** — anyone can scan a QR code to verify authenticity
- **Fraud detection** — multiple patient scans of the same code are flagged automatically
- **Supply chain tracking** — shipment status flows from distributor → pharmacy → patient
- **Role-based access** — admin, distributor, pharmacy, and patient roles
- **AI security insights** — Gemini-powered analysis of suspicious scan patterns (admin)
- **Admin user management** — activate/deactivate accounts
- **CSV export** — download QR code lists as CSV
## Tech Stack
| Layer | Technology |
|---|---|
| Frontend | React 19, TypeScript, Tailwind CSS, Vite |
| Backend | Node.js, Express, TypeScript |
| Database | SQLite (better-sqlite3) with versioned migrations |
| Auth | JWT via httpOnly cookies + bcrypt |
| Validation | Zod |
| Security | helmet, express-rate-limit, CORS |
| AI | Google Gemini (optional) |
| Testing | Vitest + supertest |
## Getting Started
### Prerequisites
- Node.js 20+
- npm
### Local Development
```bash
# 1. Install dependencies
npm install
# 2. Configure environment
cp .env.example .env
# Edit .env — set a strong JWT_SECRET and admin credentials
# 3. Start development server
npm run dev
```
The app runs at `
localhost`.
The default admin account is created from `.env` values on first run.
### Running Tests
```bash
npm test
```
### Production Build
```bash
npm run build
NODE_ENV=production npm start
```
### Docker
```bash
# Build and run with docker-compose
cp .env.example .env
# Edit .env with production values
docker-compose up -d
```
## Environment Variables
| Variable | Description | Required |
|---|---|---|
| `JWT_SECRET` | Secret for signing JWT tokens (use a long random string) | Yes |
| `ADMIN_EMAIL` | Admin accou …