# samichen99/hps-hospital-management-system architecture

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

- Interactive diagram: https://gitdiagram.com/samichen99/hps-hospital-management-system
- Repository: https://github.com/samichen99/hps-hospital-management-system

## Overview

HAP is a hospital operations portal for staff to manage users, patients, doctors, appointments, medical records, files, invoices, and payments. Users sign in, then work through protected dashboard pages; those pages call the Go API through a shared Axios client. The README describes JWT authentication, role-based access, PostgreSQL, and Kafka. Frontend routing and several page-to-API calls are shown in the excerpts; backend internals were not excerpted, so their links are omitted or marked unverified rather than inferred.

Main entry points: [`frontend/src/services/apiClient.js`](https://github.com/samichen99/hps-hospital-management-system/blob/master/frontend/src/services/apiClient.js) (HTTP API client), [`frontend/src/App.jsx`](https://github.com/samichen99/hps-hospital-management-system/blob/master/frontend/src/App.jsx) (Route application), [`backend/api/router.go`](https://github.com/samichen99/hps-hospital-management-system/blob/master/backend/api/router.go) (Go HTTP API), [`frontend/src/context/AuthContext.jsx`](https://github.com/samichen99/hps-hospital-management-system/blob/master/frontend/src/context/AuthContext.jsx) (Login and session)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Web application"]
  node_app["Route application<br/>[App.jsx]"]
  node_auth["Login and session<br/>[AuthContext.jsx]"]
  node_login["Login page<br/>[Login.jsx]"]
  node_guard["Protected routes<br/>[ProtectedRoute.jsx]"]
  node_layout["Portal layout<br/>[MainLayout.jsx]"]
  node_dashboard["Hospital dashboard<br/>[Dashboard.jsx]"]
  node_users["User administration<br/>[Users.jsx]"]
  node_patients["Patient management<br/>[Patients.jsx]"]
  node_doctors["Doctor management<br/>[Doctors.jsx]"]
  node_appointments["Appointment scheduling<br/>[Appointments.jsx]"]
  node_records["Medical records"]
  node_files["Clinical files<br/>[Files.jsx]"]
  node_invoices["Invoice management<br/>[Invoices.jsx]"]
  node_payments["Payment tracking<br/>[payments.jsx]"]
  node_api_client["HTTP API client<br/>[apiClient.js]"]
end

subgraph group_backend["Go backend"]
  node_api["Go HTTP API<br/>[router.go]"]
  node_server["Server startup<br/>[main.go]"]
  node_auth_handlers["Authentication and access<br/>[auth_handler.go]"]
  node_domain_handlers["Hospital domain handlers"]
  node_repositories["Data repositories"]
  node_models["Domain models"]
end

subgraph group_persistence["Data services"]
  node_database[("PostgreSQL")]
  node_kafka["Kafka"]
end

node_staff(("Hospital user"))

node_staff -->|"opens portal"| node_app
node_app -->|"provides session"| node_auth
node_app -->|"routes to"| node_login
node_app -->|"protects routes"| node_guard
node_guard -->|"checks session"| node_auth
node_app -->|"wraps pages"| node_layout
node_layout -->|"renders route"| node_dashboard
node_login -->|"submits credentials"| node_auth
node_auth -->|"posts login"| node_api_client
node_dashboard -->|"reads session"| node_auth
node_users -->|"requests data"| node_api_client
node_patients -->|"requests data"| node_api_client
node_doctors -->|"requests data"| node_api_client
node_appointments -->|"manages appointments"| node_api_client
node_records -->|"requests data"| node_api_client
node_files -->|"manages files"| node_api_client
node_invoices -->|"manages invoices"| node_api_client
node_invoices -->|"loads patients and appointments"| node_api_client
node_payments -->|"requests data"| node_api_client
node_api_client -.->|"sends HTTP requests"| node_api
node_server -.->|"starts API"| node_api
node_api -.->|"routes authentication"| node_auth_handlers
node_api -.->|"routes domain requests"| node_domain_handlers
node_domain_handlers -.->|"uses data access"| node_repositories
node_repositories -.->|"persists records"| node_database
node_domain_handlers -.->|"handles domain data"| node_models
node_api -.->|"may publish events"| node_kafka

click node_app "https://github.com/samichen99/hps-hospital-management-system/blob/master/frontend/src/App.jsx"
click node_auth "https://github.com/samichen99/hps-hospital-management-system/blob/master/frontend/src/context/AuthContext.jsx"
click node_login "https://github.com/samichen99/hps-hospital-management-system/blob/master/frontend/src/pages/Login.jsx"
click node_guard "https://github.com/samichen99/hps-hospital-management-system/blob/master/frontend/src/components/ProtectedRoute.jsx"
click node_layout "https://github.com/samichen99/hps-hospital-management-system/blob/master/frontend/src/layouts/MainLayout.jsx"
click node_dashboard "https://github.com/samichen99/hps-hospital-management-system/blob/master/frontend/src/pages/Dashboard.jsx"
click node_users "https://github.com/samichen99/hps-hospital-management-system/blob/master/frontend/src/pages/Users.jsx"
click node_patients "https://github.com/samichen99/hps-hospital-management-system/blob/master/frontend/src/pages/Patients.jsx"
click node_doctors "https://github.com/samichen99/hps-hospital-management-system/blob/master/frontend/src/pages/Doctors.jsx"
click node_appointments "https://github.com/samichen99/hps-hospital-management-system/blob/master/frontend/src/pages/Appointments.jsx"
click node_records "https://github.com/samichen99/hps-hospital-management-system/blob/master/frontend/src/pages/Medical_records.jsx"
click node_files "https://github.com/samichen99/hps-hospital-management-system/blob/master/frontend/src/pages/Files.jsx"
click node_invoices "https://github.com/samichen99/hps-hospital-management-system/blob/master/frontend/src/pages/Invoices.jsx"
click node_payments "https://github.com/samichen99/hps-hospital-management-system/blob/master/frontend/src/pages/payments.jsx"
click node_api_client "https://github.com/samichen99/hps-hospital-management-system/blob/master/frontend/src/services/apiClient.js"
click node_api "https://github.com/samichen99/hps-hospital-management-system/blob/master/backend/api/router.go"
click node_server "https://github.com/samichen99/hps-hospital-management-system/blob/master/backend/cmd/server/main.go"
click node_auth_handlers "https://github.com/samichen99/hps-hospital-management-system/blob/master/backend/handlers/auth_handler.go"
click node_domain_handlers "https://github.com/samichen99/hps-hospital-management-system/tree/master/backend/handlers"
click node_repositories "https://github.com/samichen99/hps-hospital-management-system/tree/master/backend/repositories"
click node_models "https://github.com/samichen99/hps-hospital-management-system/tree/master/backend/models"

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_app,node_auth,node_login,node_guard,node_layout,node_dashboard,node_users,node_patients,node_doctors,node_appointments,node_records,node_files,node_invoices,node_payments,node_api_client,node_staff toneBlue
class node_api,node_server,node_auth_handlers,node_domain_handlers,node_repositories,node_models toneAmber
class node_database,node_kafka toneMint
```

## Components

### Web application

- [Route application](https://github.com/samichen99/hps-hospital-management-system/blob/master/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Login and session](https://github.com/samichen99/hps-hospital-management-system/blob/master/frontend/src/context/AuthContext.jsx): `frontend/src/context/AuthContext.jsx`
- [Login page](https://github.com/samichen99/hps-hospital-management-system/blob/master/frontend/src/pages/Login.jsx): `frontend/src/pages/Login.jsx`
- [Protected routes](https://github.com/samichen99/hps-hospital-management-system/blob/master/frontend/src/components/ProtectedRoute.jsx): `frontend/src/components/ProtectedRoute.jsx`
- [Portal layout](https://github.com/samichen99/hps-hospital-management-system/blob/master/frontend/src/layouts/MainLayout.jsx): `frontend/src/layouts/MainLayout.jsx`
- [Hospital dashboard](https://github.com/samichen99/hps-hospital-management-system/blob/master/frontend/src/pages/Dashboard.jsx): `frontend/src/pages/Dashboard.jsx`
- [User administration](https://github.com/samichen99/hps-hospital-management-system/blob/master/frontend/src/pages/Users.jsx): `frontend/src/pages/Users.jsx`
- [Patient management](https://github.com/samichen99/hps-hospital-management-system/blob/master/frontend/src/pages/Patients.jsx): `frontend/src/pages/Patients.jsx`
- [Doctor management](https://github.com/samichen99/hps-hospital-management-system/blob/master/frontend/src/pages/Doctors.jsx): `frontend/src/pages/Doctors.jsx`
- [Appointment scheduling](https://github.com/samichen99/hps-hospital-management-system/blob/master/frontend/src/pages/Appointments.jsx): `frontend/src/pages/Appointments.jsx`
- [Medical records](https://github.com/samichen99/hps-hospital-management-system/blob/master/frontend/src/pages/Medical_records.jsx): `frontend/src/pages/Medical_records.jsx`
- [Clinical files](https://github.com/samichen99/hps-hospital-management-system/blob/master/frontend/src/pages/Files.jsx): `frontend/src/pages/Files.jsx`
- [Invoice management](https://github.com/samichen99/hps-hospital-management-system/blob/master/frontend/src/pages/Invoices.jsx): `frontend/src/pages/Invoices.jsx`
- [Payment tracking](https://github.com/samichen99/hps-hospital-management-system/blob/master/frontend/src/pages/payments.jsx): `frontend/src/pages/payments.jsx`
- [HTTP API client](https://github.com/samichen99/hps-hospital-management-system/blob/master/frontend/src/services/apiClient.js): `frontend/src/services/apiClient.js`

### Go backend

- [Go HTTP API](https://github.com/samichen99/hps-hospital-management-system/blob/master/backend/api/router.go): `backend/api/router.go`
- [Server startup](https://github.com/samichen99/hps-hospital-management-system/blob/master/backend/cmd/server/main.go): `backend/cmd/server/main.go`
- [Authentication and access](https://github.com/samichen99/hps-hospital-management-system/blob/master/backend/handlers/auth_handler.go): `backend/handlers/auth_handler.go`
- [Hospital domain handlers](https://github.com/samichen99/hps-hospital-management-system/tree/master/backend/handlers): `backend/handlers`
- [Data repositories](https://github.com/samichen99/hps-hospital-management-system/tree/master/backend/repositories): `backend/repositories`
- [Domain models](https://github.com/samichen99/hps-hospital-management-system/tree/master/backend/models): `backend/models`

### Data services

- **PostgreSQL**
- **Kafka**

### Other components

- **Hospital user**

## Connections

- Hospital user → Route application: opens portal
- Route application → Login and session: provides session (evidence: `frontend/src/App.jsx`)
- Route application → Login page: routes to (evidence: `frontend/src/App.jsx`)
- Route application → Protected routes: protects routes (evidence: `frontend/src/App.jsx`)
- Protected routes → Login and session: checks session (evidence: `frontend/src/components/ProtectedRoute.jsx`)
- Route application → Portal layout: wraps pages (evidence: `frontend/src/App.jsx`)
- Portal layout → Hospital dashboard: renders route (evidence: `frontend/src/App.jsx`)
- Login page → Login and session: submits credentials (evidence: `frontend/src/pages/Login.jsx`)
- Login and session → HTTP API client: posts login (evidence: `frontend/src/context/AuthContext.jsx`)
- Hospital dashboard → Login and session: reads session (evidence: `frontend/src/pages/Dashboard.jsx`)
- User administration → HTTP API client: requests data (evidence: `frontend/src/pages/Users.jsx`)
- Patient management → HTTP API client: requests data (evidence: `frontend/src/pages/Patients.jsx`)
- Doctor management → HTTP API client: requests data (evidence: `frontend/src/pages/Doctors.jsx`)
- Appointment scheduling → HTTP API client: manages appointments (evidence: `frontend/src/pages/Appointments.jsx`)
- Medical records → HTTP API client: requests data (evidence: `frontend/src/pages/Medical_records.jsx`)
- Clinical files → HTTP API client: manages files (evidence: `frontend/src/pages/Files.jsx`)
- Invoice management → HTTP API client: manages invoices (evidence: `frontend/src/pages/Invoices.jsx`)
- Invoice management → HTTP API client: loads patients and appointments (evidence: `frontend/src/pages/Invoices.jsx`)
- Payment tracking → HTTP API client: requests data (evidence: `frontend/src/pages/payments.jsx`)
- HTTP API client → Go HTTP API: sends HTTP requests
- Server startup → Go HTTP API: starts API
- Go HTTP API → Authentication and access: routes authentication
- Go HTTP API → Hospital domain handlers: routes domain requests
- Hospital domain handlers → Data repositories: uses data access
- Data repositories → PostgreSQL: persists records
- Hospital domain handlers → Domain models: handles domain data
- Go HTTP API → Kafka: may publish events
