# apollo-level2-web-dev/l2b6-backend-ph-healthcare-management-system architecture

> Architecture diagram of the GitHub repository apollo-level2-web-dev/l2b6-backend-ph-healthcare-management-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/apollo-level2-web-dev/l2b6-backend-ph-healthcare-management-system
- Repository: https://github.com/apollo-level2-web-dev/l2b6-backend-ph-healthcare-management-system

## Overview

This is a healthcare appointment-booking API: clients use authentication and browse doctors, specialties, and schedules, then book appointments and pay through Stripe. The server exposes the API and also runs unpaid-appointment cancellation; Stripe webhooks are a separate payment-update entry point. The graph preserves the major domain modules visible in the tree. Several route, service, and integration implementations were not excerpted, so their internal dispatch relationships are omitted rather than inferred.

Main entry points: [`src/app/lib/prisma.ts`](https://github.com/apollo-level2-web-dev/l2b6-backend-ph-healthcare-management-system/blob/development/src/app/lib/prisma.ts) (PostgreSQL database), [`src/app.ts`](https://github.com/apollo-level2-web-dev/l2b6-backend-ph-healthcare-management-system/blob/development/src/app.ts) (Express application), [`src/app/module/payment/payment.controller.ts`](https://github.com/apollo-level2-web-dev/l2b6-backend-ph-healthcare-management-system/blob/development/src/app/module/payment/payment.controller.ts) (Payment webhook), [`src/app/module/auth/auth.service.ts`](https://github.com/apollo-level2-web-dev/l2b6-backend-ph-healthcare-management-system/blob/development/src/app/module/auth/auth.service.ts) (Auth operations)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["API entry"]
  node_server["HTTP server<br/>[server.ts]"]
  node_app["Express application<br/>[app.ts]"]
  node_routes["API routes<br/>[index.ts]"]
  node_response["HTTP responses<br/>[sendResponse.ts]"]
  node_async_errors["Async error wrapper<br/>[catchAsync.ts]"]
end

subgraph group_identity["Identity and accounts"]
  node_auth_api["Auth endpoints<br/>[auth.controller.ts]"]
  node_auth_service["Auth operations<br/>[auth.service.ts]"]
  node_auth_engine["Better Auth<br/>[auth.ts]"]
  node_users["User management<br/>[user.service.ts]"]
  node_request_user["Request identity"]
end

subgraph group_care["Care scheduling"]
  node_doctors["Doctor directory<br/>[doctor.service.ts]"]
  node_specialties["Specialties"]
  node_schedules["Schedules"]
  node_doctor_schedules["Doctor schedules"]
  node_appointments["Appointments"]
  node_admin["Administration<br/>[admin.service.ts]"]
end

subgraph group_platform["Payments and platform"]
  node_payment_webhook["Payment webhook"]
  node_payments["Payment handling<br/>[payment.service.ts]"]
  node_stripe["Stripe client<br/>[stripe.config.ts]"]
  node_database[("PostgreSQL database<br/>[prisma.ts]")]
  node_query_builder["Query builder<br/>[QueryBuilder.ts]"]
  node_query_types["Query interfaces<br/>[query.interface.ts]"]
  node_env["Environment config<br/>[env.ts]"]
  node_cron["Scheduled cleanup"]
end

node_client(("API client"))

node_client -->|"sends requests"| node_app
node_server -->|"starts"| node_app
node_app -->|"mounts API"| node_routes
node_app -->|"mounts auth"| node_auth_engine
node_app -->|"registers webhook"| node_payment_webhook
node_app -->|"schedules cleanup"| node_cron
node_cron -->|"cancels unpaid"| node_appointments
node_auth_api -->|"calls"| node_auth_service
node_auth_service -->|"uses"| node_auth_engine
node_auth_engine -->|"persists auth"| node_database
node_auth_service -->|"reads and writes"| node_database
node_users -->|"reads and writes"| node_database
node_doctors -->|"queries"| node_database
node_specialties -->|"queries"| node_database
node_schedules -->|"queries"| node_database
node_doctor_schedules -->|"queries"| node_database
node_appointments -->|"reads and writes"| node_database
node_appointments -->|"creates checkout"| node_stripe
node_payment_webhook -->|"verifies event"| node_stripe
node_payment_webhook -->|"dispatches event"| node_payments
node_payments -->|"updates payment"| node_database
node_doctors -->|"builds queries"| node_query_builder
node_schedules -->|"builds queries"| node_query_builder
node_doctor_schedules -->|"builds queries"| node_query_builder
node_query_builder -->|"uses types"| node_query_types
node_auth_engine -->|"reads settings"| node_env
node_database -->|"reads database URL"| node_env
node_auth_service -->|"uses identity"| node_request_user
node_auth_api -->|"formats responses"| node_response
node_payment_webhook -->|"formats responses"| node_response
node_payment_webhook -->|"wraps handler"| node_async_errors

click node_server "https://github.com/apollo-level2-web-dev/l2b6-backend-ph-healthcare-management-system/blob/development/src/server.ts"
click node_app "https://github.com/apollo-level2-web-dev/l2b6-backend-ph-healthcare-management-system/blob/development/src/app.ts"
click node_routes "https://github.com/apollo-level2-web-dev/l2b6-backend-ph-healthcare-management-system/blob/development/src/app/routes/index.ts"
click node_auth_api "https://github.com/apollo-level2-web-dev/l2b6-backend-ph-healthcare-management-system/blob/development/src/app/module/auth/auth.controller.ts"
click node_auth_service "https://github.com/apollo-level2-web-dev/l2b6-backend-ph-healthcare-management-system/blob/development/src/app/module/auth/auth.service.ts"
click node_auth_engine "https://github.com/apollo-level2-web-dev/l2b6-backend-ph-healthcare-management-system/blob/development/src/app/lib/auth.ts"
click node_users "https://github.com/apollo-level2-web-dev/l2b6-backend-ph-healthcare-management-system/blob/development/src/app/module/user/user.service.ts"
click node_doctors "https://github.com/apollo-level2-web-dev/l2b6-backend-ph-healthcare-management-system/blob/development/src/app/module/doctor/doctor.service.ts"
click node_specialties "https://github.com/apollo-level2-web-dev/l2b6-backend-ph-healthcare-management-system/blob/development/src/app/module/specialty/specialty.service.ts"
click node_schedules "https://github.com/apollo-level2-web-dev/l2b6-backend-ph-healthcare-management-system/blob/development/src/app/module/schedule/schedule.service.ts"
click node_doctor_schedules "https://github.com/apollo-level2-web-dev/l2b6-backend-ph-healthcare-management-system/blob/development/src/app/module/doctorSchedule/doctorSchedule.service.ts"
click node_appointments "https://github.com/apollo-level2-web-dev/l2b6-backend-ph-healthcare-management-system/blob/development/src/app/module/appointment/appointment.service.ts"
click node_admin "https://github.com/apollo-level2-web-dev/l2b6-backend-ph-healthcare-management-system/blob/development/src/app/module/admin/admin.service.ts"
click node_payment_webhook "https://github.com/apollo-level2-web-dev/l2b6-backend-ph-healthcare-management-system/blob/development/src/app/module/payment/payment.controller.ts"
click node_payments "https://github.com/apollo-level2-web-dev/l2b6-backend-ph-healthcare-management-system/blob/development/src/app/module/payment/payment.service.ts"
click node_stripe "https://github.com/apollo-level2-web-dev/l2b6-backend-ph-healthcare-management-system/blob/development/src/app/config/stripe.config.ts"
click node_database "https://github.com/apollo-level2-web-dev/l2b6-backend-ph-healthcare-management-system/blob/development/src/app/lib/prisma.ts"
click node_query_builder "https://github.com/apollo-level2-web-dev/l2b6-backend-ph-healthcare-management-system/blob/development/src/app/utils/QueryBuilder.ts"
click node_query_types "https://github.com/apollo-level2-web-dev/l2b6-backend-ph-healthcare-management-system/blob/development/src/app/interfaces/query.interface.ts"
click node_request_user "https://github.com/apollo-level2-web-dev/l2b6-backend-ph-healthcare-management-system/blob/development/src/app/interfaces/requestUser.interface.ts"
click node_env "https://github.com/apollo-level2-web-dev/l2b6-backend-ph-healthcare-management-system/blob/development/src/app/config/env.ts"
click node_response "https://github.com/apollo-level2-web-dev/l2b6-backend-ph-healthcare-management-system/blob/development/src/app/shared/sendResponse.ts"
click node_async_errors "https://github.com/apollo-level2-web-dev/l2b6-backend-ph-healthcare-management-system/blob/development/src/app/shared/catchAsync.ts"
click node_cron "https://github.com/apollo-level2-web-dev/l2b6-backend-ph-healthcare-management-system/blob/development/src/app/module/appointment/appointment.service.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_server,node_app,node_routes,node_response,node_async_errors,node_client toneBlue
class node_auth_api,node_auth_service,node_auth_engine,node_users,node_request_user toneAmber
class node_doctors,node_specialties,node_schedules,node_doctor_schedules,node_appointments,node_admin toneMint
class node_payment_webhook,node_payments,node_stripe,node_database,node_query_builder,node_query_types,node_env,node_cron toneRose
```

## Components

### API entry

- [HTTP server](https://github.com/apollo-level2-web-dev/l2b6-backend-ph-healthcare-management-system/blob/development/src/server.ts): `src/server.ts`
- [Express application](https://github.com/apollo-level2-web-dev/l2b6-backend-ph-healthcare-management-system/blob/development/src/app.ts): `src/app.ts`
- [API routes](https://github.com/apollo-level2-web-dev/l2b6-backend-ph-healthcare-management-system/blob/development/src/app/routes/index.ts): `src/app/routes/index.ts`
- [HTTP responses](https://github.com/apollo-level2-web-dev/l2b6-backend-ph-healthcare-management-system/blob/development/src/app/shared/sendResponse.ts): `src/app/shared/sendResponse.ts`
- [Async error wrapper](https://github.com/apollo-level2-web-dev/l2b6-backend-ph-healthcare-management-system/blob/development/src/app/shared/catchAsync.ts): `src/app/shared/catchAsync.ts`

### Identity and accounts

- [Auth endpoints](https://github.com/apollo-level2-web-dev/l2b6-backend-ph-healthcare-management-system/blob/development/src/app/module/auth/auth.controller.ts): `src/app/module/auth/auth.controller.ts`
- [Auth operations](https://github.com/apollo-level2-web-dev/l2b6-backend-ph-healthcare-management-system/blob/development/src/app/module/auth/auth.service.ts): `src/app/module/auth/auth.service.ts`
- [Better Auth](https://github.com/apollo-level2-web-dev/l2b6-backend-ph-healthcare-management-system/blob/development/src/app/lib/auth.ts): `src/app/lib/auth.ts`
- [User management](https://github.com/apollo-level2-web-dev/l2b6-backend-ph-healthcare-management-system/blob/development/src/app/module/user/user.service.ts): `src/app/module/user/user.service.ts`
- [Request identity](https://github.com/apollo-level2-web-dev/l2b6-backend-ph-healthcare-management-system/blob/development/src/app/interfaces/requestUser.interface.ts): `src/app/interfaces/requestUser.interface.ts`

### Care scheduling

- [Doctor directory](https://github.com/apollo-level2-web-dev/l2b6-backend-ph-healthcare-management-system/blob/development/src/app/module/doctor/doctor.service.ts): `src/app/module/doctor/doctor.service.ts`
- [Specialties](https://github.com/apollo-level2-web-dev/l2b6-backend-ph-healthcare-management-system/blob/development/src/app/module/specialty/specialty.service.ts): `src/app/module/specialty/specialty.service.ts`
- [Schedules](https://github.com/apollo-level2-web-dev/l2b6-backend-ph-healthcare-management-system/blob/development/src/app/module/schedule/schedule.service.ts): `src/app/module/schedule/schedule.service.ts`
- [Doctor schedules](https://github.com/apollo-level2-web-dev/l2b6-backend-ph-healthcare-management-system/blob/development/src/app/module/doctorSchedule/doctorSchedule.service.ts): `src/app/module/doctorSchedule/doctorSchedule.service.ts`
- [Appointments](https://github.com/apollo-level2-web-dev/l2b6-backend-ph-healthcare-management-system/blob/development/src/app/module/appointment/appointment.service.ts): `src/app/module/appointment/appointment.service.ts`
- [Administration](https://github.com/apollo-level2-web-dev/l2b6-backend-ph-healthcare-management-system/blob/development/src/app/module/admin/admin.service.ts): `src/app/module/admin/admin.service.ts`

### Payments and platform

- [Payment webhook](https://github.com/apollo-level2-web-dev/l2b6-backend-ph-healthcare-management-system/blob/development/src/app/module/payment/payment.controller.ts): `src/app/module/payment/payment.controller.ts`
- [Payment handling](https://github.com/apollo-level2-web-dev/l2b6-backend-ph-healthcare-management-system/blob/development/src/app/module/payment/payment.service.ts): `src/app/module/payment/payment.service.ts`
- [Stripe client](https://github.com/apollo-level2-web-dev/l2b6-backend-ph-healthcare-management-system/blob/development/src/app/config/stripe.config.ts): `src/app/config/stripe.config.ts`
- [PostgreSQL database](https://github.com/apollo-level2-web-dev/l2b6-backend-ph-healthcare-management-system/blob/development/src/app/lib/prisma.ts): `src/app/lib/prisma.ts`
- [Query builder](https://github.com/apollo-level2-web-dev/l2b6-backend-ph-healthcare-management-system/blob/development/src/app/utils/QueryBuilder.ts): `src/app/utils/QueryBuilder.ts`
- [Query interfaces](https://github.com/apollo-level2-web-dev/l2b6-backend-ph-healthcare-management-system/blob/development/src/app/interfaces/query.interface.ts): `src/app/interfaces/query.interface.ts`
- [Environment config](https://github.com/apollo-level2-web-dev/l2b6-backend-ph-healthcare-management-system/blob/development/src/app/config/env.ts): `src/app/config/env.ts`
- [Scheduled cleanup](https://github.com/apollo-level2-web-dev/l2b6-backend-ph-healthcare-management-system/blob/development/src/app/module/appointment/appointment.service.ts): `src/app/module/appointment/appointment.service.ts`

### Other components

- **API client**

## Connections

- API client → Express application: sends requests (evidence: `src/app.ts`)
- HTTP server → Express application: starts (evidence: `src/server.ts`)
- Express application → API routes: mounts API (evidence: `src/app.ts`)
- Express application → Better Auth: mounts auth (evidence: `src/app.ts`)
- Express application → Payment webhook: registers webhook (evidence: `src/app.ts`)
- Express application → Scheduled cleanup: schedules cleanup (evidence: `src/app.ts`)
- Scheduled cleanup → Appointments: cancels unpaid (evidence: `src/app.ts`)
- Auth endpoints → Auth operations: calls (evidence: `src/app/module/auth/auth.controller.ts`)
- Auth operations → Better Auth: uses (evidence: `src/app/module/auth/auth.service.ts`)
- Better Auth → PostgreSQL database: persists auth (evidence: `src/app/lib/auth.ts`)
- Auth operations → PostgreSQL database: reads and writes (evidence: `src/app/module/auth/auth.service.ts`)
- User management → PostgreSQL database: reads and writes (evidence: `src/app/module/user/user.service.ts`)
- Doctor directory → PostgreSQL database: queries (evidence: `src/app/module/doctor/doctor.service.ts`)
- Specialties → PostgreSQL database: queries (evidence: `src/app/module/specialty/specialty.service.ts`)
- Schedules → PostgreSQL database: queries (evidence: `src/app/module/schedule/schedule.service.ts`)
- Doctor schedules → PostgreSQL database: queries (evidence: `src/app/module/doctorSchedule/doctorSchedule.service.ts`)
- Appointments → PostgreSQL database: reads and writes (evidence: `src/app/module/appointment/appointment.service.ts`)
- Appointments → Stripe client: creates checkout (evidence: `src/app/module/appointment/appointment.service.ts`)
- Payment webhook → Stripe client: verifies event (evidence: `src/app/module/payment/payment.controller.ts`)
- Payment webhook → Payment handling: dispatches event (evidence: `src/app/module/payment/payment.controller.ts`)
- Payment handling → PostgreSQL database: updates payment (evidence: `src/app/module/payment/payment.service.ts`)
- Doctor directory → Query builder: builds queries (evidence: `src/app/module/doctor/doctor.service.ts`)
- Schedules → Query builder: builds queries (evidence: `src/app/module/schedule/schedule.service.ts`)
- Doctor schedules → Query builder: builds queries (evidence: `src/app/module/doctorSchedule/doctorSchedule.service.ts`)
- Query builder → Query interfaces: uses types (evidence: `src/app/utils/QueryBuilder.ts`)
- Better Auth → Environment config: reads settings (evidence: `src/app/lib/auth.ts`)
- PostgreSQL database → Environment config: reads database URL (evidence: `src/app/lib/prisma.ts`)
- Auth operations → Request identity: uses identity (evidence: `src/app/module/auth/auth.service.ts`)
- Auth endpoints → HTTP responses: formats responses (evidence: `src/app/module/auth/auth.controller.ts`)
- Payment webhook → HTTP responses: formats responses (evidence: `src/app/module/payment/payment.controller.ts`)
- Payment webhook → Async error wrapper: wraps handler (evidence: `src/app/module/payment/payment.controller.ts`)
