Drug Inventory System
A simple, lightweight drug inventory management system for small charity veterinary clinics.
Tech Stack
- Backend: Python + FastAPI + Uvicorn + SQLite
- Frontend: Plain HTML, CSS, JavaScript (no frameworks)
- Database: SQLite (file-based, zero setup)
Features
✅ Add, edit, delete drugs
✅ Track quantities and units
✅ Low stock alerts
✅ Filter by inventory status
✅ Responsive design (works on desktop and mobile)
✅ Fast and lightweight
Quick Start (Docker - Recommended)
Everything runs in containers. Just make sure you have Docker and Docker Compose installed.
docker-compose up
That's it! Everything will start automatically:
- Frontend:
http://localhost(Nginx serving the UI) - Backend API:
http://localhost:8000(FastAPI) - API Docs:
http://localhost:8000/docs(Interactive Swagger UI) - Database: SQLite file at
./drugs.db(auto-created)
To stop:
docker-compose down
To rebuild after code changes:
docker-compose up --build
Project Structure
/drugs
/backend
/app
__init__.py # Database config
database.py # Database connection setup
models.py # SQLAlchemy models
main.py # FastAPI app and routes
requirements.txt # Python dependencies
Dockerfile # Container image
/frontend
index.html # Main page
styles.css # All styling
app.js # All JavaScript logic
docker-compose.yml # Run everything with Docker Compose
nginx.conf # Nginx config for frontend
API Endpoints
| Method | Endpoint | Description |
|---|---|---|
| GET | /drugs |
List all drugs |
| GET | /drugs/{id} |
Get specific drug |
| POST | /drugs |
Create new drug |
| PUT | /drugs/{id} |
Update drug |
| DELETE | /drugs/{id} |
Delete drug |
| GET | /drugs/low-stock |
Get low stock drugs |
Database
SQLite database is stored as drugs.db in the project root. It's a single file that persists between container restarts. You can:
- Backup by copying the file
- Share with team members
Configuration
Edit environment variables in docker-compose.yml:
environment:
- DATABASE_URL=sqlite:///./drugs.db
MQTT
The system includes an MQTT broker (Mosquitto) with WebSocket support:
- MQTT:
localhost:1883 - WebSocket:
localhost:9001or/mqttvia nginx
To create a new MQTT user with a custom password:
docker run --rm -v $(pwd)/mosquitto/config:/temp eclipse-mosquitto mosquitto_passwd -b /temp/pwfile username password
Then restart the containers:
docker compose restart mosquitto
Development
When you run docker-compose up, the backend automatically reloads when code changes (--reload flag). Just refresh your browser to see updates.
Production Deployment
For production:
- Disable
--reloadin docker-compose.yml command - Use a production WSGI server (e.g., Gunicorn)
- Add environment variables for security
- Use a managed database instead of SQLite if scaling
Future Enhancements
- User authentication & roles
- Audit log (who changed what and when)
- Export to CSV
- Barcode/QR code scanning
- Email alerts for low stock
- Multi-location support
- Mobile app