# imdurgeshhh/pharmacy-management-system architecture

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

- Interactive diagram: https://gitdiagram.com/imdurgeshhh/pharmacy-management-system
- Repository: https://github.com/imdurgeshhh/pharmacy-management-system

## Overview

This is a multi-tenant pharmacy management system. Staff sign in, enter the workspace, manage medicines and purchasing, and use point of sale to bill customers; the backend applies authentication and tenant/role checks, handles domain operations, and persists data in PostgreSQL. The README also describes supplier and wholesale operations, prescription/invoice OCR, and report/export capabilities. Some backend route-to-controller links are supported by the source index rather than excerpts; OCR and reporting internals were not sampled, so their deeper connections are omitted.

Main entry points: [`backend/server.js`](https://github.com/imdurgeshhh/pharmacy-management-system/blob/main/backend/server.js) (REST API), [`frontend/src/App.jsx`](https://github.com/imdurgeshhh/pharmacy-management-system/blob/main/frontend/src/App.jsx) (Workspace shell), [`backend/config/db.js`](https://github.com/imdurgeshhh/pharmacy-management-system/blob/main/backend/config/db.js) (Database connection), [`backend/controllers/saleController.js`](https://github.com/imdurgeshhh/pharmacy-management-system/blob/main/backend/controllers/saleController.js) (Sales and billing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web workspace"]
  node_app["Workspace shell<br/>[App.jsx]"]
  node_state["Client state<br/>[useStore.js]"]
  node_posui["Retail POS<br/>[POS.jsx]"]
  node_inventoryui["Inventory workspace<br/>[Inventory.jsx]"]
  node_purchaseui["Purchase workspace<br/>[Purchases.jsx]"]
  node_employeeui["Employee workspace<br/>[Employees.jsx]"]
  node_reportsui["Reports workspace<br/>[Reports.jsx]"]
  node_suppliersui["Supplier workspace<br/>[Suppliers.jsx]"]
end

subgraph group_security["Identity and access"]
  node_auth["Identity loading<br/>[auth.js]"]
  node_roles["Tenant and role checks<br/>[roleCheck.js]"]
  node_validation["Request validation<br/>[validate.js]"]
end

subgraph group_operations["Pharmacy operations"]
  node_api["REST API<br/>[server.js]"]
  node_sales["Sales and billing<br/>[saleController.js]"]
  node_inventory["Inventory domain"]
  node_purchases["Purchase domain"]
  node_employees["Employee management"]
  node_suppliers["Supplier and wholesale"]
  node_customers["Customer records"]
end

subgraph group_data["Persistence and billing"]
  node_quantity["Quantity calculations<br/>[quantity.js]"]
  node_invoice["Invoice generation"]
  node_dbconfig["Database connection<br/>[db.js]"]
  node_postgres[("PostgreSQL")]
end

subgraph group_insights["Scanning and reporting"]
  node_ocr["Prescription and invoice OCR<br/>[ocrController.js]"]
  node_reporting["Reports and analytics"]
end

node_staff(("Pharmacy staff"))

node_staff -->|"uses"| node_app
node_app -->|"reads state"| node_state
node_app -->|"routes to"| node_posui
node_posui -->|"reads state"| node_state
node_app -->|"routes to"| node_inventoryui
node_app -->|"routes to"| node_purchaseui
node_app -->|"routes to"| node_employeeui
node_app -->|"routes to"| node_reportsui
node_app -->|"routes to"| node_suppliersui
node_posui -.->|"requests"| node_api
node_inventoryui -.->|"requests"| node_api
node_purchaseui -.->|"requests"| node_api
node_employeeui -.->|"requests"| node_api
node_reportsui -.->|"requests"| node_api
node_suppliersui -.->|"requests"| node_api
node_api -->|"mounts routes"| node_auth
node_api -->|"routes inventory"| node_inventory
node_api -->|"routes sales"| node_sales
node_api -->|"routes purchases"| node_purchases
node_api -->|"routes employees"| node_employees
node_api -->|"routes OCR"| node_ocr
node_api -->|"routes reports"| node_reporting
node_api -->|"routes wholesale"| node_suppliers
node_auth -->|"loads profile"| node_dbconfig
node_auth -->|"supplies identity"| node_roles
node_inventory -->|"queries"| node_dbconfig
node_purchases -->|"queries"| node_dbconfig
node_sales -->|"queries"| node_dbconfig
node_sales -->|"calculates quantities"| node_quantity
node_purchases -->|"normalizes quantities"| node_quantity
node_sales -->|"generates invoices"| node_invoice
node_dbconfig -->|"connects"| node_postgres
node_inventory -->|"validates input"| node_validation
node_employees -->|"validates input"| node_validation

click node_app "https://github.com/imdurgeshhh/pharmacy-management-system/blob/main/frontend/src/App.jsx"
click node_state "https://github.com/imdurgeshhh/pharmacy-management-system/blob/main/frontend/src/store/useStore.js"
click node_posui "https://github.com/imdurgeshhh/pharmacy-management-system/blob/main/frontend/src/pages/POS.jsx"
click node_inventoryui "https://github.com/imdurgeshhh/pharmacy-management-system/blob/main/frontend/src/pages/Inventory.jsx"
click node_purchaseui "https://github.com/imdurgeshhh/pharmacy-management-system/blob/main/frontend/src/pages/Purchases.jsx"
click node_employeeui "https://github.com/imdurgeshhh/pharmacy-management-system/blob/main/frontend/src/pages/Employees.jsx"
click node_reportsui "https://github.com/imdurgeshhh/pharmacy-management-system/blob/main/frontend/src/pages/Reports.jsx"
click node_suppliersui "https://github.com/imdurgeshhh/pharmacy-management-system/blob/main/frontend/src/pages/Suppliers.jsx"
click node_api "https://github.com/imdurgeshhh/pharmacy-management-system/blob/main/backend/server.js"
click node_auth "https://github.com/imdurgeshhh/pharmacy-management-system/blob/main/backend/middleware/auth.js"
click node_roles "https://github.com/imdurgeshhh/pharmacy-management-system/blob/main/backend/middleware/roleCheck.js"
click node_validation "https://github.com/imdurgeshhh/pharmacy-management-system/blob/main/backend/middleware/validate.js"
click node_sales "https://github.com/imdurgeshhh/pharmacy-management-system/blob/main/backend/controllers/saleController.js"
click node_inventory "https://github.com/imdurgeshhh/pharmacy-management-system/blob/main/backend/controllers/inventoryController.js"
click node_purchases "https://github.com/imdurgeshhh/pharmacy-management-system/blob/main/backend/controllers/purchaseController.js"
click node_employees "https://github.com/imdurgeshhh/pharmacy-management-system/blob/main/backend/controllers/employeeController.js"
click node_suppliers "https://github.com/imdurgeshhh/pharmacy-management-system/blob/main/backend/controllers/wholesaleController.js"
click node_customers "https://github.com/imdurgeshhh/pharmacy-management-system/blob/main/backend/controllers/customerController.js"
click node_ocr "https://github.com/imdurgeshhh/pharmacy-management-system/blob/main/backend/controllers/ocrController.js"
click node_reporting "https://github.com/imdurgeshhh/pharmacy-management-system/blob/main/backend/controllers/reportController.js"
click node_quantity "https://github.com/imdurgeshhh/pharmacy-management-system/blob/main/backend/utils/quantity.js"
click node_invoice "https://github.com/imdurgeshhh/pharmacy-management-system/blob/main/backend/utils/invoiceGenerator.js"
click node_dbconfig "https://github.com/imdurgeshhh/pharmacy-management-system/blob/main/backend/config/db.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_state,node_posui,node_inventoryui,node_purchaseui,node_employeeui,node_reportsui,node_suppliersui toneBlue
class node_auth,node_roles,node_validation toneAmber
class node_api,node_sales,node_inventory,node_purchases,node_employees,node_suppliers,node_customers toneMint
class node_quantity,node_invoice,node_dbconfig,node_postgres toneRose
class node_ocr,node_reporting,node_staff toneIndigo
```

## Components

### Web workspace

- [Workspace shell](https://github.com/imdurgeshhh/pharmacy-management-system/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Client state](https://github.com/imdurgeshhh/pharmacy-management-system/blob/main/frontend/src/store/useStore.js): `frontend/src/store/useStore.js`
- [Retail POS](https://github.com/imdurgeshhh/pharmacy-management-system/blob/main/frontend/src/pages/POS.jsx): `frontend/src/pages/POS.jsx`
- [Inventory workspace](https://github.com/imdurgeshhh/pharmacy-management-system/blob/main/frontend/src/pages/Inventory.jsx): `frontend/src/pages/Inventory.jsx`
- [Purchase workspace](https://github.com/imdurgeshhh/pharmacy-management-system/blob/main/frontend/src/pages/Purchases.jsx): `frontend/src/pages/Purchases.jsx`
- [Employee workspace](https://github.com/imdurgeshhh/pharmacy-management-system/blob/main/frontend/src/pages/Employees.jsx): `frontend/src/pages/Employees.jsx`
- [Reports workspace](https://github.com/imdurgeshhh/pharmacy-management-system/blob/main/frontend/src/pages/Reports.jsx): `frontend/src/pages/Reports.jsx`
- [Supplier workspace](https://github.com/imdurgeshhh/pharmacy-management-system/blob/main/frontend/src/pages/Suppliers.jsx): `frontend/src/pages/Suppliers.jsx`

### Identity and access

- [Identity loading](https://github.com/imdurgeshhh/pharmacy-management-system/blob/main/backend/middleware/auth.js): `backend/middleware/auth.js`
- [Tenant and role checks](https://github.com/imdurgeshhh/pharmacy-management-system/blob/main/backend/middleware/roleCheck.js): `backend/middleware/roleCheck.js`
- [Request validation](https://github.com/imdurgeshhh/pharmacy-management-system/blob/main/backend/middleware/validate.js): `backend/middleware/validate.js`

### Pharmacy operations

- [REST API](https://github.com/imdurgeshhh/pharmacy-management-system/blob/main/backend/server.js): `backend/server.js`
- [Sales and billing](https://github.com/imdurgeshhh/pharmacy-management-system/blob/main/backend/controllers/saleController.js): `backend/controllers/saleController.js`
- [Inventory domain](https://github.com/imdurgeshhh/pharmacy-management-system/blob/main/backend/controllers/inventoryController.js): `backend/controllers/inventoryController.js`
- [Purchase domain](https://github.com/imdurgeshhh/pharmacy-management-system/blob/main/backend/controllers/purchaseController.js): `backend/controllers/purchaseController.js`
- [Employee management](https://github.com/imdurgeshhh/pharmacy-management-system/blob/main/backend/controllers/employeeController.js): `backend/controllers/employeeController.js`
- [Supplier and wholesale](https://github.com/imdurgeshhh/pharmacy-management-system/blob/main/backend/controllers/wholesaleController.js): `backend/controllers/wholesaleController.js`
- [Customer records](https://github.com/imdurgeshhh/pharmacy-management-system/blob/main/backend/controllers/customerController.js): `backend/controllers/customerController.js`

### Persistence and billing

- [Quantity calculations](https://github.com/imdurgeshhh/pharmacy-management-system/blob/main/backend/utils/quantity.js): `backend/utils/quantity.js`
- [Invoice generation](https://github.com/imdurgeshhh/pharmacy-management-system/blob/main/backend/utils/invoiceGenerator.js): `backend/utils/invoiceGenerator.js`
- [Database connection](https://github.com/imdurgeshhh/pharmacy-management-system/blob/main/backend/config/db.js): `backend/config/db.js`
- **PostgreSQL**

### Scanning and reporting

- [Prescription and invoice OCR](https://github.com/imdurgeshhh/pharmacy-management-system/blob/main/backend/controllers/ocrController.js): `backend/controllers/ocrController.js`
- [Reports and analytics](https://github.com/imdurgeshhh/pharmacy-management-system/blob/main/backend/controllers/reportController.js): `backend/controllers/reportController.js`

### Other components

- **Pharmacy staff**

## Connections

- Pharmacy staff → Workspace shell: uses
- Workspace shell → Client state: reads state (evidence: `frontend/src/App.jsx`)
- Workspace shell → Retail POS: routes to (evidence: `frontend/src/App.jsx`)
- Retail POS → Client state: reads state (evidence: `frontend/src/pages/POS.jsx`)
- Workspace shell → Inventory workspace: routes to (evidence: `frontend/src/App.jsx`)
- Workspace shell → Purchase workspace: routes to (evidence: `frontend/src/App.jsx`)
- Workspace shell → Employee workspace: routes to (evidence: `frontend/src/App.jsx`)
- Workspace shell → Reports workspace: routes to (evidence: `frontend/src/App.jsx`)
- Workspace shell → Supplier workspace: routes to (evidence: `frontend/src/App.jsx`)
- Retail POS → REST API: requests
- Inventory workspace → REST API: requests
- Purchase workspace → REST API: requests
- Employee workspace → REST API: requests
- Reports workspace → REST API: requests
- Supplier workspace → REST API: requests
- REST API → Identity loading: mounts routes (evidence: `backend/server.js`)
- REST API → Inventory domain: routes inventory
- REST API → Sales and billing: routes sales (evidence: `backend/server.js`)
- REST API → Purchase domain: routes purchases (evidence: `backend/server.js`)
- REST API → Employee management: routes employees
- REST API → Prescription and invoice OCR: routes OCR (evidence: `backend/server.js`)
- REST API → Reports and analytics: routes reports (evidence: `backend/server.js`)
- REST API → Supplier and wholesale: routes wholesale (evidence: `backend/server.js`)
- Identity loading → Database connection: loads profile (evidence: `backend/middleware/auth.js`)
- Identity loading → Tenant and role checks: supplies identity (evidence: `backend/middleware/roleCheck.js`)
- Inventory domain → Database connection: queries (evidence: `backend/controllers/inventoryController.js`)
- Purchase domain → Database connection: queries (evidence: `backend/controllers/purchaseController.js`)
- Sales and billing → Database connection: queries (evidence: `backend/controllers/saleController.js`)
- Sales and billing → Quantity calculations: calculates quantities (evidence: `backend/controllers/saleController.js`)
- Purchase domain → Quantity calculations: normalizes quantities (evidence: `backend/controllers/purchaseController.js`)
- Sales and billing → Invoice generation: generates invoices (evidence: `backend/controllers/saleController.js`)
- Database connection → PostgreSQL: connects (evidence: `backend/config/db.js`)
- Inventory domain → Request validation: validates input (evidence: `backend/routes/inventoryRoutes.js`)
- Employee management → Request validation: validates input (evidence: `backend/routes/employeeRoutes.js`)
