Overview
The ADHD Simple Clinical platform is a React web application with a Supabase backend, deployed on Netlify. It manages ADHD patient records, prescriptions, and medication delivery using a service layer architecture that centralizes business logic and provides consistent error handling.High-Level Architecture
Technology Stack
Frontend
- React 18 with TypeScript
- Vite for build tooling
- Material-UI (MUI) for components
- Tailwind CSS for styling
- React Router for navigation
- Service Layer Architecture - No direct Supabase calls
Backend
- Supabase as backend-as-a-service
- PostgreSQL database
- Supabase Auth with mandatory 2FA
- Edge Functions for business logic
- Supabase Storage for medication images
Deployment
- Netlify hosting with automatic deployments
- GitHub Actions for CI/CD
- Custom domain with SSL
Service Layer Architecture
The platform uses a service layer architecture that eliminates direct Supabase calls from the frontend, providing:Core Services (4)
- PatientService - Patient CRUD operations, health metrics, monitoring
- PrescriptionService - Prescription orders, item management, charge calculations
- MedicationService - Medication library, active medication tracking, stock management
- AuthService - User authentication, session management, MFA support
Feature Services (7)
- ShipmentService - Shipment creation, tracking, label generation, DHL integration
- PaymentService - Payment settings, Stripe integration, authorization processing
- PatientRequestService - Patient app request management, review workflows
- AddressService - UK postcode lookup, address validation, pickup addresses
- ClinicService - Clinic settings and configuration management
- DeliveryService - Delivery fee calculation, shipping cost management
- PharmacyService - Order management, pharmacy statistics, controlled drugs register
Benefits
- Centralized business logic - All operations go through services
- Consistent error handling - Using shared
handle()utility - Type safety - Full TypeScript support with Zod validation
- Zero direct Supabase calls - Complete separation of concerns
- Testable architecture - Services can be mocked and tested independently
Key Features
Authentication & Security
- Mandatory TOTP 2FA for all users
- Role-based access control (admin, prescriber, staff)
- Session management with automatic timeouts
Patient Management
- Comprehensive ADHD patient records
- Health metrics tracking (weight, BP, pulse, symptoms)
- Clinical pathways: new → titration → stable care
Prescription Management
- Digital prescription creation and editing
- Controlled drug compliance monitoring
- 28-day prescription cycles
- DHL integration for medication delivery
Clinical Data
- Real-time data synchronization
- Audit trails for all clinical actions
- NHS/GDPR compliant data handling
Database Structure
Key tables include:users- Clinician accounts and profilespatients- Patient records and clinical dataprescriptions- Prescription records and ordershealth_metrics- Patient monitoring datashipments- DHL delivery trackingaudit_logs- Complete audit trail
Edge Functions
The system uses consolidated Supabase Edge Functions corresponding to each service:Core Operations
auth-operations- User authentication, session management, MFApatient-operations- Patient CRUD, health metrics, monitoringclinical-prescription-operations- Prescription management, order processingclinical-medication-operations- Medication library, active medication tracking
Feature Operations
clinical-shipment-operations- Shipment creation, tracking, DHL integrationclinical-payment-operations- Payment processing, Stripe integrationclinical-request-operations- Patient app request managementclinical-address-operations- Address validation, postcode lookupclinical-clinic-operations- Clinic settings managementclinical-delivery-operations- Delivery fee calculation and configurationclinical-pharmacy-operations- Pharmacy order management and statistics
Specialized Functions
generate-medication-image- Medication image generationprescription-notifications- Email and push notificationssend-email- Email service integrationsend-push-notification- Push notification service
External Integrations
DHL API
- Automated shipment creation with tracking numbers
- Van pickup scheduling
- Real-time delivery tracking
- Patient delivery confirmations
Compliance
- Controlled drug monitoring
- NHS Digital standards compliance
- GDPR data protection measures
Development
Local Setup
- Supabase local development with Docker
- Hot reload with Vite HMR
- TypeScript for type safety
Service Layer Development
- Services can be mocked for testing
- Consistent error handling patterns
- Zod validation for all inputs
- Type-safe service interfaces
Testing
- Playwright for end-to-end testing
- Component testing with Jest
- Service layer unit testing
- Clinical workflow testing
Deployment
- Automatic Netlify deployments from main branch
- Environment-based configuration
- Database migrations via Supabase CLI
- Edge function deployments
This architecture prioritizes clinical safety, regulatory compliance, and operational efficiency for ADHD care delivery through a robust service layer that eliminates direct database access from the frontend.