# medsync1990/medsync architecture

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

- Interactive diagram: https://gitdiagram.com/medsync1990/medsync
- Repository: https://github.com/medsync1990/medsync

## Overview

MedSync is a role-based, multi-branch clinic management system. Its main workflow runs from patient registration and appointment booking through consultation and treatment recording to invoicing, payment, and insurance handling; reporting provides an additional operational and financial view. The React app calls a FastAPI API backed by shared PostgreSQL. The graph preserves the documented domain areas and core frontend pages; unsampled modules are represented at their exact file paths, but their internal calls are not inferred.

Main entry points: [`backend/app/main.py`](https://github.com/medsync1990/medsync/blob/main/backend/app/main.py) (FastAPI application), [`frontend/src/api/client.ts`](https://github.com/medsync1990/medsync/blob/main/frontend/src/api/client.ts) (API client), [`backend/app/db.py`](https://github.com/medsync1990/medsync/blob/main/backend/app/db.py) (Connection and RLS context), [`backend/app/routers/appointments.py`](https://github.com/medsync1990/medsync/blob/main/backend/app/routers/appointments.py) (Appointments)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web application"]
  node_web_app["Role-based web app<br/>[App.tsx]"]
  node_routes["Role routes<br/>[routes.tsx]"]
  node_auth_context["Session context<br/>[AuthContext.tsx]"]
  node_api_client["API client<br/>[client.ts]"]
  node_patient_ui["Patient registration"]
  node_appointment_ui["Appointment booking"]
  node_consultation_ui["Consultation workflow<br/>[Consultation.tsx]"]
  node_billing_ui["Invoice and payment UI<br/>[CollectPayment.tsx]"]
  node_reports_ui["Reports UI<br/>[DoctorRevenue.tsx]"]
end

subgraph group_api["API and access control"]
  node_api_app["FastAPI application<br/>[main.py]"]
  node_auth_api["Authentication<br/>[auth.py]"]
  node_access["Identity and branch access<br/>[dependencies.py]"]
  node_db_access["Connection and RLS context<br/>[db.py]"]
end

subgraph group_clinic["Clinic operations"]
  node_patients["Patients and allergies<br/>[patients.py]"]
  node_appointments["Appointments<br/>[appointments.py]"]
  node_consultations["Consultations and treatments<br/>[consultations.py]"]
  node_branches_staff["Branches and staff<br/>[branches.py]"]
end

subgraph group_finance["Billing and insights"]
  node_billing["Invoices and payments<br/>[invoices.py]"]
  node_insurance["Insurance<br/>[insurance.py]"]
  node_reports["Reporting and statistics<br/>[reports.py]"]
end

node_staff_user(("Clinic staff"))
node_postgres[("Shared PostgreSQL")]

node_staff_user -->|"uses"| node_web_app
node_web_app -->|"renders"| node_routes
node_routes -->|"checks roles"| node_auth_context
node_web_app -->|"provides session"| node_auth_context
node_patient_ui -->|"sends requests"| node_api_client
node_appointment_ui -->|"sends requests"| node_api_client
node_consultation_ui -.->|"calls API"| node_api_client
node_billing_ui -.->|"calls API"| node_api_client
node_reports_ui -.->|"calls API"| node_api_client
node_api_client -->|"HTTP requests"| node_api_app
node_api_app -->|"mounts routes"| node_auth_api
node_api_app -->|"mounts routes"| node_patients
node_api_app -->|"mounts routes"| node_appointments
node_api_app -->|"mounts routes"| node_consultations
node_api_app -->|"mounts routes"| node_branches_staff
node_api_app -->|"mounts routes"| node_billing
node_api_app -->|"mounts routes"| node_insurance
node_api_app -->|"mounts routes"| node_reports
node_auth_api -->|"uses identity"| node_access
node_access -->|"gets connections"| node_db_access
node_patients -->|"queries data"| node_db_access
node_appointments -->|"gets connections"| node_db_access
node_reports -->|"gets connections"| node_db_access
node_api_app -->|"opens pools"| node_postgres
node_db_access -->|"acquires connections"| node_postgres
node_patients -.->|"supports booking flow"| node_appointments
node_appointments -.->|"precedes care"| node_consultations
node_consultations -.->|"feeds billing"| node_billing
node_billing -.->|"handles claims"| node_insurance
node_reports -.->|"queries metrics"| node_postgres

click node_web_app "https://github.com/medsync1990/medsync/blob/main/frontend/src/app/App.tsx"
click node_routes "https://github.com/medsync1990/medsync/blob/main/frontend/src/app/routes.tsx"
click node_auth_context "https://github.com/medsync1990/medsync/blob/main/frontend/src/context/AuthContext.tsx"
click node_api_client "https://github.com/medsync1990/medsync/blob/main/frontend/src/api/client.ts"
click node_patient_ui "https://github.com/medsync1990/medsync/blob/main/frontend/src/pages/receptionist/RegisterPatient.tsx"
click node_appointment_ui "https://github.com/medsync1990/medsync/blob/main/frontend/src/pages/receptionist/BookAppointment.tsx"
click node_consultation_ui "https://github.com/medsync1990/medsync/blob/main/frontend/src/pages/doctor/Consultation.tsx"
click node_billing_ui "https://github.com/medsync1990/medsync/blob/main/frontend/src/pages/receptionist/CollectPayment.tsx"
click node_reports_ui "https://github.com/medsync1990/medsync/blob/main/frontend/src/pages/reports/DoctorRevenue.tsx"
click node_api_app "https://github.com/medsync1990/medsync/blob/main/backend/app/main.py"
click node_auth_api "https://github.com/medsync1990/medsync/blob/main/backend/app/routers/auth.py"
click node_access "https://github.com/medsync1990/medsync/blob/main/backend/app/dependencies.py"
click node_db_access "https://github.com/medsync1990/medsync/blob/main/backend/app/db.py"
click node_patients "https://github.com/medsync1990/medsync/blob/main/backend/app/routers/patients.py"
click node_appointments "https://github.com/medsync1990/medsync/blob/main/backend/app/routers/appointments.py"
click node_consultations "https://github.com/medsync1990/medsync/blob/main/backend/app/routers/consultations.py"
click node_branches_staff "https://github.com/medsync1990/medsync/blob/main/backend/app/routers/branches.py"
click node_billing "https://github.com/medsync1990/medsync/blob/main/backend/app/routers/invoices.py"
click node_insurance "https://github.com/medsync1990/medsync/blob/main/backend/app/routers/insurance.py"
click node_reports "https://github.com/medsync1990/medsync/blob/main/backend/app/routers/reports.py"

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_web_app,node_routes,node_auth_context,node_api_client,node_patient_ui,node_appointment_ui,node_consultation_ui,node_billing_ui,node_reports_ui toneBlue
class node_api_app,node_auth_api,node_access,node_db_access,node_postgres toneAmber
class node_patients,node_appointments,node_consultations,node_branches_staff toneMint
class node_billing,node_insurance,node_reports toneRose
class node_staff_user toneIndigo
```

## Components

### Web application

- [Role-based web app](https://github.com/medsync1990/medsync/blob/main/frontend/src/app/App.tsx): `frontend/src/app/App.tsx`
- [Role routes](https://github.com/medsync1990/medsync/blob/main/frontend/src/app/routes.tsx): `frontend/src/app/routes.tsx`
- [Session context](https://github.com/medsync1990/medsync/blob/main/frontend/src/context/AuthContext.tsx): `frontend/src/context/AuthContext.tsx`
- [API client](https://github.com/medsync1990/medsync/blob/main/frontend/src/api/client.ts): `frontend/src/api/client.ts`
- [Patient registration](https://github.com/medsync1990/medsync/blob/main/frontend/src/pages/receptionist/RegisterPatient.tsx): `frontend/src/pages/receptionist/RegisterPatient.tsx`
- [Appointment booking](https://github.com/medsync1990/medsync/blob/main/frontend/src/pages/receptionist/BookAppointment.tsx): `frontend/src/pages/receptionist/BookAppointment.tsx`
- [Consultation workflow](https://github.com/medsync1990/medsync/blob/main/frontend/src/pages/doctor/Consultation.tsx): `frontend/src/pages/doctor/Consultation.tsx`
- [Invoice and payment UI](https://github.com/medsync1990/medsync/blob/main/frontend/src/pages/receptionist/CollectPayment.tsx): `frontend/src/pages/receptionist/CollectPayment.tsx`
- [Reports UI](https://github.com/medsync1990/medsync/blob/main/frontend/src/pages/reports/DoctorRevenue.tsx): `frontend/src/pages/reports/DoctorRevenue.tsx`

### API and access control

- [FastAPI application](https://github.com/medsync1990/medsync/blob/main/backend/app/main.py): `backend/app/main.py`
- [Authentication](https://github.com/medsync1990/medsync/blob/main/backend/app/routers/auth.py): `backend/app/routers/auth.py`
- [Identity and branch access](https://github.com/medsync1990/medsync/blob/main/backend/app/dependencies.py): `backend/app/dependencies.py`
- [Connection and RLS context](https://github.com/medsync1990/medsync/blob/main/backend/app/db.py): `backend/app/db.py`

### Clinic operations

- [Patients and allergies](https://github.com/medsync1990/medsync/blob/main/backend/app/routers/patients.py): `backend/app/routers/patients.py`
- [Appointments](https://github.com/medsync1990/medsync/blob/main/backend/app/routers/appointments.py): `backend/app/routers/appointments.py`
- [Consultations and treatments](https://github.com/medsync1990/medsync/blob/main/backend/app/routers/consultations.py): `backend/app/routers/consultations.py`
- [Branches and staff](https://github.com/medsync1990/medsync/blob/main/backend/app/routers/branches.py): `backend/app/routers/branches.py`

### Billing and insights

- [Invoices and payments](https://github.com/medsync1990/medsync/blob/main/backend/app/routers/invoices.py): `backend/app/routers/invoices.py`
- [Insurance](https://github.com/medsync1990/medsync/blob/main/backend/app/routers/insurance.py): `backend/app/routers/insurance.py`
- [Reporting and statistics](https://github.com/medsync1990/medsync/blob/main/backend/app/routers/reports.py): `backend/app/routers/reports.py`

### Other components

- **Clinic staff**
- **Shared PostgreSQL**

## Connections

- Clinic staff → Role-based web app: uses (evidence: `README.md`)
- Role-based web app → Role routes: renders (evidence: `frontend/src/app/App.tsx`)
- Role routes → Session context: checks roles (evidence: `frontend/src/app/routes.tsx`)
- Role-based web app → Session context: provides session (evidence: `frontend/src/app/App.tsx`)
- Patient registration → API client: sends requests
- Appointment booking → API client: sends requests (evidence: `frontend/src/pages/receptionist/BookAppointment.tsx`)
- Consultation workflow → API client: calls API
- Invoice and payment UI → API client: calls API
- Reports UI → API client: calls API
- API client → FastAPI application: HTTP requests (evidence: `frontend/src/api/client.ts`)
- FastAPI application → Authentication: mounts routes (evidence: `backend/app/main.py`)
- FastAPI application → Patients and allergies: mounts routes (evidence: `backend/app/main.py`)
- FastAPI application → Appointments: mounts routes (evidence: `backend/app/main.py`)
- FastAPI application → Consultations and treatments: mounts routes (evidence: `backend/app/main.py`)
- FastAPI application → Branches and staff: mounts routes (evidence: `backend/app/main.py`)
- FastAPI application → Invoices and payments: mounts routes (evidence: `backend/app/main.py`)
- FastAPI application → Insurance: mounts routes (evidence: `backend/app/main.py`)
- FastAPI application → Reporting and statistics: mounts routes (evidence: `backend/app/main.py`)
- Authentication → Identity and branch access: uses identity (evidence: `backend/app/routers/auth.py`)
- Identity and branch access → Connection and RLS context: gets connections (evidence: `backend/app/dependencies.py`)
- Patients and allergies → Connection and RLS context: queries data (evidence: `backend/app/routers/patients.py`)
- Appointments → Connection and RLS context: gets connections (evidence: `backend/app/routers/appointments.py`)
- Reporting and statistics → Connection and RLS context: gets connections (evidence: `backend/app/routers/reports.py`)
- FastAPI application → Shared PostgreSQL: opens pools (evidence: `backend/app/main.py`)
- Connection and RLS context → Shared PostgreSQL: acquires connections (evidence: `backend/app/db.py`)
- Patients and allergies → Appointments: supports booking flow
- Appointments → Consultations and treatments: precedes care (evidence: `README.md`)
- Consultations and treatments → Invoices and payments: feeds billing (evidence: `README.md`)
- Invoices and payments → Insurance: handles claims (evidence: `README.md`)
- Reporting and statistics → Shared PostgreSQL: queries metrics (evidence: `README.md`)
