# zahraaasgari/medical-appointment-app architecture

> Architecture diagram of the GitHub repository zahraaasgari/medical-appointment-app, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/zahraaasgari/medical-appointment-app
- Repository: https://github.com/zahraaasgari/medical-appointment-app

## Overview

This Telegram Mini App lets clinic staff—not patients—authenticate, manage a clinic’s schedule and records, and complete appointment workflows in a Persian RTL interface. The UI shell hosts the daily timeline, appointment and patient management, and profile settings; forms call protected API routes, which enforce user-scoped access and scheduling conflicts before database operations. The README documents broad API capabilities, while several route implementations are unsampled; those subsystems are represented from documented routes, without asserting unverified internal calls.

Main entry points: [`src/lib/api.ts`](https://github.com/zahraaasgari/medical-appointment-app/blob/main/src/lib/api.ts) (API client), [`src/db/index.ts`](https://github.com/zahraaasgari/medical-appointment-app/blob/main/src/db/index.ts) (PostgreSQL), [`src/lib/session.ts`](https://github.com/zahraaasgari/medical-appointment-app/blob/main/src/lib/session.ts) (Session access), [`src/app/page.tsx`](https://github.com/zahraaasgari/medical-appointment-app/blob/main/src/app/page.tsx) (Tab shell)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Staff interface"]
  node_shell["Tab shell<br/>[page.tsx]"]
  node_providers["App state<br/>[providers.tsx]"]
  node_timeline["Daily timeline<br/>[home-tab.tsx]"]
  node_appt_ui["Appointment views"]
  node_patients_ui["Patient management<br/>[patients-tab.tsx]"]
  node_profile_ui["Profile settings<br/>[profile-tab.tsx]"]
  node_forms["Workflow forms<br/>[forms.tsx]"]
  node_calendar["Jalali picker<br/>[date-picker.tsx]"]
  node_ui["UI primitives<br/>[ui.tsx]"]
  node_telegram_client["Telegram SDK<br/>[twa.ts]"]
  node_api_client["API client<br/>[api.ts]"]
end

subgraph group_api["API and scheduling"]
  node_appointment_routes["Appointment routes"]
  node_patient_routes["Patient routes"]
  node_profile_routes["Profile and clinic"]
  node_hours_routes["Working hours"]
  node_blocks_routes["Unavailable slots"]
  node_schedule_rules["Conflict checking<br/>[appointments.ts]"]
  node_dto["Appointment DTOs<br/>[dto.ts]"]
  node_format["Date and formatting<br/>[format.ts]"]
end

subgraph group_identity["Identity and setup"]
  node_telegram_auth["Telegram sign-in<br/>[route.ts]"]
  node_session["Session access<br/>[session.ts]"]
  node_seed["Account defaults<br/>[seed.ts]"]
end

subgraph group_data["Persistence"]
  node_db[("PostgreSQL<br/>[index.ts]")]
  node_schema["Clinic data model<br/>[schema.ts]"]
end

node_staff(("Clinic staff"))
node_telegram["Telegram platform"]

node_staff -->|"uses"| node_shell
node_shell -->|"renders"| node_providers
node_shell -->|"renders"| node_timeline
node_shell -->|"renders"| node_appt_ui
node_shell -->|"renders"| node_patients_ui
node_shell -->|"renders"| node_profile_ui
node_timeline -->|"fetches"| node_api_client
node_appt_ui -->|"fetches"| node_api_client
node_profile_ui -->|"fetches"| node_api_client
node_patients_ui -->|"fetches"| node_api_client
node_providers -->|"fetches"| node_api_client
node_providers -->|"opens"| node_forms
node_forms -->|"submits"| node_api_client
node_forms -->|"renders"| node_calendar
node_timeline -->|"opens"| node_calendar
node_forms -->|"renders"| node_ui
node_providers -->|"renders"| node_ui
node_providers -->|"uses"| node_telegram_client
node_api_client -.->|"requests"| node_appointment_routes
node_api_client -.->|"requests"| node_patient_routes
node_api_client -.->|"requests"| node_profile_routes
node_api_client -.->|"requests"| node_hours_routes
node_api_client -.->|"requests"| node_blocks_routes
node_appointment_routes -->|"requires user"| node_session
node_patient_routes -->|"requires user"| node_session
node_profile_routes -->|"requires user"| node_session
node_hours_routes -->|"requires user"| node_session
node_blocks_routes -->|"requires user"| node_session
node_appointment_routes -->|"checks conflicts"| node_schedule_rules
node_appointment_routes -->|"maps results"| node_dto
node_appointment_routes -->|"queries"| node_db
node_patient_routes -->|"queries"| node_db
node_profile_routes -->|"queries"| node_db
node_hours_routes -->|"queries"| node_db
node_blocks_routes -->|"queries"| node_db
node_telegram_auth -->|"validates initData"| node_telegram
node_telegram_auth -->|"creates session"| node_session
node_telegram_auth -->|"bootstraps demo"| node_seed
node_session -->|"reads and writes"| node_db
node_seed -->|"initializes records"| node_db
node_db -->|"uses tables"| node_schema
node_schedule_rules -->|"checks schedule data"| node_db
node_appointment_routes -->|"validates dates"| node_format

click node_shell "https://github.com/zahraaasgari/medical-appointment-app/blob/main/src/app/page.tsx"
click node_providers "https://github.com/zahraaasgari/medical-appointment-app/blob/main/src/components/providers.tsx"
click node_timeline "https://github.com/zahraaasgari/medical-appointment-app/blob/main/src/components/home-tab.tsx"
click node_appt_ui "https://github.com/zahraaasgari/medical-appointment-app/blob/main/src/components/appointments-tab.tsx"
click node_patients_ui "https://github.com/zahraaasgari/medical-appointment-app/blob/main/src/components/patients-tab.tsx"
click node_profile_ui "https://github.com/zahraaasgari/medical-appointment-app/blob/main/src/components/profile-tab.tsx"
click node_forms "https://github.com/zahraaasgari/medical-appointment-app/blob/main/src/components/forms.tsx"
click node_calendar "https://github.com/zahraaasgari/medical-appointment-app/blob/main/src/components/date-picker.tsx"
click node_ui "https://github.com/zahraaasgari/medical-appointment-app/blob/main/src/components/ui.tsx"
click node_telegram_client "https://github.com/zahraaasgari/medical-appointment-app/blob/main/src/lib/twa.ts"
click node_api_client "https://github.com/zahraaasgari/medical-appointment-app/blob/main/src/lib/api.ts"
click node_appointment_routes "https://github.com/zahraaasgari/medical-appointment-app/tree/main/src/app/api/appointments"
click node_patient_routes "https://github.com/zahraaasgari/medical-appointment-app/tree/main/src/app/api/patients"
click node_profile_routes "https://github.com/zahraaasgari/medical-appointment-app/tree/main/src/app/api/profile"
click node_hours_routes "https://github.com/zahraaasgari/medical-appointment-app/tree/main/src/app/api/working-hours"
click node_blocks_routes "https://github.com/zahraaasgari/medical-appointment-app/tree/main/src/app/api/unavailable"
click node_schedule_rules "https://github.com/zahraaasgari/medical-appointment-app/blob/main/src/lib/appointments.ts"
click node_dto "https://github.com/zahraaasgari/medical-appointment-app/blob/main/src/lib/dto.ts"
click node_format "https://github.com/zahraaasgari/medical-appointment-app/blob/main/src/lib/format.ts"
click node_telegram_auth "https://github.com/zahraaasgari/medical-appointment-app/blob/main/src/app/api/auth/telegram/route.ts"
click node_session "https://github.com/zahraaasgari/medical-appointment-app/blob/main/src/lib/session.ts"
click node_seed "https://github.com/zahraaasgari/medical-appointment-app/blob/main/src/lib/seed.ts"
click node_db "https://github.com/zahraaasgari/medical-appointment-app/blob/main/src/db/index.ts"
click node_schema "https://github.com/zahraaasgari/medical-appointment-app/blob/main/src/db/schema.ts"

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_shell,node_providers,node_timeline,node_appt_ui,node_patients_ui,node_profile_ui,node_forms,node_calendar,node_ui,node_telegram_client,node_api_client toneBlue
class node_appointment_routes,node_patient_routes,node_profile_routes,node_hours_routes,node_blocks_routes,node_schedule_rules,node_dto,node_format toneAmber
class node_telegram_auth,node_session,node_seed toneMint
class node_db,node_schema toneRose
class node_staff,node_telegram toneIndigo
```

## Components

### Staff interface

- [Tab shell](https://github.com/zahraaasgari/medical-appointment-app/blob/main/src/app/page.tsx): `src/app/page.tsx`
- [App state](https://github.com/zahraaasgari/medical-appointment-app/blob/main/src/components/providers.tsx): `src/components/providers.tsx`
- [Daily timeline](https://github.com/zahraaasgari/medical-appointment-app/blob/main/src/components/home-tab.tsx): `src/components/home-tab.tsx`
- [Appointment views](https://github.com/zahraaasgari/medical-appointment-app/blob/main/src/components/appointments-tab.tsx): `src/components/appointments-tab.tsx`
- [Patient management](https://github.com/zahraaasgari/medical-appointment-app/blob/main/src/components/patients-tab.tsx): `src/components/patients-tab.tsx`
- [Profile settings](https://github.com/zahraaasgari/medical-appointment-app/blob/main/src/components/profile-tab.tsx): `src/components/profile-tab.tsx`
- [Workflow forms](https://github.com/zahraaasgari/medical-appointment-app/blob/main/src/components/forms.tsx): `src/components/forms.tsx`
- [Jalali picker](https://github.com/zahraaasgari/medical-appointment-app/blob/main/src/components/date-picker.tsx): `src/components/date-picker.tsx`
- [UI primitives](https://github.com/zahraaasgari/medical-appointment-app/blob/main/src/components/ui.tsx): `src/components/ui.tsx`
- [Telegram SDK](https://github.com/zahraaasgari/medical-appointment-app/blob/main/src/lib/twa.ts): `src/lib/twa.ts`
- [API client](https://github.com/zahraaasgari/medical-appointment-app/blob/main/src/lib/api.ts): `src/lib/api.ts`

### API and scheduling

- [Appointment routes](https://github.com/zahraaasgari/medical-appointment-app/tree/main/src/app/api/appointments): `src/app/api/appointments`
- [Patient routes](https://github.com/zahraaasgari/medical-appointment-app/tree/main/src/app/api/patients): `src/app/api/patients`
- [Profile and clinic](https://github.com/zahraaasgari/medical-appointment-app/tree/main/src/app/api/profile): `src/app/api/profile`
- [Working hours](https://github.com/zahraaasgari/medical-appointment-app/tree/main/src/app/api/working-hours): `src/app/api/working-hours`
- [Unavailable slots](https://github.com/zahraaasgari/medical-appointment-app/tree/main/src/app/api/unavailable): `src/app/api/unavailable`
- [Conflict checking](https://github.com/zahraaasgari/medical-appointment-app/blob/main/src/lib/appointments.ts): `src/lib/appointments.ts`
- [Appointment DTOs](https://github.com/zahraaasgari/medical-appointment-app/blob/main/src/lib/dto.ts): `src/lib/dto.ts`
- [Date and formatting](https://github.com/zahraaasgari/medical-appointment-app/blob/main/src/lib/format.ts): `src/lib/format.ts`

### Identity and setup

- [Telegram sign-in](https://github.com/zahraaasgari/medical-appointment-app/blob/main/src/app/api/auth/telegram/route.ts): `src/app/api/auth/telegram/route.ts`
- [Session access](https://github.com/zahraaasgari/medical-appointment-app/blob/main/src/lib/session.ts): `src/lib/session.ts`
- [Account defaults](https://github.com/zahraaasgari/medical-appointment-app/blob/main/src/lib/seed.ts): `src/lib/seed.ts`

### Persistence

- [PostgreSQL](https://github.com/zahraaasgari/medical-appointment-app/blob/main/src/db/index.ts): `src/db/index.ts`
- [Clinic data model](https://github.com/zahraaasgari/medical-appointment-app/blob/main/src/db/schema.ts): `src/db/schema.ts`

### Other components

- **Clinic staff**
- **Telegram platform**

## Connections

- Clinic staff → Tab shell: uses (evidence: `README.md`)
- Tab shell → App state: renders (evidence: `src/app/page.tsx`)
- Tab shell → Daily timeline: renders (evidence: `src/app/page.tsx`)
- Tab shell → Appointment views: renders (evidence: `src/app/page.tsx`)
- Tab shell → Patient management: renders (evidence: `src/app/page.tsx`)
- Tab shell → Profile settings: renders (evidence: `src/app/page.tsx`)
- Daily timeline → API client: fetches (evidence: `src/components/home-tab.tsx`)
- Appointment views → API client: fetches (evidence: `src/components/appointments-tab.tsx`)
- Profile settings → API client: fetches (evidence: `src/components/profile-tab.tsx`)
- Patient management → API client: fetches
- App state → API client: fetches (evidence: `src/components/providers.tsx`)
- App state → Workflow forms: opens (evidence: `src/components/providers.tsx`)
- Workflow forms → API client: submits (evidence: `src/components/forms.tsx`)
- Workflow forms → Jalali picker: renders (evidence: `src/components/forms.tsx`)
- Daily timeline → Jalali picker: opens (evidence: `src/components/home-tab.tsx`)
- Workflow forms → UI primitives: renders (evidence: `src/components/forms.tsx`)
- App state → UI primitives: renders (evidence: `src/components/providers.tsx`)
- App state → Telegram SDK: uses (evidence: `src/components/providers.tsx`)
- API client → Appointment routes: requests (evidence: `README.md`)
- API client → Patient routes: requests (evidence: `README.md`)
- API client → Profile and clinic: requests (evidence: `README.md`)
- API client → Working hours: requests (evidence: `README.md`)
- API client → Unavailable slots: requests (evidence: `README.md`)
- Appointment routes → Session access: requires user (evidence: `src/app/api/appointments/route.ts`)
- Patient routes → Session access: requires user (evidence: `src/app/api/patients/route.ts`)
- Profile and clinic → Session access: requires user (evidence: `src/app/api/profile/route.ts`)
- Working hours → Session access: requires user (evidence: `src/app/api/working-hours/route.ts`)
- Unavailable slots → Session access: requires user (evidence: `src/app/api/unavailable/route.ts`)
- Appointment routes → Conflict checking: checks conflicts (evidence: `src/app/api/appointments/route.ts`)
- Appointment routes → Appointment DTOs: maps results (evidence: `src/app/api/appointments/route.ts`)
- Appointment routes → PostgreSQL: queries (evidence: `src/app/api/appointments/route.ts`)
- Patient routes → PostgreSQL: queries (evidence: `src/app/api/patients/route.ts`)
- Profile and clinic → PostgreSQL: queries (evidence: `src/app/api/profile/route.ts`)
- Working hours → PostgreSQL: queries (evidence: `src/app/api/working-hours/route.ts`)
- Unavailable slots → PostgreSQL: queries (evidence: `src/app/api/unavailable/route.ts`)
- Telegram sign-in → Telegram platform: validates initData (evidence: `README.md`)
- Telegram sign-in → Session access: creates session (evidence: `src/app/api/auth/telegram/route.ts`)
- Telegram sign-in → Account defaults: bootstraps demo (evidence: `src/app/api/auth/telegram/route.ts`)
- Session access → PostgreSQL: reads and writes (evidence: `src/lib/session.ts`)
- Account defaults → PostgreSQL: initializes records (evidence: `src/lib/seed.ts`)
- PostgreSQL → Clinic data model: uses tables (evidence: `README.md`)
- Conflict checking → PostgreSQL: checks schedule data (evidence: `src/lib/appointments.ts`)
- Appointment routes → Date and formatting: validates dates (evidence: `src/app/api/appointments/route.ts`)
