How prajwalmhetre/medilens-ai works
Purpose and entry points
MediLens AI is a full-stack healthcare demo for medicine scanning, medication tracking/reminders, profile-based safety guidance, and simulated AI-pharmacist chat. Flutter is the multi-platform client; FastAPI exposes the REST backend. Primary entry points are lib/main.dart, lib/app/medilens_app.dart, and backend/main.py.
Flutter composition and navigation
The application bootstrap installs app-wide composition, Material styling, and provider-backed state before presenting onboarding and the main tab shell. The shell hosts dashboard, scanning, reminders, chat, and profile presentation modules.
Paths: lib/app/medilens_app.dart, lib/features/shell/presentation/main_shell.dart, lib/features/onboarding/presentation/splash_screen.dart.
Global state and offline boundary
AppStateProvider is the client-side orchestration layer: it owns loaded/optimistic UI state and coordinates profile, medicines, reminders, and conversations. The README specifies offline-first fallback behavior, notably local simulated chat responses when API calls fail; feature screens should remain presentation-focused.
Paths: lib/app/state/app_state_provider.dart, lib/shared/models/medicine.dart, lib/shared/models/reminder.dart.
API integration boundary
Flutter feature/state code reaches the backend only through the HTTP service. Its base URL is runtime-configured through API_BASE_URL, allowing native development, web builds, and container deployments to target different API hosts.
Paths: lib/core/network/api_service.dart, .env.example, pubspec.yaml.
User-facing feature stages
Dashboard renders medication/adherence status; scan simulates medicine identification and allergy-conflict guidance; medicine details expose a selected medicine; reminders support creation and completion state; chat submits and displays medication guidance. These are separate feature presentation areas sharing state and model contracts.
Paths: lib/features/dashboard/presentation/dashboard_tab.dart, lib/features/scan/presentation/scan_tab.dart, lib/features/reminders/presentation/reminders_tab.dart.
FastAPI service and AI workflow
The FastAPI application owns /api endpoints for seeded user data, medicines, reminders, and chat. Chat is a deterministic safety-guidance pipeline: persist user text, classify intent, produce an allergy/safety/scheduling/general response, persist it, then return both messages. It is mock AI today; AI_PROVIDER and OPENAI_API_KEY are future integration seams, not evidence of an active external LLM dependency.
Paths: backend/main.py, backend/schemas.py, backend/AI_IMPLEMENTATION.md.
Persistence and deployment
SQLAlchemy models and database setup isolate persistence from HTTP handlers. SQLite is the default local store, seeded at backend startup; DATABASE_URL permits replacement with a production database. Docker Compose runs the static Flutter web frontend and FastAPI backend together; backend CORS is environment-configured.
Paths: backend/database.py, backend/models.py, docker-compose.yml.
Runtime surface
Flutter/Dart targets Android, iOS, web, Linux, macOS, and Windows through generated platform runners. The material deployment path is Flutter web in the root Dockerfile, with Python/FastAPI/Uvicorn in backend/Dockerfile; no authentication, real OCR, push notification, or production LLM service is currently implemented.
Paths: Dockerfile, backend/Dockerfile, android/app/src/main/kotlin/com/prajwalmhetre/medilens_ai/medilens_ai/MainActivity.kt.
Main entry points: app_state_provider.dart App state provider · main.py FastAPI application · medilens_app.dart App composition · main_shell.dart Main tab shell
Components 18
Flutter client
Multi-platform presentation and client orchestration.
- Flutter entry
lib/main.dart - App composition · Installs styling and provider-backed application composition.
lib/app/medilens_app.dart - Splash onboarding
lib/features/onboarding/presentation/splash_screen.dart - Main tab shell · Hosts the primary feature tabs.
lib/features/shell/presentation/main_shell.dart - Dashboard · Shows medication and adherence status.
lib/features/dashboard/presentation/dashboard_tab.dart - Medicine scan · Simulates identification and allergy-conflict guidance.
lib/features/scan/presentation/scan_tab.dart - Reminders · Creates and completes reminder state.
lib/features/reminders/presentation/reminders_tab.dart - App state provider · Coordinates profile, medicines, reminders, and conversations with optimistic state.
lib/app/state/app_state_provider.dart - Medicine and reminder models
lib/shared/models/medicine.dart - HTTP API service · Uses runtime API_BASE_URL and enables local chat fallback on failures.
lib/core/network/api_service.dart
FastAPI backend
REST API, deterministic chat workflow, and persistence.
- FastAPI application · Serves seeded user data, medicines, reminders, and chat under /api.
backend/main.py - API schemas
backend/schemas.py - Safety chat pipeline · Persists input, classifies intent, produces guidance, and persists the reply.
backend/main.py - SQLAlchemy persistence · Separates database setup and models from HTTP handlers.
backend/database.py - SQLite default store · Seeded at backend startup; DATABASE_URL can replace it.
backend/models.py
Deployment
Containerized web frontend and API runtime.
- Flutter web container
Dockerfile - FastAPI/Uvicorn container
backend/Dockerfile - Docker Compose · Runs the static web frontend and API together.
docker-compose.yml
Connections 23
- Flutter entry → App composition: starts
- App composition → Splash onboarding: presents
- App composition → Main tab shell: presents
- Main tab shell → Dashboard: hosts
- Main tab shell → Medicine scan: hosts
- Main tab shell → Reminders: hosts
- App composition → App state provider: provides
- Dashboard → App state provider: reads state
- Medicine scan → App state provider: reads and updates
- Reminders → App state provider: reads and updates
- App state provider → Medicine and reminder models: uses
- App state provider → HTTP API service: calls
- HTTP API service → FastAPI application: REST /api
- HTTP API service → App state provider: simulated chat fallback
- FastAPI application → API schemas: validates with
- FastAPI application → Safety chat pipeline: chat requests
- FastAPI application → SQLAlchemy persistence: reads and writes
- Safety chat pipeline → SQLAlchemy persistence: persists both messages
- SQLAlchemy persistence → SQLite default store: stores data
- Docker Compose → Flutter web container: runs
- Docker Compose → FastAPI/Uvicorn container: runs
- Flutter web container → HTTP API service: serves client
- FastAPI/Uvicorn container → FastAPI application: hosts