# gildaciolopes/doctor-schedule architecture

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

- Interactive diagram: https://gitdiagram.com/gildaciolopes/doctor-schedule
- Repository: https://github.com/gildaciolopes/doctor-schedule

## Overview

Dr. Schedule is a clinic-management SaaS. Its documented user journey is account creation/login, subscription or trial access, clinic setup, then managing doctors, patients and appointments and reviewing clinic metrics. The repository separates Next.js screens and API routes from server actions, authentication/session logic, dashboard queries and Drizzle/PostgreSQL data. The README documents the broad product workflow; source-index references and excerpts support the implementation links shown. Several CRUD and billing internals were not sampled, so their specific call paths are not inferred.

Main entry points: [`src/db/index.ts`](https://github.com/gildaciolopes/doctor-schedule/blob/main/src/db/index.ts) (Drizzle connection), [`src/lib/auth.ts`](https://github.com/gildaciolopes/doctor-schedule/blob/main/src/lib/auth.ts) (Auth service), [`src/app/api/export/[entity]/route.ts`](https://github.com/gildaciolopes/doctor-schedule/blob/main/src/app/api/export/%5Bentity%5D/route.ts) (Data export), [`src/hocs/with-authentication.tsx`](https://github.com/gildaciolopes/doctor-schedule/blob/main/src/hocs/with-authentication.tsx) (Access guard)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["Web experience"]
  node_landing["Marketing site<br/>[page.tsx]"]
end

subgraph group_clinic["Clinic operations"]
  node_clinicsetup["Clinic setup<br/>[index.ts]"]
  node_doctors["Doctor management"]
  node_patients["Patient management"]
  node_appointments["Appointment management"]
  node_availability["Available times<br/>[index.ts]"]
  node_dashboard["Clinic dashboard<br/>[page.tsx]"]
  node_dashboarddata["Dashboard queries<br/>[get-dashboard.ts]"]
  node_export["Data export<br/>[route.ts]"]
end

subgraph group_identity["Identity and access"]
  node_authscreen["Account screens"]
  node_authapi["Auth API<br/>[route.ts]"]
  node_authcore["Auth service<br/>[auth.ts]"]
  node_session["Session lookup<br/>[get-session.ts]"]
  node_access["Access guard"]
  node_trial["Trial rules<br/>[demo-trial.ts]"]
end

subgraph group_platform["Data and billing"]
  node_subscription["Subscription screen"]
  node_checkout["Checkout action<br/>[index.ts]"]
  node_webhook["Billing webhook<br/>[route.ts]"]
  node_database[("PostgreSQL data<br/>[schema.ts]")]
  node_dbclient["Drizzle connection<br/>[index.ts]"]
end

node_visitor(("Visitor / staff"))
node_stripe(("Stripe"))

node_visitor -->|"visits"| node_landing
node_visitor -->|"signs up"| node_authscreen
node_authscreen -.->|"authenticates"| node_authapi
node_authapi -.->|"routes to"| node_authcore
node_authcore -->|"reads session data"| node_dbclient
node_dbclient -->|"maps schema"| node_database
node_session -->|"gets session"| node_authcore
node_access -->|"checks session"| node_session
node_access -->|"checks trial"| node_trial
node_visitor -->|"selects plan"| node_subscription
node_subscription -->|"starts checkout"| node_checkout
node_checkout -.->|"creates checkout"| node_stripe
node_stripe -->|"sends events"| node_webhook
node_webhook -->|"updates billing data"| node_dbclient
node_visitor -->|"creates clinic"| node_clinicsetup
node_visitor -->|"manages doctors"| node_doctors
node_visitor -->|"manages patients"| node_patients
node_visitor -->|"manages appointments"| node_appointments
node_appointments -.->|"requests times"| node_availability
node_availability -->|"queries schedules"| node_dbclient
node_visitor -->|"views metrics"| node_dashboard
node_dashboard -.->|"loads metrics"| node_dashboarddata
node_dashboarddata -->|"queries clinic data"| node_dbclient
node_visitor -.->|"requests export"| node_export
node_export -->|"checks session"| node_authcore
node_export -->|"reads clinic records"| node_dbclient

click node_landing "https://github.com/gildaciolopes/doctor-schedule/blob/main/src/app/page.tsx"
click node_authscreen "https://github.com/gildaciolopes/doctor-schedule/tree/main/src/app/authentication"
click node_authapi "https://github.com/gildaciolopes/doctor-schedule/blob/main/src/app/api/auth/%5B...all%5D/route.ts"
click node_authcore "https://github.com/gildaciolopes/doctor-schedule/blob/main/src/lib/auth.ts"
click node_session "https://github.com/gildaciolopes/doctor-schedule/blob/main/src/lib/get-session.ts"
click node_access "https://github.com/gildaciolopes/doctor-schedule/blob/main/src/hocs/with-authentication.tsx"
click node_trial "https://github.com/gildaciolopes/doctor-schedule/blob/main/src/helpers/demo-trial.ts"
click node_subscription "https://github.com/gildaciolopes/doctor-schedule/blob/main/src/app/(protected)/subscription/_components/subscription-plan.tsx"
click node_checkout "https://github.com/gildaciolopes/doctor-schedule/blob/main/src/actions/create-stripe-checkout/index.ts"
click node_webhook "https://github.com/gildaciolopes/doctor-schedule/blob/main/src/app/api/stripe/webhook/route.ts"
click node_clinicsetup "https://github.com/gildaciolopes/doctor-schedule/blob/main/src/actions/create-clinic/index.ts"
click node_doctors "https://github.com/gildaciolopes/doctor-schedule/tree/main/src/app/(protected)/doctors"
click node_patients "https://github.com/gildaciolopes/doctor-schedule/tree/main/src/app/(protected)/patients"
click node_appointments "https://github.com/gildaciolopes/doctor-schedule/tree/main/src/app/(protected)/appointments"
click node_availability "https://github.com/gildaciolopes/doctor-schedule/blob/main/src/actions/get-available-times/index.ts"
click node_dashboard "https://github.com/gildaciolopes/doctor-schedule/blob/main/src/app/(protected)/dashboard/page.tsx"
click node_dashboarddata "https://github.com/gildaciolopes/doctor-schedule/blob/main/src/data/get-dashboard.ts"
click node_export "https://github.com/gildaciolopes/doctor-schedule/blob/main/src/app/api/export/%5Bentity%5D/route.ts"
click node_database "https://github.com/gildaciolopes/doctor-schedule/blob/main/src/db/schema.ts"
click node_dbclient "https://github.com/gildaciolopes/doctor-schedule/blob/main/src/db/index.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_landing toneBlue
class node_clinicsetup,node_doctors,node_patients,node_appointments,node_availability,node_dashboard,node_dashboarddata,node_export toneAmber
class node_authscreen,node_authapi,node_authcore,node_session,node_access,node_trial toneMint
class node_subscription,node_checkout,node_webhook,node_database,node_dbclient toneRose
class node_visitor,node_stripe toneIndigo
```

## Components

### Web experience

- [Marketing site](https://github.com/gildaciolopes/doctor-schedule/blob/main/src/app/page.tsx): `src/app/page.tsx`

### Clinic operations

- [Clinic setup](https://github.com/gildaciolopes/doctor-schedule/blob/main/src/actions/create-clinic/index.ts): `src/actions/create-clinic/index.ts`
- [Doctor management](https://github.com/gildaciolopes/doctor-schedule/tree/main/src/app/(protected)/doctors): `src/app/(protected)/doctors`
- [Patient management](https://github.com/gildaciolopes/doctor-schedule/tree/main/src/app/(protected)/patients): `src/app/(protected)/patients`
- [Appointment management](https://github.com/gildaciolopes/doctor-schedule/tree/main/src/app/(protected)/appointments): `src/app/(protected)/appointments`
- [Available times](https://github.com/gildaciolopes/doctor-schedule/blob/main/src/actions/get-available-times/index.ts): `src/actions/get-available-times/index.ts`
- [Clinic dashboard](https://github.com/gildaciolopes/doctor-schedule/blob/main/src/app/(protected)/dashboard/page.tsx): `src/app/(protected)/dashboard/page.tsx`
- [Dashboard queries](https://github.com/gildaciolopes/doctor-schedule/blob/main/src/data/get-dashboard.ts): `src/data/get-dashboard.ts`
- [Data export](https://github.com/gildaciolopes/doctor-schedule/blob/main/src/app/api/export/%5Bentity%5D/route.ts): `src/app/api/export/[entity]/route.ts`

### Identity and access

- [Account screens](https://github.com/gildaciolopes/doctor-schedule/tree/main/src/app/authentication): `src/app/authentication`
- [Auth API](https://github.com/gildaciolopes/doctor-schedule/blob/main/src/app/api/auth/%5B...all%5D/route.ts): `src/app/api/auth/[...all]/route.ts`
- [Auth service](https://github.com/gildaciolopes/doctor-schedule/blob/main/src/lib/auth.ts): `src/lib/auth.ts`
- [Session lookup](https://github.com/gildaciolopes/doctor-schedule/blob/main/src/lib/get-session.ts): `src/lib/get-session.ts`
- [Access guard](https://github.com/gildaciolopes/doctor-schedule/blob/main/src/hocs/with-authentication.tsx): `src/hocs/with-authentication.tsx`
- [Trial rules](https://github.com/gildaciolopes/doctor-schedule/blob/main/src/helpers/demo-trial.ts): `src/helpers/demo-trial.ts`

### Data and billing

- [Subscription screen](https://github.com/gildaciolopes/doctor-schedule/blob/main/src/app/(protected)/subscription/_components/subscription-plan.tsx): `src/app/(protected)/subscription/_components/subscription-plan.tsx`
- [Checkout action](https://github.com/gildaciolopes/doctor-schedule/blob/main/src/actions/create-stripe-checkout/index.ts): `src/actions/create-stripe-checkout/index.ts`
- [Billing webhook](https://github.com/gildaciolopes/doctor-schedule/blob/main/src/app/api/stripe/webhook/route.ts): `src/app/api/stripe/webhook/route.ts`
- [PostgreSQL data](https://github.com/gildaciolopes/doctor-schedule/blob/main/src/db/schema.ts): `src/db/schema.ts`
- [Drizzle connection](https://github.com/gildaciolopes/doctor-schedule/blob/main/src/db/index.ts): `src/db/index.ts`

### Other components

- **Visitor / staff**
- **Stripe**

## Connections

- Visitor / staff → Marketing site: visits (evidence: `src/app/page.tsx`)
- Visitor / staff → Account screens: signs up (evidence: `README.md`)
- Account screens → Auth API: authenticates
- Auth API → Auth service: routes to
- Auth service → Drizzle connection: reads session data (evidence: `src/lib/auth.ts`)
- Drizzle connection → PostgreSQL data: maps schema (evidence: `src/db/index.ts`)
- Session lookup → Auth service: gets session (evidence: `src/lib/get-session.ts`)
- Access guard → Session lookup: checks session (evidence: `src/hocs/with-authentication.tsx`)
- Access guard → Trial rules: checks trial (evidence: `src/hocs/with-authentication.tsx`)
- Visitor / staff → Subscription screen: selects plan (evidence: `README.md`)
- Subscription screen → Checkout action: starts checkout (evidence: `src/app/(protected)/subscription/_components/subscription-plan.tsx`)
- Checkout action → Stripe: creates checkout
- Stripe → Billing webhook: sends events (evidence: `README.md`)
- Billing webhook → Drizzle connection: updates billing data (evidence: `src/app/api/stripe/webhook/route.ts`)
- Visitor / staff → Clinic setup: creates clinic (evidence: `README.md`)
- Visitor / staff → Doctor management: manages doctors (evidence: `README.md`)
- Visitor / staff → Patient management: manages patients (evidence: `README.md`)
- Visitor / staff → Appointment management: manages appointments (evidence: `README.md`)
- Appointment management → Available times: requests times
- Available times → Drizzle connection: queries schedules (evidence: `src/actions/get-available-times/index.ts`)
- Visitor / staff → Clinic dashboard: views metrics (evidence: `README.md`)
- Clinic dashboard → Dashboard queries: loads metrics
- Dashboard queries → Drizzle connection: queries clinic data (evidence: `src/data/get-dashboard.ts`)
- Visitor / staff → Data export: requests export
- Data export → Auth service: checks session (evidence: `src/app/api/export/[entity]/route.ts`)
- Data export → Drizzle connection: reads clinic records (evidence: `src/app/api/export/[entity]/route.ts`)
