# nuby911/inventory-klinik architecture

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

- Interactive diagram: https://gitdiagram.com/nuby911/inventory-klinik
- Repository: https://github.com/nuby911/inventory-klinik

## Overview

Klinik El Medika is an integrated clinic and pharmacy back-office: staff sign in, then administrators manage medicines and batches, doctors register patients and write e-prescriptions, and pharmacists prepare and dispense them. The client uses a shared API service; the server routes requests to domain controllers backed by SQLite. FEFO allocation supports dispensing, while Socket.io carries prescription and stock updates. The README documents these capabilities; unsampled route wiring and some client-to-server details are shown only where the indexed references or excerpts support them.

Main entry points: [`server/src/routes/api.js`](https://github.com/nuby911/inventory-klinik/blob/main/server/src/routes/api.js) (API routes), [`server/src/config/database.js`](https://github.com/nuby911/inventory-klinik/blob/main/server/src/config/database.js) (Clinic database), [`client/src/App.jsx`](https://github.com/nuby911/inventory-klinik/blob/main/client/src/App.jsx) (Role-based app), [`server/src/controllers/prescriptionController.js`](https://github.com/nuby911/inventory-klinik/blob/main/server/src/controllers/prescriptionController.js) (E-prescriptions)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Staff application"]
  node_app["Role-based app<br/>[App.jsx]"]
  node_login["Staff sign-in<br/>[LoginPage.jsx]"]
  node_doctor["Doctor portal<br/>[DoctorPortal.jsx]"]
  node_pharmacy["Pharmacy portal<br/>[PharmacyPortal.jsx]"]
  node_admin["Admin portal<br/>[AdminPortal.jsx]"]
  node_api_client["API client<br/>[api.js]"]
  node_socket_client["Socket context<br/>[SocketContext.jsx]"]
end

subgraph group_server["API and access"]
  node_server["Express and sockets<br/>[server.js]"]
  node_api_routes["API routes<br/>[api.js]"]
  node_auth["Authentication<br/>[authController.js]"]
  node_auth_mw["Session and role checks<br/>[authMiddleware.js]"]
  node_users["User management<br/>[userController.js]"]
end

subgraph group_domain["Clinical and inventory"]
  node_medicine["Medicine catalog"]
  node_batch["Batch inventory<br/>[batchController.js]"]
  node_patient["Patient records"]
  node_prescription["E-prescriptions"]
  node_fefo["Unit conversion and FEFO<br/>[fefoService.js]"]
  node_database[("Clinic database<br/>[database.js]")]
  node_clinic_helpers["Clinic rules and dates<br/>[clinicHelpers.js]"]
end

subgraph group_insights["Reports and operations"]
  node_reports_ui["Reports and logistics"]
  node_reports["Reports"]
end

node_staff(("Clinic staff"))
node_http(("HTTP clients"))
node_socket(("Live event clients"))

node_staff -->|"uses"| node_app
node_app -->|"shows when signed out"| node_login
node_app -->|"routes by role"| node_doctor
node_app -->|"routes by role"| node_pharmacy
node_app -->|"routes by role"| node_admin
node_doctor -->|"requests data"| node_api_client
node_pharmacy -->|"requests data"| node_api_client
node_admin -->|"requests data"| node_api_client
node_reports_ui -->|"requests reports"| node_api_client
node_api_client -->|"sends requests"| node_http
node_http -.->|"reaches API"| node_server
node_server -->|"mounts routes"| node_api_routes
node_api_routes -.->|"dispatches"| node_auth
node_api_routes -.->|"dispatches"| node_medicine
node_api_routes -.->|"dispatches"| node_batch
node_api_routes -.->|"dispatches"| node_patient
node_api_routes -.->|"dispatches"| node_prescription
node_api_routes -.->|"dispatches"| node_users
node_api_routes -.->|"dispatches"| node_reports
node_medicine -->|"reads and writes"| node_database
node_batch -->|"reads and writes"| node_database
node_patient -->|"reads and writes"| node_database
node_prescription -->|"reads and writes"| node_database
node_users -->|"reads and writes"| node_database
node_reports -->|"reads"| node_database
node_auth_mw -->|"checks session"| node_database
node_prescription -->|"allocates stock"| node_fefo
node_batch -->|"uses allocation rules"| node_fefo
node_medicine -->|"uses unit rules"| node_fefo
node_fefo -->|"updates batches"| node_database
node_fefo -->|"uses clinic dates"| node_clinic_helpers
node_prescription -->|"uses clinic rules"| node_clinic_helpers
node_reports -->|"uses date ranges"| node_clinic_helpers
node_prescription -->|"emits prescription events"| node_socket
node_socket -->|"delivers live updates"| node_socket_client
node_socket_client -.->|"provides socket state"| node_app

click node_app "https://github.com/nuby911/inventory-klinik/blob/main/client/src/App.jsx"
click node_login "https://github.com/nuby911/inventory-klinik/blob/main/client/src/pages/auth/LoginPage.jsx"
click node_doctor "https://github.com/nuby911/inventory-klinik/blob/main/client/src/pages/doctor/DoctorPortal.jsx"
click node_pharmacy "https://github.com/nuby911/inventory-klinik/blob/main/client/src/pages/pharmacy/PharmacyPortal.jsx"
click node_admin "https://github.com/nuby911/inventory-klinik/blob/main/client/src/pages/admin/AdminPortal.jsx"
click node_api_client "https://github.com/nuby911/inventory-klinik/blob/main/client/src/services/api.js"
click node_socket_client "https://github.com/nuby911/inventory-klinik/blob/main/client/src/context/SocketContext.jsx"
click node_reports_ui "https://github.com/nuby911/inventory-klinik/blob/main/client/src/components/common/LogisticsReportView.jsx"
click node_server "https://github.com/nuby911/inventory-klinik/blob/main/server/src/server.js"
click node_api_routes "https://github.com/nuby911/inventory-klinik/blob/main/server/src/routes/api.js"
click node_auth "https://github.com/nuby911/inventory-klinik/blob/main/server/src/controllers/authController.js"
click node_auth_mw "https://github.com/nuby911/inventory-klinik/blob/main/server/src/middlewares/authMiddleware.js"
click node_medicine "https://github.com/nuby911/inventory-klinik/blob/main/server/src/controllers/medicineController.js"
click node_batch "https://github.com/nuby911/inventory-klinik/blob/main/server/src/controllers/batchController.js"
click node_patient "https://github.com/nuby911/inventory-klinik/blob/main/server/src/controllers/patientController.js"
click node_prescription "https://github.com/nuby911/inventory-klinik/blob/main/server/src/controllers/prescriptionController.js"
click node_fefo "https://github.com/nuby911/inventory-klinik/blob/main/server/src/services/fefoService.js"
click node_users "https://github.com/nuby911/inventory-klinik/blob/main/server/src/controllers/userController.js"
click node_reports "https://github.com/nuby911/inventory-klinik/blob/main/server/src/controllers/reportController.js"
click node_database "https://github.com/nuby911/inventory-klinik/blob/main/server/src/config/database.js"
click node_clinic_helpers "https://github.com/nuby911/inventory-klinik/blob/main/server/src/utils/clinicHelpers.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_app,node_login,node_doctor,node_pharmacy,node_admin,node_api_client,node_socket_client,node_http,node_socket toneBlue
class node_server,node_api_routes,node_auth,node_auth_mw,node_users toneAmber
class node_medicine,node_batch,node_patient,node_prescription,node_fefo,node_database,node_clinic_helpers toneMint
class node_reports_ui,node_reports toneRose
class node_staff toneIndigo
```

## Components

### Staff application

- [Role-based app](https://github.com/nuby911/inventory-klinik/blob/main/client/src/App.jsx): `client/src/App.jsx`
- [Staff sign-in](https://github.com/nuby911/inventory-klinik/blob/main/client/src/pages/auth/LoginPage.jsx): `client/src/pages/auth/LoginPage.jsx`
- [Doctor portal](https://github.com/nuby911/inventory-klinik/blob/main/client/src/pages/doctor/DoctorPortal.jsx): `client/src/pages/doctor/DoctorPortal.jsx`
- [Pharmacy portal](https://github.com/nuby911/inventory-klinik/blob/main/client/src/pages/pharmacy/PharmacyPortal.jsx): `client/src/pages/pharmacy/PharmacyPortal.jsx`
- [Admin portal](https://github.com/nuby911/inventory-klinik/blob/main/client/src/pages/admin/AdminPortal.jsx): `client/src/pages/admin/AdminPortal.jsx`
- [API client](https://github.com/nuby911/inventory-klinik/blob/main/client/src/services/api.js): `client/src/services/api.js`
- [Socket context](https://github.com/nuby911/inventory-klinik/blob/main/client/src/context/SocketContext.jsx): `client/src/context/SocketContext.jsx`

### API and access

- [Express and sockets](https://github.com/nuby911/inventory-klinik/blob/main/server/src/server.js): `server/src/server.js`
- [API routes](https://github.com/nuby911/inventory-klinik/blob/main/server/src/routes/api.js): `server/src/routes/api.js`
- [Authentication](https://github.com/nuby911/inventory-klinik/blob/main/server/src/controllers/authController.js): `server/src/controllers/authController.js`
- [Session and role checks](https://github.com/nuby911/inventory-klinik/blob/main/server/src/middlewares/authMiddleware.js): `server/src/middlewares/authMiddleware.js`
- [User management](https://github.com/nuby911/inventory-klinik/blob/main/server/src/controllers/userController.js): `server/src/controllers/userController.js`

### Clinical and inventory

- [Medicine catalog](https://github.com/nuby911/inventory-klinik/blob/main/server/src/controllers/medicineController.js): `server/src/controllers/medicineController.js`
- [Batch inventory](https://github.com/nuby911/inventory-klinik/blob/main/server/src/controllers/batchController.js): `server/src/controllers/batchController.js`
- [Patient records](https://github.com/nuby911/inventory-klinik/blob/main/server/src/controllers/patientController.js): `server/src/controllers/patientController.js`
- [E-prescriptions](https://github.com/nuby911/inventory-klinik/blob/main/server/src/controllers/prescriptionController.js): `server/src/controllers/prescriptionController.js`
- [Unit conversion and FEFO](https://github.com/nuby911/inventory-klinik/blob/main/server/src/services/fefoService.js): `server/src/services/fefoService.js`
- [Clinic database](https://github.com/nuby911/inventory-klinik/blob/main/server/src/config/database.js): `server/src/config/database.js`
- [Clinic rules and dates](https://github.com/nuby911/inventory-klinik/blob/main/server/src/utils/clinicHelpers.js): `server/src/utils/clinicHelpers.js`

### Reports and operations

- [Reports and logistics](https://github.com/nuby911/inventory-klinik/blob/main/client/src/components/common/LogisticsReportView.jsx): `client/src/components/common/LogisticsReportView.jsx`
- [Reports](https://github.com/nuby911/inventory-klinik/blob/main/server/src/controllers/reportController.js): `server/src/controllers/reportController.js`

### Other components

- **Clinic staff**
- **HTTP clients**
- **Live event clients**

## Connections

- Clinic staff → Role-based app: uses
- Role-based app → Staff sign-in: shows when signed out (evidence: `client/src/App.jsx`)
- Role-based app → Doctor portal: routes by role (evidence: `client/src/App.jsx`)
- Role-based app → Pharmacy portal: routes by role (evidence: `client/src/App.jsx`)
- Role-based app → Admin portal: routes by role (evidence: `client/src/App.jsx`)
- Doctor portal → API client: requests data (evidence: `client/src/pages/doctor/DoctorPortal.jsx`)
- Pharmacy portal → API client: requests data (evidence: `client/src/pages/pharmacy/PharmacyPortal.jsx`)
- Admin portal → API client: requests data (evidence: `client/src/pages/admin/AdminPortal.jsx`)
- Reports and logistics → API client: requests reports (evidence: `client/src/components/common/LogisticsReportView.jsx`)
- API client → HTTP clients: sends requests (evidence: `client/src/services/api.js`)
- HTTP clients → Express and sockets: reaches API
- Express and sockets → API routes: mounts routes (evidence: `server/src/server.js`)
- API routes → Authentication: dispatches
- API routes → Medicine catalog: dispatches
- API routes → Batch inventory: dispatches
- API routes → Patient records: dispatches
- API routes → E-prescriptions: dispatches
- API routes → User management: dispatches
- API routes → Reports: dispatches
- Medicine catalog → Clinic database: reads and writes (evidence: `server/src/controllers/medicineController.js`)
- Batch inventory → Clinic database: reads and writes (evidence: `server/src/controllers/batchController.js`)
- Patient records → Clinic database: reads and writes (evidence: `server/src/controllers/patientController.js`)
- E-prescriptions → Clinic database: reads and writes (evidence: `server/src/controllers/prescriptionController.js`)
- User management → Clinic database: reads and writes (evidence: `server/src/controllers/userController.js`)
- Reports → Clinic database: reads (evidence: `server/src/controllers/reportController.js`)
- Session and role checks → Clinic database: checks session (evidence: `server/src/middlewares/authMiddleware.js`)
- E-prescriptions → Unit conversion and FEFO: allocates stock (evidence: `server/src/controllers/prescriptionController.js`)
- Batch inventory → Unit conversion and FEFO: uses allocation rules (evidence: `server/src/controllers/batchController.js`)
- Medicine catalog → Unit conversion and FEFO: uses unit rules (evidence: `server/src/controllers/medicineController.js`)
- Unit conversion and FEFO → Clinic database: updates batches (evidence: `server/src/services/fefoService.js`)
- Unit conversion and FEFO → Clinic rules and dates: uses clinic dates (evidence: `server/src/services/fefoService.js`)
- E-prescriptions → Clinic rules and dates: uses clinic rules (evidence: `server/src/controllers/prescriptionController.js`)
- Reports → Clinic rules and dates: uses date ranges (evidence: `server/src/controllers/reportController.js`)
- E-prescriptions → Live event clients: emits prescription events (evidence: `server/src/controllers/prescriptionController.js`)
- Live event clients → Socket context: delivers live updates
- Socket context → Role-based app: provides socket state (evidence: `client/src/App.jsx`)
