# nabdcm/iada architecture

> Architecture diagram of the GitHub repository nabdcm/iada, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nabdcm/iada
- Repository: https://github.com/nabdcm/iada

## Overview

1. This is a Next.js application using the App Router and TypeScript. The architecture is split between UI routes under `src/app`, reusable UI in `components`, and server-side helpers in `src/lib`.

2. The main runtime boundary is the Next.js app itself: page components render the user-facing screens, while `src/app/api/*/route.ts` files expose HTTP endpoints for backend actions. That gives the repo a clear frontend + API split inside a single codebase.

3. The backend data layer appears to be Supabase. `src/lib/supabase.ts` is the central integration point, and `src/lib/auth.ts` likely contains authentication/session logic used across protected pages and middleware.

4. Authentication and access control are enforced at the edge with `middleware.ts`. That suggests route gating before requests reach pages, likely protecting dashboard/admin/patient-management areas and redirecting unauthenticated or blocked users.

5. The core product domain looks like a clinic management system. The API routes under `src/app/api/` support clinic lifecycle operations: create, update, delete, freeze, cancel, and list clinics. These routes define the main server-side business boundary.

6. The UI is organized around operational workflows rather than generic navigation. Key screens include `dashboard`, `appointments`, `patients`, `payments`, `prescriptions`, and `patient-tracking`, which likely consume shared clinic/patient data from Supabase through the API or direct server access.

7. There is a public booking flow under `src/app/book/[clinicId]`, indicating a clinic-specific appointment booking page. This is a separate entry path from the internal dashboard, and it likely uses the clinic ID as the primary lookup key.

8. There is also a tokenized `daily-log/[token]` route, which looks like a shareable or access-controlled workflow distinct from normal authenticated users. That implies a second access model alongside the standard login-protected app.

9. `src/app/login` and `src/app/blocked` suggest explicit auth-state outcomes: successful sign-in, and a blocked/denied state for accounts or clinics that are suspended/frozen. The freeze/cancel clinic APIs line up with that lifecycle.

10. `components/ClinicProfileSetup.tsx` is the notable reusable feature component. It likely supports onboarding or clinic configuration and sits between the admin/management pages and the underlying clinic records.

11. The `src/app/api/*/page.tsx` files are unusual because they are page routes nested under `api`. In architecture terms, they behave as UI pages rather than HTTP handlers, so they should be treated as part of the app’s screen structure, not the backend API surface.

12. Overall, the repository centers on one bounded domain: managing clinics, their staff/patients/appointments/payments, and access-controlled operational views. The main data flow is: user or public visitor enters a page → middleware/auth decides access → page loads data from Supabase or calls a route handler → UI updates clinic records and related workflows.

