How lasuss/medihouse works
1. System shape
- MediHouse is a Flutter mobile app backed by Supabase and augmented with Firebase Cloud Messaging for push notifications.
- The repository is split into three architectural layers: the Flutter client (lib/), the backend/database provisioning (database/, supabase/, docs/), and the platform wrappers for Android/iOS (android/, ios/).
2. Client entry point and app shell
- The runtime starts in lib/main.dart, which likely initializes Supabase/Firebase, loads environment config from .env, and sets up routing.
- lib/Widgets/AppShell.dart and lib/menus/bottom_navigation.dart suggest a shared application frame used after login, with role-specific navigation and consistent layout across screens.
3. Role-based frontend architecture
- The UI is organized by user role:
- patient/
- doctor/
- receptionist/
- admin/
- pharmacy/
- This is a strong boundary in the architecture: each role gets its own dashboard and task screens, while shared components live outside those folders.
4. Authentication and user state
- lib/Widgets/login.dart, register.dart, and lib/enroll/UserRole.dart indicate an onboarding/auth flow that determines the user’s role.
- lib/helpers/UserManager.dart acts as the app’s central session/user-state singleton, likely holding current user identity, role, and session-derived access data.
- Supabase Auth is the main authentication boundary, with role-based access control enforced at the app and database level.
5. Routing and screen composition
- lib/helpers/routers.dart is the main navigation boundary.
- The app appears to route users into different dashboards and nested feature screens based on authentication state and role, rather than using one monolithic UI flow.
6. Domain-specific subsystems
- The repository models healthcare workflows as separate feature areas:
- Appointments/booking: PatientBooking, PatientAppointment, DoctorSchedule
- Medical records: PatientRecordDetail, DoctorRecordDetail, DoctorRecordDetailEdit
- Profiles: patient, doctor, receptionist, and edit/profile-detail screens
- Messaging and notifications: role-specific message and notification screens
- Help/policy content: help center, privacy policy, terms of service
- This indicates a screen-driven architecture where each clinical workflow is encapsulated in its own feature folder.
7. Shared domain models
- lib/Widgets/model/ contains data objects such as Appointment, Inventory, Medicine, Message, and Prescription.
- These models are the bridge between Supabase records and UI screens, and likely represent the main entities flowing through the app.
- PatientChatScreen.dart under the model folder suggests chat is treated as a reusable feature tied to the message model.
8. Operational workflows in the app
- The main user journeys are:
- login/register → resolve role → dashboard
- booking/triage → appointment scheduling
- profile/record lookup → detailed record view or edit
- QR/National ID scan → patient or prescription identification
- The QR and ID scanning screens in both patient and doctor areas show that identity capture is a recurring integration point in the app.
9. Backend and database layer
- Supabase is the central backend runtime: database, auth, and likely row-level authorization.
- database/supabase_setup.sql, database/supabase_auth_trigger.sql, and the docs in docs/ imply the schema is provisioned through SQL scripts and documented separately.
- docs/database_overview.md and docs/database_full_reference.md suggest the database is a first-class part of the system design, not an opaque external dependency.
10. Notification pipeline
- lib/helpers/NotificationService.dart plus supabase/functions/push-notification/index.ts show a two-part notification architecture:
- the Flutter client receives and displays notifications
- a Supabase Edge Function sends push notifications via Firebase
- This is the main asynchronous cross-system flow in the repo: backend event → edge function → Firebase FCM → device.
11. Administrative and operational boundaries
- Admin screens (AdminDashboard, AdminUserManagement) imply centralized governance over users and system data.
- Pharmacy screens (PharmacyPending, PharmacyFilled, PharmacyInventory) isolate medication fulfillment from clinical workflows.
- Receptionist screens manage triage and coordination, acting as an operational bridge between patients and clinicians.
12. Platform and build boundaries
- android/ and ios/ are standard Flutter host apps, meaning the business architecture lives almost entirely in Dart while native code remains thin.
- Native code is mainly for app bootstrapping and platform packaging, not domain logic.
13. What to show in an architecture diagram
- A useful diagram should center on:
- Flutter client
- Role-based feature modules
- Shared auth/session/router helpers
- Supabase Auth + PostgreSQL
- Supabase Edge Function for notifications
- Firebase Cloud Messaging
- SQL/database provisioning scripts and documentation
- The key flows are auth/role resolution, CRUD-style healthcare data access, QR-based identification, and asynchronous push notifications.
Main entry points: AppShell.dart App Shell · main.dart Main · supabase_setup.sql Supabase · PatientDashboard.dart Patient Space
Components 21
Flutter client
Dart app runtime, feature screens, shared state, and navigation.
- Main · App startup and initial service wiring.
lib/main.dart - Router · Central route and role-based screen selection.
lib/helpers/routers.dart - App Shell · Shared logged-in frame and bottom navigation.
lib/Widgets/AppShell.dart - User Manager · Central user/session singleton for identity and role state.
lib/helpers/UserManager.dart - Login & Register · Sign-in, registration, and onboarding entry screens.
lib/Widgets/login.dart - User Role · Role selection and enrollment boundary.
lib/enroll/UserRole.dart - Domain Models · Core app entities shared across features and backend records.
lib/Widgets/model/Appointment.dart - Scan Tools · Shared QR and national ID scanning capability.
lib/Widgets/common/CCCDScanner.dart - Notifications · Client-side notification display and handling.
lib/helpers/NotificationService.dart - Patient Space · Patient dashboard, booking, records, profile, and policy screens.
lib/Widgets/patient/PatientDashboard.dart - Doctor Space · Doctor dashboard, records, schedule, chat, and scan flows.
lib/Widgets/doctor/DoctorDashboard.dart - Receptionist Space · Reception and triage coordination screens.
lib/Widgets/receptionist/ReceptionistDashboard.dart - Admin Space · Administrative dashboard and user management.
lib/Widgets/admin/AdminDashboard.dart - Pharmacy Space · Medication fulfillment and inventory screens.
lib/Widgets/pharmacy/PharmacyInventory.dart
Backend & data
Supabase auth, database setup, edge functions, and schema docs.
- Supabase · Backend auth and database platform.
database/supabase_setup.sql - DB Setup · Schema and auth trigger provisioning scripts.
database/supabase_auth_trigger.sql - DB Docs · Database overview and full reference documentation.
docs/database_overview.md - Push Function · Supabase Edge Function that sends push notifications.
supabase/functions/push-notification/index.ts - Firebase FCM · External push notification delivery channel.
Native shells
Android and iOS host projects for packaging and bootstrapping.
- Android Host · Android packaging and platform bootstrap layer.
android/app/src/main/kotlin/com/example/medi_house/MainActivity.kt - iOS Host · iOS packaging and platform bootstrap layer.
ios/Runner/AppDelegate.swift
Connections 25
- Main → Router: boots · Startup hands control to routing and app flow selection.
- Main → User Manager: initializes · App startup loads or creates session state.
- Main → Supabase: connects · Client initializes Supabase services for auth and data access.
- Main → Notifications: registers · Client sets up local notification handling.
- Login & Register → User Role: resolves · Authentication flow determines the user's role.
- User Role → User Manager: stores · Selected role is persisted in session state.
- Router → App Shell: enters · Authenticated users are routed into the shared app shell.
- App Shell → Patient Space: hosts · Shared shell renders patient workflows.
- App Shell → Doctor Space: hosts · Shared shell renders doctor workflows.
- App Shell → Receptionist Space: hosts · Shared shell renders receptionist workflows.
- App Shell → Admin Space: hosts · Shared shell renders admin workflows.
- App Shell → Pharmacy Space: hosts · Shared shell renders pharmacy workflows.
- Patient Space → Domain Models: uses · Patient screens read and write shared domain entities.
- Doctor Space → Domain Models: uses · Doctor screens read and write shared domain entities.
- Receptionist Space → Domain Models: uses · Reception workflows operate on shared records and appointments.
- Admin Space → Supabase: governs · Admin workflows depend on backend-authored user and data state.
- Pharmacy Space → Supabase: fulfills · Pharmacy workflows manage fulfillment and inventory records.
- Scan Tools → Patient Space: supports · Patient identity capture is used in patient flows.
- Scan Tools → Doctor Space: supports · Patient identity capture is used in doctor flows.
- Notifications → Push Function: receives · Client-side notifications are triggered by backend push events.
- Push Function → Firebase FCM: sends · Edge function forwards push payloads to Firebase Cloud Messaging.
- Supabase → DB Setup: provisioned by · Backend setup is defined through SQL scripts.
- Supabase → DB Docs: documented by · Database behavior and structure are described in repo docs.
- Android Host → Main: launches · Android host starts the Flutter runtime.
- iOS Host → Main: launches · iOS host starts the Flutter runtime.