# manoj24-mj/caresphere architecture

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

- Interactive diagram: https://gitdiagram.com/manoj24-mj/caresphere
- Repository: https://github.com/manoj24-mj/caresphere

## Overview

CareSphere is a civic healthcare resource and patient-services platform exposed through a local REST API. Citizens discover hospitals, beds, doctors, blood and medicines; patients also book appointments and manage private records, while staff update resources and clinicians use controlled record access. The API routes requests to domain handlers, which use repositories and PostgreSQL; the vault additionally stores encrypted documents locally. README capabilities include ambulance requests and grounded assistant queries. Several domain handlers and integrations were not sampled, so their internal links are omitted or marked unverified.

Main entry points: [`backend/src/routes/index.js`](https://github.com/manoj24-mj/caresphere/blob/main/backend/src/routes/index.js) (API routing), [`backend/src/controllers/medicalRecordController.js`](https://github.com/manoj24-mj/caresphere/blob/main/backend/src/controllers/medicalRecordController.js) (Health Vault), [`backend/src/repositories/userRepository.js`](https://github.com/manoj24-mj/caresphere/blob/main/backend/src/repositories/userRepository.js) (User records), [`backend/src/repositories`](https://github.com/manoj24-mj/caresphere/tree/main/backend/src/repositories) (Resource registries)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and identity"]
  node_api["REST API<br/>[app.js]"]
  node_routing["API routing<br/>[index.js]"]
  node_auth_routes["Authentication routes<br/>[authRoutes.js]"]
  node_auth["JWT and role checks<br/>[auth.js]"]
  node_auth_controller["Registration and login<br/>[authController.js]"]
  node_rate_limiter["Endpoint rate limits<br/>[rateLimiter.js]"]
  node_response["API responses<br/>[response.js]"]
end

subgraph group_discovery["Resource discovery"]
  node_resource_controllers["Resource handlers"]
  node_ambulance_controller["Ambulance requests"]
  node_chat_controller["Care assistant<br/>[chatController.js]"]
end

subgraph group_care["Patient care"]
  node_user_controller["Profile and settings<br/>[userController.js]"]
  node_appointments["Appointment booking"]
  node_vault_routes["Vault access routes"]
  node_vault_controller["Health Vault"]
end

subgraph group_data["Data and privacy"]
  node_audit["Sensitive-action audit<br/>[audit.js]"]
  node_repositories["Domain repositories"]
  node_user_repository["User records<br/>[userRepository.js]"]
  node_medical_repository["Vault records"]
  node_discovery_repositories["Resource registries"]
  node_database[("PostgreSQL via Prisma<br/>[database.js]")]
  node_document_storage["Private document storage<br/>[documentStorage.js]"]
  node_encryption["Document encryption<br/>[encryption.js]"]
  node_jwt["JWT configuration<br/>[jwt.js]"]
end

node_citizens(("Citizens and staff"))

node_citizens -->|"request services"| node_api
node_api -->|"mounts API"| node_routing
node_routing -->|"mounts routes"| node_auth_routes
node_routing -->|"mounts routes"| node_vault_routes
node_auth_routes -->|"dispatches auth"| node_auth_controller
node_auth_routes -->|"guards sessions"| node_auth
node_auth -->|"checks session"| node_user_repository
node_auth -->|"verifies tokens"| node_jwt
node_auth_controller -->|"manages accounts"| node_user_repository
node_routing -.->|"dispatches domains"| node_resource_controllers
node_resource_controllers -.->|"queries registries"| node_discovery_repositories
node_chat_controller -->|"queries summaries"| node_discovery_repositories
node_routing -.->|"dispatches booking"| node_appointments
node_routing -->|"dispatches requests"| node_ambulance_controller
node_ambulance_controller -->|"reads fleet"| node_discovery_repositories
node_vault_routes -->|"dispatches vault"| node_vault_controller
node_vault_controller -->|"manages records"| node_medical_repository
node_vault_controller -->|"stores documents"| node_document_storage
node_document_storage -->|"encrypts files"| node_encryption
node_vault_controller -->|"records access"| node_audit
node_auth_controller -->|"records auth events"| node_audit
node_user_controller -->|"updates profile"| node_user_repository
node_user_repository -->|"reads and writes"| node_database
node_medical_repository -->|"reads and writes"| node_database
node_discovery_repositories -.->|"queries registries"| node_database
node_audit -->|"writes audit logs"| node_database
node_vault_routes -->|"limits sensitive actions"| node_rate_limiter

click node_api "https://github.com/manoj24-mj/caresphere/blob/main/backend/src/app.js"
click node_routing "https://github.com/manoj24-mj/caresphere/blob/main/backend/src/routes/index.js"
click node_auth_routes "https://github.com/manoj24-mj/caresphere/blob/main/backend/src/routes/authRoutes.js"
click node_auth "https://github.com/manoj24-mj/caresphere/blob/main/backend/src/middleware/auth.js"
click node_auth_controller "https://github.com/manoj24-mj/caresphere/blob/main/backend/src/controllers/authController.js"
click node_user_controller "https://github.com/manoj24-mj/caresphere/blob/main/backend/src/controllers/userController.js"
click node_resource_controllers "https://github.com/manoj24-mj/caresphere/tree/main/backend/src/controllers"
click node_ambulance_controller "https://github.com/manoj24-mj/caresphere/blob/main/backend/src/controllers/ambulanceController.js"
click node_chat_controller "https://github.com/manoj24-mj/caresphere/blob/main/backend/src/controllers/chatController.js"
click node_appointments "https://github.com/manoj24-mj/caresphere/blob/main/backend/src/controllers/appointmentController.js"
click node_vault_routes "https://github.com/manoj24-mj/caresphere/blob/main/backend/src/routes/medicalRecordRoutes.js"
click node_vault_controller "https://github.com/manoj24-mj/caresphere/blob/main/backend/src/controllers/medicalRecordController.js"
click node_audit "https://github.com/manoj24-mj/caresphere/blob/main/backend/src/middleware/audit.js"
click node_repositories "https://github.com/manoj24-mj/caresphere/tree/main/backend/src/repositories"
click node_user_repository "https://github.com/manoj24-mj/caresphere/blob/main/backend/src/repositories/userRepository.js"
click node_medical_repository "https://github.com/manoj24-mj/caresphere/blob/main/backend/src/repositories/medicalRecordRepository.js"
click node_discovery_repositories "https://github.com/manoj24-mj/caresphere/tree/main/backend/src/repositories"
click node_database "https://github.com/manoj24-mj/caresphere/blob/main/backend/src/config/database.js"
click node_document_storage "https://github.com/manoj24-mj/caresphere/blob/main/backend/src/services/documentStorage.js"
click node_encryption "https://github.com/manoj24-mj/caresphere/blob/main/backend/src/config/encryption.js"
click node_jwt "https://github.com/manoj24-mj/caresphere/blob/main/backend/src/config/jwt.js"
click node_rate_limiter "https://github.com/manoj24-mj/caresphere/blob/main/backend/src/middleware/rateLimiter.js"
click node_response "https://github.com/manoj24-mj/caresphere/blob/main/backend/src/utils/response.js"

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_api,node_routing,node_auth_routes,node_auth,node_auth_controller,node_rate_limiter,node_response toneBlue
class node_resource_controllers,node_ambulance_controller,node_chat_controller toneAmber
class node_user_controller,node_appointments,node_vault_routes,node_vault_controller toneMint
class node_audit,node_repositories,node_user_repository,node_medical_repository,node_discovery_repositories,node_database,node_document_storage,node_encryption,node_jwt toneRose
class node_citizens toneIndigo
```

## Components

### API and identity

- [REST API](https://github.com/manoj24-mj/caresphere/blob/main/backend/src/app.js): `backend/src/app.js`
- [API routing](https://github.com/manoj24-mj/caresphere/blob/main/backend/src/routes/index.js): `backend/src/routes/index.js`
- [Authentication routes](https://github.com/manoj24-mj/caresphere/blob/main/backend/src/routes/authRoutes.js): `backend/src/routes/authRoutes.js`
- [JWT and role checks](https://github.com/manoj24-mj/caresphere/blob/main/backend/src/middleware/auth.js): `backend/src/middleware/auth.js`
- [Registration and login](https://github.com/manoj24-mj/caresphere/blob/main/backend/src/controllers/authController.js): `backend/src/controllers/authController.js`
- [Endpoint rate limits](https://github.com/manoj24-mj/caresphere/blob/main/backend/src/middleware/rateLimiter.js): `backend/src/middleware/rateLimiter.js`
- [API responses](https://github.com/manoj24-mj/caresphere/blob/main/backend/src/utils/response.js): `backend/src/utils/response.js`

### Resource discovery

- [Resource handlers](https://github.com/manoj24-mj/caresphere/tree/main/backend/src/controllers): `backend/src/controllers`
- [Ambulance requests](https://github.com/manoj24-mj/caresphere/blob/main/backend/src/controllers/ambulanceController.js): `backend/src/controllers/ambulanceController.js`
- [Care assistant](https://github.com/manoj24-mj/caresphere/blob/main/backend/src/controllers/chatController.js): `backend/src/controllers/chatController.js`

### Patient care

- [Profile and settings](https://github.com/manoj24-mj/caresphere/blob/main/backend/src/controllers/userController.js): `backend/src/controllers/userController.js`
- [Appointment booking](https://github.com/manoj24-mj/caresphere/blob/main/backend/src/controllers/appointmentController.js): `backend/src/controllers/appointmentController.js`
- [Vault access routes](https://github.com/manoj24-mj/caresphere/blob/main/backend/src/routes/medicalRecordRoutes.js): `backend/src/routes/medicalRecordRoutes.js`
- [Health Vault](https://github.com/manoj24-mj/caresphere/blob/main/backend/src/controllers/medicalRecordController.js): `backend/src/controllers/medicalRecordController.js`

### Data and privacy

- [Sensitive-action audit](https://github.com/manoj24-mj/caresphere/blob/main/backend/src/middleware/audit.js): `backend/src/middleware/audit.js`
- [Domain repositories](https://github.com/manoj24-mj/caresphere/tree/main/backend/src/repositories): `backend/src/repositories`
- [User records](https://github.com/manoj24-mj/caresphere/blob/main/backend/src/repositories/userRepository.js): `backend/src/repositories/userRepository.js`
- [Vault records](https://github.com/manoj24-mj/caresphere/blob/main/backend/src/repositories/medicalRecordRepository.js): `backend/src/repositories/medicalRecordRepository.js`
- [Resource registries](https://github.com/manoj24-mj/caresphere/tree/main/backend/src/repositories): `backend/src/repositories`
- [PostgreSQL via Prisma](https://github.com/manoj24-mj/caresphere/blob/main/backend/src/config/database.js): `backend/src/config/database.js`
- [Private document storage](https://github.com/manoj24-mj/caresphere/blob/main/backend/src/services/documentStorage.js): `backend/src/services/documentStorage.js`
- [Document encryption](https://github.com/manoj24-mj/caresphere/blob/main/backend/src/config/encryption.js): `backend/src/config/encryption.js`
- [JWT configuration](https://github.com/manoj24-mj/caresphere/blob/main/backend/src/config/jwt.js): `backend/src/config/jwt.js`

### Other components

- **Citizens and staff**

## Connections

- Citizens and staff → REST API: request services
- REST API → API routing: mounts API (evidence: `backend/src/app.js`)
- API routing → Authentication routes: mounts routes (evidence: `backend/src/routes/index.js`)
- API routing → Vault access routes: mounts routes (evidence: `backend/src/routes/index.js`)
- Authentication routes → Registration and login: dispatches auth (evidence: `backend/src/routes/authRoutes.js`)
- Authentication routes → JWT and role checks: guards sessions (evidence: `backend/src/routes/authRoutes.js`)
- JWT and role checks → User records: checks session (evidence: `backend/src/middleware/auth.js`)
- JWT and role checks → JWT configuration: verifies tokens (evidence: `backend/src/middleware/auth.js`)
- Registration and login → User records: manages accounts (evidence: `backend/src/controllers/authController.js`)
- API routing → Resource handlers: dispatches domains
- Resource handlers → Resource registries: queries registries (evidence: `backend/src/controllers/medicalRecordController.js`)
- Care assistant → Resource registries: queries summaries (evidence: `backend/src/controllers/chatController.js`)
- API routing → Appointment booking: dispatches booking
- API routing → Ambulance requests: dispatches requests (evidence: `backend/src/routes/index.js`)
- Ambulance requests → Resource registries: reads fleet (evidence: `backend/src/controllers/ambulanceController.js`)
- Vault access routes → Health Vault: dispatches vault (evidence: `backend/src/routes/medicalRecordRoutes.js`)
- Health Vault → Vault records: manages records (evidence: `backend/src/controllers/medicalRecordController.js`)
- Health Vault → Private document storage: stores documents (evidence: `backend/src/controllers/medicalRecordController.js`)
- Private document storage → Document encryption: encrypts files (evidence: `backend/src/services/documentStorage.js`)
- Health Vault → Sensitive-action audit: records access (evidence: `backend/src/controllers/medicalRecordController.js`)
- Registration and login → Sensitive-action audit: records auth events (evidence: `backend/src/controllers/authController.js`)
- Profile and settings → User records: updates profile (evidence: `backend/src/controllers/userController.js`)
- User records → PostgreSQL via Prisma: reads and writes (evidence: `backend/src/repositories/userRepository.js`)
- Vault records → PostgreSQL via Prisma: reads and writes (evidence: `backend/src/repositories/medicalRecordRepository.js`)
- Resource registries → PostgreSQL via Prisma: queries registries (evidence: `backend/src/repositories/medicalRecordRepository.js`)
- Sensitive-action audit → PostgreSQL via Prisma: writes audit logs (evidence: `backend/src/middleware/audit.js`)
- Vault access routes → Endpoint rate limits: limits sensitive actions (evidence: `backend/src/routes/medicalRecordRoutes.js`)