Main entry points: [`src/lib/supabase.ts`](https://github.com/nabdcm/iada/blob/main/src/lib/supabase.ts) (Supabase), [`middleware.ts`](https://github.com/nabdcm/iada/blob/main/middleware.ts) (Middleware), [`src/lib/auth.ts`](https://github.com/nabdcm/iada/blob/main/src/lib/auth.ts) (Auth), [`src/app/api/create-clinic/route.ts`](https://github.com/nabdcm/iada/blob/main/src/app/api/create-clinic/route.ts) (Create clinic)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app_routes["App routes"]
  node_src_app_layout["App shell<br/>Next.js layout<br/>[layout.tsx]"]
  node_src_app_page["Landing<br/>Home page<br/>[page.tsx]"]
  node_src_app_login_page["Login<br/>Auth page<br/>[page.tsx]"]
  node_src_app_blocked_page["Blocked<br/>Access page<br/>[page.tsx]"]
  node_src_app_dashboard_page["Dashboard<br/>Ops page<br/>[page.tsx]"]
  node_src_app_admin_page["Admin<br/>[page.tsx]"]
  node_src_app_appointments_page["Appointments<br/>Workflow page<br/>[page.tsx]"]
  node_src_app_patients_page["Patients<br/>Workflow page<br/>[page.tsx]"]
  node_src_app_payments_page["Payments<br/>Workflow page<br/>[page.tsx]"]
  node_src_app_prescriptions_page["Prescriptions<br/>Workflow page<br/>[page.tsx]"]
  node_src_app_patient_tracking_page["Tracking<br/>Workflow page<br/>[page.tsx]"]
  node_src_app_book_clinic_page["Book visit<br/>Public booking<br/>[page.tsx]"]
  node_src_app_daily_log_page["Daily log<br/>Token page<br/>[page.tsx]"]
end

subgraph group_api_backend["API backend"]
  node_src_app_api_dashboard_page["API dashboard<br/>API page<br/>[page.tsx]"]
  node_src_app_api_appointments_page["API appointments<br/>API page<br/>[page.tsx]"]
  node_src_app_api_patients_page["API patients<br/>API page<br/>[page.tsx]"]
  node_src_app_api_payments_page["API payments<br/>API page<br/>[page.tsx]"]
  node_src_app_api_create_clinic_route["Create clinic<br/>Route handler<br/>[route.ts]"]
  node_src_app_api_update_clinic_route["Update clinic<br/>Route handler<br/>[route.ts]"]
  node_src_app_api_freeze_clinic_route["Freeze clinic<br/>Route handler<br/>[route.ts]"]
  node_src_app_api_cancel_clinic_route["Cancel clinic<br/>Route handler<br/>[route.ts]"]
  node_src_app_api_delete_clinic_route["Delete clinic<br/>Route handler<br/>[route.ts]"]
  node_src_app_api_get_clinics_route["List clinics<br/>Route handler<br/>[route.ts]"]
end

subgraph group_shared_code["Shared code"]
  node_middleware_ts{{"Middleware<br/>Edge gate<br/>[middleware.ts]"}}
  node_src_lib_auth_ts["Auth<br/>[auth.ts]"]
  node_src_lib_supabase_ts[("Supabase<br/>Data client<br/>[supabase.ts]")]
  node_components_klinical_setup["Clinic setup<br/>Feature component"]
end

node_src_app_layout -->|"wraps"| node_src_app_page
node_middleware_ts -->|"uses"| node_src_lib_auth_ts
node_middleware_ts -->|"permits"| node_src_app_login_page
node_middleware_ts -->|"redirects"| node_src_app_blocked_page
node_middleware_ts -->|"guards"| node_src_app_dashboard_page
node_middleware_ts -->|"guards"| node_src_app_admin_page
node_middleware_ts -->|"guards"| node_src_app_appointments_page
node_middleware_ts -->|"guards"| node_src_app_patients_page
node_middleware_ts -->|"guards"| node_src_app_payments_page
node_middleware_ts -->|"guards"| node_src_app_prescriptions_page
node_middleware_ts -->|"guards"| node_src_app_patient_tracking_page
node_src_app_dashboard_page -->|"reads"| node_src_lib_supabase_ts
node_src_app_appointments_page -->|"reads"| node_src_lib_supabase_ts
node_src_app_patients_page -->|"reads"| node_src_lib_supabase_ts
node_src_app_payments_page -->|"reads"| node_src_lib_supabase_ts
node_src_app_prescriptions_page -->|"reads"| node_src_lib_supabase_ts
node_src_app_patient_tracking_page -->|"reads"| node_src_lib_supabase_ts
node_src_app_book_clinic_page -->|"reads"| node_src_lib_supabase_ts
node_src_app_daily_log_page -->|"reads"| node_src_lib_supabase_ts
node_src_app_api_dashboard_page -->|"reads"| node_src_lib_supabase_ts
node_src_app_api_appointments_page -->|"reads"| node_src_lib_supabase_ts
node_src_app_api_patients_page -->|"reads"| node_src_lib_supabase_ts
node_src_app_api_payments_page -->|"reads"| node_src_lib_supabase_ts
node_src_app_api_create_clinic_route -->|"writes"| node_src_lib_supabase_ts
node_src_app_api_update_clinic_route -->|"writes"| node_src_lib_supabase_ts
node_src_app_api_freeze_clinic_route -->|"writes"| node_src_lib_supabase_ts
node_src_app_api_cancel_clinic_route -->|"writes"| node_src_lib_supabase_ts
node_src_app_api_delete_clinic_route -->|"writes"| node_src_lib_supabase_ts
node_src_app_api_get_clinics_route -->|"reads"| node_src_lib_supabase_ts
node_src_app_api_create_clinic_route -->|"verifies"| node_src_lib_auth_ts
node_src_app_api_update_clinic_route -->|"verifies"| node_src_lib_auth_ts
node_src_app_api_freeze_clinic_route -->|"verifies"| node_src_lib_auth_ts
node_src_app_api_cancel_clinic_route -->|"verifies"| node_src_lib_auth_ts
node_src_app_api_delete_clinic_route -->|"verifies"| node_src_lib_auth_ts
node_src_app_api_get_clinics_route -->|"verifies"| node_src_lib_auth_ts
node_src_app_admin_page -->|"uses"| node_components_klinical_setup
node_src_app_dashboard_page -->|"uses"| node_components_klinical_setup
node_src_app_api_create_clinic_route -->|"supports"| node_components_klinical_setup

click node_src_app_layout "https://github.com/nabdcm/iada/blob/main/src/app/layout.tsx"
click node_src_app_page "https://github.com/nabdcm/iada/blob/main/src/app/page.tsx"
click node_src_app_login_page "https://github.com/nabdcm/iada/blob/main/src/app/login/page.tsx"
click node_src_app_blocked_page "https://github.com/nabdcm/iada/blob/main/src/app/blocked/page.tsx"
click node_src_app_dashboard_page "https://github.com/nabdcm/iada/blob/main/src/app/dashboard/page.tsx"
click node_src_app_admin_page "https://github.com/nabdcm/iada/blob/main/src/app/admin/page.tsx"
click node_src_app_appointments_page "https://github.com/nabdcm/iada/blob/main/src/app/appointments/page.tsx"
click node_src_app_patients_page "https://github.com/nabdcm/iada/blob/main/src/app/patients/page.tsx"
click node_src_app_payments_page "https://github.com/nabdcm/iada/blob/main/src/app/payments/page.tsx"
click node_src_app_prescriptions_page "https://github.com/nabdcm/iada/blob/main/src/app/prescriptions/page.tsx"
click node_src_app_patient_tracking_page "https://github.com/nabdcm/iada/blob/main/src/app/patient-tracking/page.tsx"
click node_src_app_book_clinic_page "https://github.com/nabdcm/iada/blob/main/src/app/book/[clinicId]/page.tsx"
click node_src_app_daily_log_page "https://github.com/nabdcm/iada/blob/main/src/app/daily-log/[token]/page.tsx"
click node_src_app_api_dashboard_page "https://github.com/nabdcm/iada/blob/main/src/app/api/dashboard/page.tsx"
click node_src_app_api_appointments_page "https://github.com/nabdcm/iada/blob/main/src/app/api/appointments/page.tsx"
click node_src_app_api_patients_page "https://github.com/nabdcm/iada/blob/main/src/app/api/patients/page.tsx"
click node_src_app_api_payments_page "https://github.com/nabdcm/iada/blob/main/src/app/api/payments/page.tsx"
click node_src_app_api_create_clinic_route "https://github.com/nabdcm/iada/blob/main/src/app/api/create-clinic/route.ts"
click node_src_app_api_update_clinic_route "https://github.com/nabdcm/iada/blob/main/src/app/api/update-clinic/route.ts"
click node_src_app_api_freeze_clinic_route "https://github.com/nabdcm/iada/blob/main/src/app/api/freeze-clinic/route.ts"
click node_src_app_api_cancel_clinic_route "https://github.com/nabdcm/iada/blob/main/src/app/api/cancel-clinic/route.ts"
click node_src_app_api_delete_clinic_route "https://github.com/nabdcm/iada/blob/main/src/app/api/delete-clinic/route.ts"
click node_src_app_api_get_clinics_route "https://github.com/nabdcm/iada/blob/main/src/app/api/get-clinics/route.ts"
click node_middleware_ts "https://github.com/nabdcm/iada/blob/main/middleware.ts"
click node_src_lib_auth_ts "https://github.com/nabdcm/iada/blob/main/src/lib/auth.ts"
click node_src_lib_supabase_ts "https://github.com/nabdcm/iada/blob/main/src/lib/supabase.ts"
click node_components_klinical_setup "https://github.com/nabdcm/iada/blob/main/components/ClinicProfileSetup.tsx"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_src_app_layout,node_src_app_page,node_src_app_login_page,node_src_app_blocked_page,node_src_app_dashboard_page,node_src_app_admin_page,node_src_app_appointments_page,node_src_app_patients_page,node_src_app_payments_page,node_src_app_prescriptions_page,node_src_app_patient_tracking_page,node_src_app_book_clinic_page,node_src_app_daily_log_page toneBlue
class node_src_app_api_dashboard_page,node_src_app_api_appointments_page,node_src_app_api_patients_page,node_src_app_api_payments_page,node_src_app_api_create_clinic_route,node_src_app_api_update_clinic_route,node_src_app_api_freeze_clinic_route,node_src_app_api_cancel_clinic_route,node_src_app_api_delete_clinic_route,node_src_app_api_get_clinics_route toneAmber
class node_middleware_ts,node_src_lib_auth_ts,node_src_lib_supabase_ts,node_components_klinical_setup toneMint
```

## Components

### App routes

User-facing screens and route-driven workflows

- [App shell](https://github.com/nabdcm/iada/blob/main/src/app/layout.tsx): Next.js layout · Root app layout and global providers · `src/app/layout.tsx`
- [Landing](https://github.com/nabdcm/iada/blob/main/src/app/page.tsx): Home page · Public entry page · `src/app/page.tsx`
- [Login](https://github.com/nabdcm/iada/blob/main/src/app/login/page.tsx): Auth page · Sign-in screen · `src/app/login/page.tsx`
- [Blocked](https://github.com/nabdcm/iada/blob/main/src/app/blocked/page.tsx): Access page · Denied or suspended account state · `src/app/blocked/page.tsx`
- [Dashboard](https://github.com/nabdcm/iada/blob/main/src/app/dashboard/page.tsx): Ops page · Main authenticated overview · `src/app/dashboard/page.tsx`
- [Admin](https://github.com/nabdcm/iada/blob/main/src/app/admin/page.tsx): Admin page · Administrative control screen · `src/app/admin/page.tsx`
- [Appointments](https://github.com/nabdcm/iada/blob/main/src/app/appointments/page.tsx): Workflow page · Appointment management screen · `src/app/appointments/page.tsx`
- [Patients](https://github.com/nabdcm/iada/blob/main/src/app/patients/page.tsx): Workflow page · Patient management screen · `src/app/patients/page.tsx`
- [Payments](https://github.com/nabdcm/iada/blob/main/src/app/payments/page.tsx): Workflow page · Billing and payment screen · `src/app/payments/page.tsx`
- [Prescriptions](https://github.com/nabdcm/iada/blob/main/src/app/prescriptions/page.tsx): Workflow page · Prescription workflow screen · `src/app/prescriptions/page.tsx`
- [Tracking](https://github.com/nabdcm/iada/blob/main/src/app/patient-tracking/page.tsx): Workflow page · Patient tracking screen · `src/app/patient-tracking/page.tsx`
- [Book visit](https://github.com/nabdcm/iada/blob/main/src/app/book/[clinicId]/page.tsx): Public booking · Clinic-specific public booking flow · `src/app/book/[clinicId]/page.tsx`
- [Daily log](https://github.com/nabdcm/iada/blob/main/src/app/daily-log/[token]/page.tsx): Token page · Shareable tokenized daily-log workflow · `src/app/daily-log/[token]/page.tsx`

### API backend

HTTP handlers and API-hosted screens

- [API dashboard](https://github.com/nabdcm/iada/blob/main/src/app/api/dashboard/page.tsx): API page · Dashboard-like UI nested under api · `src/app/api/dashboard/page.tsx`
- [API appointments](https://github.com/nabdcm/iada/blob/main/src/app/api/appointments/page.tsx): API page · Appointments UI nested under api · `src/app/api/appointments/page.tsx`
- [API patients](https://github.com/nabdcm/iada/blob/main/src/app/api/patients/page.tsx): API page · Patients UI nested under api · `src/app/api/patients/page.tsx`
- [API payments](https://github.com/nabdcm/iada/blob/main/src/app/api/payments/page.tsx): API page · Payments UI nested under api · `src/app/api/payments/page.tsx`
- [Create clinic](https://github.com/nabdcm/iada/blob/main/src/app/api/create-clinic/route.ts): Route handler · Clinic creation endpoint · `src/app/api/create-clinic/route.ts`
- [Update clinic](https://github.com/nabdcm/iada/blob/main/src/app/api/update-clinic/route.ts): Route handler · Clinic update endpoint · `src/app/api/update-clinic/route.ts`
- [Freeze clinic](https://github.com/nabdcm/iada/blob/main/src/app/api/freeze-clinic/route.ts): Route handler · Clinic suspension endpoint · `src/app/api/freeze-clinic/route.ts`
- [Cancel clinic](https://github.com/nabdcm/iada/blob/main/src/app/api/cancel-clinic/route.ts): Route handler · Clinic cancellation endpoint · `src/app/api/cancel-clinic/route.ts`
- [Delete clinic](https://github.com/nabdcm/iada/blob/main/src/app/api/delete-clinic/route.ts): Route handler · Clinic deletion endpoint · `src/app/api/delete-clinic/route.ts`
- [List clinics](https://github.com/nabdcm/iada/blob/main/src/app/api/get-clinics/route.ts): Route handler · Clinic listing endpoint · `src/app/api/get-clinics/route.ts`

### Shared code

Cross-cutting auth, data access, and reusable UI

- [Middleware](https://github.com/nabdcm/iada/blob/main/middleware.ts): Edge gate · Route gating and access control before rendering · `middleware.ts`
- [Auth](https://github.com/nabdcm/iada/blob/main/src/lib/auth.ts): Auth helper · Session and access logic · `src/lib/auth.ts`
- [Supabase](https://github.com/nabdcm/iada/blob/main/src/lib/supabase.ts): Data client · Primary database and backend integration · `src/lib/supabase.ts`
- [Clinic setup](https://github.com/nabdcm/iada/blob/main/components/ClinicProfileSetup.tsx): Feature component · Reusable clinic profile onboarding/configuration UI · `components/ClinicProfileSetup.tsx`

## Connections

- App shell → Landing: wraps · Root layout frames the application
- Middleware → Auth: uses · Edge checks rely on auth/session state
- Middleware → Login: permits · Login remains reachable without gating
- Middleware → Blocked: redirects · Blocked access routes to denied state
- Middleware → Dashboard: guards · Protects internal operational pages
- Middleware → Admin: guards · Protects administrative pages
- Middleware → Appointments: guards · Protects workflow pages
- Middleware → Patients: guards · Protects workflow pages
- Middleware → Payments: guards · Protects workflow pages
- Middleware → Prescriptions: guards · Protects workflow pages
- Middleware → Tracking: guards · Protects workflow pages
- Dashboard → Supabase: reads · Dashboard loads clinic data
- Appointments → Supabase: reads · Appointments screen consumes clinic data
- Patients → Supabase: reads · Patients screen consumes records
- Payments → Supabase: reads · Payments screen consumes billing data
- Prescriptions → Supabase: reads · Prescription workflow uses backend data
- Tracking → Supabase: reads · Tracking screen uses patient state
- Book visit → Supabase: reads · Public booking looks up clinic by id
- Daily log → Supabase: reads · Token workflow resolves log data
- API dashboard → Supabase: reads · API-hosted dashboard accesses data
- API appointments → Supabase: reads · API-hosted appointments accesses data
- API patients → Supabase: reads · API-hosted patients accesses data
- API payments → Supabase: reads · API-hosted payments accesses data
- Create clinic → Supabase: writes · Creates clinic records
- Update clinic → Supabase: writes · Updates clinic records
- Freeze clinic → Supabase: writes · Freezes clinic state
- Cancel clinic → Supabase: writes · Cancels clinic state
- Delete clinic → Supabase: writes · Deletes clinic records
- List clinics → Supabase: reads · Lists clinics from storage
- Create clinic → Auth: verifies · Mutation routes likely enforce identity
- Update clinic → Auth: verifies · Mutation routes likely enforce identity
- Freeze clinic → Auth: verifies · Mutation routes likely enforce identity
- Cancel clinic → Auth: verifies · Mutation routes likely enforce identity
- Delete clinic → Auth: verifies · Mutation routes likely enforce identity
- List clinics → Auth: verifies · Listing route may enforce access
- Admin → Clinic setup: uses · Admin/management flows reuse clinic setup UI
- Dashboard → Clinic setup: uses · Operational setup can surface here
- Create clinic → Clinic setup: supports · Creation flow pairs with setup component
