# akibrahman/medicorx architecture

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

- Interactive diagram: https://gitdiagram.com/akibrahman/medicorx
- Repository: https://github.com/akibrahman/medicorx

## Overview

MedicoRx is a pharmacy storefront and management system. Customers browse medicines, manage a cart, place cash-on-delivery orders, and track orders and notifications; order creation deducts stock from earliest-expiring batches. Admins manage medicines, inventory, orders, payments, and reports. The graph follows documented route capabilities and sampled handlers; some UI-to-API links are documented rather than shown in sampled page source.

Main entry points: [`app/api/orders/route.js`](https://github.com/akibrahman/medicorx/blob/main/app/api/orders/route.js) (Order placement and listing), [`app/api/admin/dashboard/route.js`](https://github.com/akibrahman/medicorx/blob/main/app/api/admin/dashboard/route.js) (Admin dashboard API), [`app/api/admin/medicines/route.js`](https://github.com/akibrahman/medicorx/blob/main/app/api/admin/medicines/route.js) (Admin medicine API), [`app/api/orders/[id]/route.js`](https://github.com/akibrahman/medicorx/blob/main/app/api/orders/%5Bid%5D/route.js) (Order detail and updates)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_customer["Customer commerce"]
  node_storefront["Storefront and shop<br/>[page.jsx]"]
  node_cart["Cart state<br/>[CartContext.jsx]"]
  node_checkout["Checkout<br/>[CheckoutClient.jsx]"]
  node_orders_ui["Order history and detail<br/>[page.jsx]"]
  node_notifications_ui["Notifications<br/>[page.jsx]"]
  node_public_medicines_api["Public medicine API<br/>[route.js]"]
  node_order_api["Order placement and listing<br/>[route.js]"]
  node_order_detail_api["Order detail and updates<br/>[route.js]"]
  node_notification_api["Notification API<br/>[route.js]"]
end

subgraph group_identity["Identity and access"]
  node_auth_ui["Login and registration<br/>[page.jsx]"]
  node_auth_api["Authentication handlers<br/>[route.js]"]
  node_session["Cookie sessions<br/>[session.js]"]
end

subgraph group_admin["Pharmacy operations"]
  node_medicine_admin["Medicine catalog admin<br/>[page.jsx]"]
  node_inventory_admin["Inventory management<br/>[page.jsx]"]
  node_orders_admin["Order management<br/>[page.jsx]"]
  node_dashboard_ui["Dashboard and reports<br/>[page.jsx]"]
  node_admin_medicines_api["Admin medicine API<br/>[route.js]"]
  node_admin_dashboard_api["Admin dashboard API<br/>[route.js]"]
end

subgraph group_data["Persistence and shared state"]
  node_db_connection["MongoDB connection<br/>[db.js]"]
  node_medicine_model[("Medicine records<br/>[Medicine.js]")]
  node_inventory_model[("Inventory batches<br/>[Inventory.js]")]
  node_order_model[("Orders<br/>[Order.js]")]
  node_order_item_model[("Order items<br/>[OrderItem.js]")]
  node_transaction_model[("Transactions<br/>[Transaction.js]")]
  node_notification_model[("Notifications<br/>[Notification.js]")]
  node_user_model[("Users<br/>[User.js]")]
end

node_customer(("Customer"))
node_admin_actor(("Admin"))
node_mongo[("MongoDB")]

node_customer -->|"browses"| node_storefront
node_storefront -.->|"requests listings"| node_public_medicines_api
node_public_medicines_api -->|"aggregates"| node_medicine_model
node_public_medicines_api -->|"joins stock"| node_inventory_model
node_customer -->|"manages items"| node_cart
node_storefront -->|"adds medicines"| node_cart
node_cart -->|"supplies cart"| node_checkout
node_customer -->|"places order"| node_checkout
node_checkout -->|"submits order"| node_order_api
node_order_api -->|"checks session"| node_session
node_order_api -->|"creates order"| node_order_model
node_order_api -->|"creates items"| node_order_item_model
node_order_api -->|"deducts FIFO stock"| node_inventory_model
node_order_api -->|"creates transaction"| node_transaction_model
node_order_api -->|"creates confirmation"| node_notification_model
node_customer -->|"signs in"| node_auth_ui
node_auth_ui -.->|"authenticates"| node_auth_api
node_auth_api -.->|"sets session"| node_session
node_orders_ui -.->|"lists orders"| node_order_api
node_orders_ui -.->|"loads details"| node_order_detail_api
node_order_detail_api -->|"reads and updates"| node_order_model
node_order_detail_api -->|"loads items"| node_order_item_model
node_order_detail_api -->|"loads payment"| node_transaction_model
node_notifications_ui -.->|"loads notifications"| node_notification_api
node_notification_api -->|"reads notifications"| node_notification_model
node_admin_actor -->|"manages catalog"| node_medicine_admin
node_admin_actor -->|"manages stock"| node_inventory_admin
node_admin_actor -->|"manages orders"| node_orders_admin
node_admin_actor -->|"reviews metrics"| node_dashboard_ui
node_medicine_admin -.->|"maintains catalog"| node_admin_medicines_api
node_admin_medicines_api -->|"checks role"| node_session
node_admin_medicines_api -->|"creates and lists"| node_medicine_model
node_admin_medicines_api -->|"creates stock batch"| node_inventory_model
node_inventory_admin -.->|"manages batches"| node_admin_medicines_api
node_dashboard_ui -.->|"requests metrics"| node_admin_dashboard_api
node_admin_dashboard_api -->|"checks role"| node_session
node_admin_dashboard_api -->|"calculates sales"| node_order_model
node_admin_dashboard_api -->|"reads catalog"| node_medicine_model
node_admin_dashboard_api -->|"finds stock alerts"| node_inventory_model
node_db_connection -->|"connects"| node_mongo

click node_storefront "https://github.com/akibrahman/medicorx/blob/main/app/(customer)/shop/page.jsx"
click node_cart "https://github.com/akibrahman/medicorx/blob/main/context/CartContext.jsx"
click node_checkout "https://github.com/akibrahman/medicorx/blob/main/app/(customer)/checkout/CheckoutClient.jsx"
click node_orders_ui "https://github.com/akibrahman/medicorx/blob/main/app/(customer)/orders/page.jsx"
click node_notifications_ui "https://github.com/akibrahman/medicorx/blob/main/app/(customer)/notifications/page.jsx"
click node_auth_ui "https://github.com/akibrahman/medicorx/blob/main/app/(auth)/login/page.jsx"
click node_auth_api "https://github.com/akibrahman/medicorx/blob/main/app/api/auth/login/route.js"
click node_session "https://github.com/akibrahman/medicorx/blob/main/lib/session.js"
click node_medicine_admin "https://github.com/akibrahman/medicorx/blob/main/app/(admin)/medicines/page.jsx"
click node_inventory_admin "https://github.com/akibrahman/medicorx/blob/main/app/(admin)/inventory/page.jsx"
click node_orders_admin "https://github.com/akibrahman/medicorx/blob/main/app/(admin)/admin-orders/page.jsx"
click node_dashboard_ui "https://github.com/akibrahman/medicorx/blob/main/app/(admin)/dashboard/page.jsx"
click node_public_medicines_api "https://github.com/akibrahman/medicorx/blob/main/app/api/medicines/route.js"
click node_order_api "https://github.com/akibrahman/medicorx/blob/main/app/api/orders/route.js"
click node_order_detail_api "https://github.com/akibrahman/medicorx/blob/main/app/api/orders/%5Bid%5D/route.js"
click node_notification_api "https://github.com/akibrahman/medicorx/blob/main/app/api/notifications/route.js"
click node_admin_medicines_api "https://github.com/akibrahman/medicorx/blob/main/app/api/admin/medicines/route.js"
click node_admin_dashboard_api "https://github.com/akibrahman/medicorx/blob/main/app/api/admin/dashboard/route.js"
click node_db_connection "https://github.com/akibrahman/medicorx/blob/main/lib/db.js"
click node_medicine_model "https://github.com/akibrahman/medicorx/blob/main/models/Medicine.js"
click node_inventory_model "https://github.com/akibrahman/medicorx/blob/main/models/Inventory.js"
click node_order_model "https://github.com/akibrahman/medicorx/blob/main/models/Order.js"
click node_order_item_model "https://github.com/akibrahman/medicorx/blob/main/models/OrderItem.js"
click node_transaction_model "https://github.com/akibrahman/medicorx/blob/main/models/Transaction.js"
click node_notification_model "https://github.com/akibrahman/medicorx/blob/main/models/Notification.js"
click node_user_model "https://github.com/akibrahman/medicorx/blob/main/models/User.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_storefront,node_cart,node_checkout,node_orders_ui,node_notifications_ui,node_public_medicines_api,node_order_api,node_order_detail_api,node_notification_api toneBlue
class node_auth_ui,node_auth_api,node_session,node_mongo toneAmber
class node_medicine_admin,node_inventory_admin,node_orders_admin,node_dashboard_ui,node_admin_medicines_api,node_admin_dashboard_api toneMint
class node_db_connection,node_medicine_model,node_inventory_model,node_order_model,node_order_item_model,node_transaction_model,node_notification_model,node_user_model toneRose
class node_customer,node_admin_actor toneIndigo
```

## Components

### Customer commerce

- [Storefront and shop](https://github.com/akibrahman/medicorx/blob/main/app/(customer)/shop/page.jsx): `app/(customer)/shop/page.jsx`
- [Cart state](https://github.com/akibrahman/medicorx/blob/main/context/CartContext.jsx): `context/CartContext.jsx`
- [Checkout](https://github.com/akibrahman/medicorx/blob/main/app/(customer)/checkout/CheckoutClient.jsx): `app/(customer)/checkout/CheckoutClient.jsx`
- [Order history and detail](https://github.com/akibrahman/medicorx/blob/main/app/(customer)/orders/page.jsx): `app/(customer)/orders/page.jsx`
- [Notifications](https://github.com/akibrahman/medicorx/blob/main/app/(customer)/notifications/page.jsx): `app/(customer)/notifications/page.jsx`
- [Public medicine API](https://github.com/akibrahman/medicorx/blob/main/app/api/medicines/route.js): `app/api/medicines/route.js`
- [Order placement and listing](https://github.com/akibrahman/medicorx/blob/main/app/api/orders/route.js): `app/api/orders/route.js`
- [Order detail and updates](https://github.com/akibrahman/medicorx/blob/main/app/api/orders/%5Bid%5D/route.js): `app/api/orders/[id]/route.js`
- [Notification API](https://github.com/akibrahman/medicorx/blob/main/app/api/notifications/route.js): `app/api/notifications/route.js`

### Identity and access

- [Login and registration](https://github.com/akibrahman/medicorx/blob/main/app/(auth)/login/page.jsx): `app/(auth)/login/page.jsx`
- [Authentication handlers](https://github.com/akibrahman/medicorx/blob/main/app/api/auth/login/route.js): `app/api/auth/login/route.js`
- [Cookie sessions](https://github.com/akibrahman/medicorx/blob/main/lib/session.js): `lib/session.js`

### Pharmacy operations

- [Medicine catalog admin](https://github.com/akibrahman/medicorx/blob/main/app/(admin)/medicines/page.jsx): `app/(admin)/medicines/page.jsx`
- [Inventory management](https://github.com/akibrahman/medicorx/blob/main/app/(admin)/inventory/page.jsx): `app/(admin)/inventory/page.jsx`
- [Order management](https://github.com/akibrahman/medicorx/blob/main/app/(admin)/admin-orders/page.jsx): `app/(admin)/admin-orders/page.jsx`
- [Dashboard and reports](https://github.com/akibrahman/medicorx/blob/main/app/(admin)/dashboard/page.jsx): `app/(admin)/dashboard/page.jsx`
- [Admin medicine API](https://github.com/akibrahman/medicorx/blob/main/app/api/admin/medicines/route.js): `app/api/admin/medicines/route.js`
- [Admin dashboard API](https://github.com/akibrahman/medicorx/blob/main/app/api/admin/dashboard/route.js): `app/api/admin/dashboard/route.js`

### Persistence and shared state

- [MongoDB connection](https://github.com/akibrahman/medicorx/blob/main/lib/db.js): `lib/db.js`
- [Medicine records](https://github.com/akibrahman/medicorx/blob/main/models/Medicine.js): `models/Medicine.js`
- [Inventory batches](https://github.com/akibrahman/medicorx/blob/main/models/Inventory.js): `models/Inventory.js`
- [Orders](https://github.com/akibrahman/medicorx/blob/main/models/Order.js): `models/Order.js`
- [Order items](https://github.com/akibrahman/medicorx/blob/main/models/OrderItem.js): `models/OrderItem.js`
- [Transactions](https://github.com/akibrahman/medicorx/blob/main/models/Transaction.js): `models/Transaction.js`
- [Notifications](https://github.com/akibrahman/medicorx/blob/main/models/Notification.js): `models/Notification.js`
- [Users](https://github.com/akibrahman/medicorx/blob/main/models/User.js): `models/User.js`

### Other components

- **Customer**
- **Admin**
- **MongoDB**

## Connections

- Customer → Storefront and shop: browses (evidence: `README.md`)
- Storefront and shop → Public medicine API: requests listings
- Public medicine API → Medicine records: aggregates (evidence: `app/api/medicines/route.js`)
- Public medicine API → Inventory batches: joins stock (evidence: `app/api/medicines/route.js`)
- Customer → Cart state: manages items (evidence: `README.md`)
- Storefront and shop → Cart state: adds medicines (evidence: `app/(customer)/shop/page.jsx`)
- Cart state → Checkout: supplies cart (evidence: `app/(customer)/checkout/CheckoutClient.jsx`)
- Customer → Checkout: places order (evidence: `README.md`)
- Checkout → Order placement and listing: submits order (evidence: `README.md`)
- Order placement and listing → Cookie sessions: checks session (evidence: `app/api/orders/route.js`)
- Order placement and listing → Orders: creates order (evidence: `app/api/orders/route.js`)
- Order placement and listing → Order items: creates items (evidence: `app/api/orders/route.js`)
- Order placement and listing → Inventory batches: deducts FIFO stock (evidence: `app/api/orders/route.js`)
- Order placement and listing → Transactions: creates transaction (evidence: `app/api/orders/route.js`)
- Order placement and listing → Notifications: creates confirmation (evidence: `app/api/orders/route.js`)
- Customer → Login and registration: signs in (evidence: `README.md`)
- Login and registration → Authentication handlers: authenticates
- Authentication handlers → Cookie sessions: sets session
- Order history and detail → Order placement and listing: lists orders
- Order history and detail → Order detail and updates: loads details
- Order detail and updates → Orders: reads and updates (evidence: `app/api/orders/[id]/route.js`)
- Order detail and updates → Order items: loads items (evidence: `app/api/orders/[id]/route.js`)
- Order detail and updates → Transactions: loads payment (evidence: `app/api/orders/[id]/route.js`)
- Notifications → Notification API: loads notifications
- Notification API → Notifications: reads notifications (evidence: `app/api/notifications/route.js`)
- Admin → Medicine catalog admin: manages catalog (evidence: `README.md`)
- Admin → Inventory management: manages stock (evidence: `README.md`)
- Admin → Order management: manages orders (evidence: `README.md`)
- Admin → Dashboard and reports: reviews metrics (evidence: `README.md`)
- Medicine catalog admin → Admin medicine API: maintains catalog
- Admin medicine API → Cookie sessions: checks role (evidence: `app/api/admin/medicines/route.js`)
- Admin medicine API → Medicine records: creates and lists (evidence: `app/api/admin/medicines/route.js`)
- Admin medicine API → Inventory batches: creates stock batch (evidence: `app/api/admin/medicines/route.js`)
- Inventory management → Admin medicine API: manages batches
- Dashboard and reports → Admin dashboard API: requests metrics
- Admin dashboard API → Cookie sessions: checks role (evidence: `app/api/admin/dashboard/route.js`)
- Admin dashboard API → Orders: calculates sales (evidence: `app/api/admin/dashboard/route.js`)
- Admin dashboard API → Medicine records: reads catalog (evidence: `app/api/admin/dashboard/route.js`)
- Admin dashboard API → Inventory batches: finds stock alerts (evidence: `app/api/admin/dashboard/route.js`)
- MongoDB connection → MongoDB: connects (evidence: `lib/db.js`)
