# mannyivfouy/pos_api_express architecture

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

- Interactive diagram: https://gitdiagram.com/mannyivfouy/pos_api_express
- Repository: https://github.com/mannyivfouy/pos_api_express

## Overview

Precision POS Backend is an Express/Mongoose REST API for point-of-sale and inventory operations. A client request enters the app, is routed to domain handlers, and—where shown—flows through controllers to services and persisted models. Sales cover pending/complete/cancelled payments, stock updates, and reporting; purchasing and the other management domains are documented capabilities, though several implementations were not excerpted. The graph preserves those domains without guessing their internal call chains; dashed links mark documented but unverified integrations.

Main entry points: [`src/routes`](https://github.com/mannyivfouy/pos_api_express/tree/main/src/routes) (API routes), [`src/services/sale.service.ts`](https://github.com/mannyivfouy/pos_api_express/blob/main/src/services/sale.service.ts) (Sale processing), [`src/services/product.service.ts`](https://github.com/mannyivfouy/pos_api_express/blob/main/src/services/product.service.ts) (Product service), [`src/middlewares/auth.middleware.ts`](https://github.com/mannyivfouy/pos_api_express/blob/main/src/middlewares/auth.middleware.ts) (JWT authentication)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and access"]
  node_app["Express app<br/>[app.ts]"]
  node_routes["API routes"]
end

subgraph group_identity["Identity and access"]
  node_userctl["User controller<br/>[user.controller.ts]"]
  node_usersvc["User service<br/>[user.service.ts]"]
  node_usermodel[("User records<br/>[User.ts]")]
  node_authmw["JWT authentication<br/>[auth.middleware.ts]"]
  node_permsvc["Permission lookup"]
  node_permissiondata[("Role permissions<br/>[Role-Permission.ts]")]
  node_permissionmodel[("Permission records<br/>[Permission.ts]")]
end

subgraph group_catalog["Catalog and inventory"]
  node_productctl["Product controller"]
  node_productsvc["Product service<br/>[product.service.ts]"]
  node_productmodel[("Product records<br/>[Product.ts]")]
  node_categorysvc["Category service"]
  node_categorymodel[("Category records<br/>[Category.ts]")]
  node_supplier["Supplier management"]
end

subgraph group_transactions["Sales and purchasing"]
  node_purchasesvc["Purchase management"]
  node_purchasemodel[("Purchase records<br/>[Purchase.ts]")]
  node_salesctl["Sales controller<br/>[sale.controller.ts]"]
  node_salesvc["Sale processing<br/>[sale.service.ts]"]
  node_salemodel[("Sale records<br/>[Sale.ts]")]
  node_saleitems[("Sale items<br/>[SaleItem.ts]")]
end

subgraph group_support["Payments and messaging"]
  node_paymentsvc["Payment processing<br/>[payment.service.ts]"]
  node_bakong["Bakong KHQR<br/>[bakong.service.ts]"]
  node_telegram["Telegram notifications"]
end

node_client(("API client"))

node_client -->|"sends request"| node_app
node_app -->|"mounts routes"| node_routes
node_routes -->|"dispatches"| node_userctl
node_routes -->|"authenticates"| node_authmw
node_routes -->|"calls profile update"| node_usersvc
node_userctl -->|"calls"| node_usersvc
node_usersvc -->|"reads and writes"| node_usermodel
node_authmw -->|"loads user"| node_usermodel
node_authmw -->|"loads permissions"| node_permsvc
node_permsvc -->|"reads mappings"| node_permissiondata
node_permsvc -->|"reads permissions"| node_permissionmodel
node_routes -->|"dispatches"| node_productctl
node_productctl -->|"calls"| node_productsvc
node_productsvc -->|"reads and writes"| node_productmodel
node_productsvc -->|"checks category"| node_categorymodel
node_productsvc -->|"checks supplier"| node_supplier
node_categorysvc -->|"reads and writes"| node_categorymodel
node_routes -->|"dispatches"| node_salesctl
node_salesctl -->|"calls"| node_salesvc
node_salesvc -->|"reads and writes"| node_salemodel
node_salesvc -->|"reads and writes"| node_saleitems
node_salesvc -->|"checks and reduces stock"| node_productmodel
node_salesvc -->|"requests and verifies payment"| node_paymentsvc
node_salesvc -->|"sends notification"| node_telegram
node_purchasesvc -->|"reads and writes"| node_purchasemodel
node_purchasesvc -->|"updates inventory"| node_productmodel
node_paymentsvc -.->|"uses KHQR"| node_bakong

click node_app "https://github.com/mannyivfouy/pos_api_express/blob/main/src/app.ts"
click node_routes "https://github.com/mannyivfouy/pos_api_express/tree/main/src/routes"
click node_userctl "https://github.com/mannyivfouy/pos_api_express/blob/main/src/controllers/user.controller.ts"
click node_usersvc "https://github.com/mannyivfouy/pos_api_express/blob/main/src/services/user.service.ts"
click node_usermodel "https://github.com/mannyivfouy/pos_api_express/blob/main/src/models/User.ts"
click node_authmw "https://github.com/mannyivfouy/pos_api_express/blob/main/src/middlewares/auth.middleware.ts"
click node_permsvc "https://github.com/mannyivfouy/pos_api_express/blob/main/src/services/permission.service.ts"
click node_permissiondata "https://github.com/mannyivfouy/pos_api_express/blob/main/src/models/Role-Permission.ts"
click node_permissionmodel "https://github.com/mannyivfouy/pos_api_express/blob/main/src/models/Permission.ts"
click node_productctl "https://github.com/mannyivfouy/pos_api_express/blob/main/src/controllers/product.controller.ts"
click node_productsvc "https://github.com/mannyivfouy/pos_api_express/blob/main/src/services/product.service.ts"
click node_productmodel "https://github.com/mannyivfouy/pos_api_express/blob/main/src/models/Product.ts"
click node_categorysvc "https://github.com/mannyivfouy/pos_api_express/blob/main/src/services/category.service.ts"
click node_categorymodel "https://github.com/mannyivfouy/pos_api_express/blob/main/src/models/Category.ts"
click node_supplier "https://github.com/mannyivfouy/pos_api_express/blob/main/src/services/supplier.service.ts"
click node_purchasesvc "https://github.com/mannyivfouy/pos_api_express/blob/main/src/services/purchase.service.ts"
click node_purchasemodel "https://github.com/mannyivfouy/pos_api_express/blob/main/src/models/Purchase.ts"
click node_salesctl "https://github.com/mannyivfouy/pos_api_express/blob/main/src/controllers/sale.controller.ts"
click node_salesvc "https://github.com/mannyivfouy/pos_api_express/blob/main/src/services/sale.service.ts"
click node_salemodel "https://github.com/mannyivfouy/pos_api_express/blob/main/src/models/Sale.ts"
click node_saleitems "https://github.com/mannyivfouy/pos_api_express/blob/main/src/models/SaleItem.ts"
click node_paymentsvc "https://github.com/mannyivfouy/pos_api_express/blob/main/src/services/payment.service.ts"
click node_bakong "https://github.com/mannyivfouy/pos_api_express/blob/main/src/services/bakong.service.ts"
click node_telegram "https://github.com/mannyivfouy/pos_api_express/blob/main/src/services/telegram.service.ts"

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_routes,node_client toneBlue
class node_userctl,node_usersvc,node_usermodel,node_authmw,node_permsvc,node_permissiondata,node_permissionmodel toneAmber
class node_productctl,node_productsvc,node_productmodel,node_categorysvc,node_categorymodel,node_supplier toneMint
class node_purchasesvc,node_purchasemodel,node_salesctl,node_salesvc,node_salemodel,node_saleitems toneRose
class node_paymentsvc,node_bakong,node_telegram toneIndigo
```

## Components

### API and access

- [Express app](https://github.com/mannyivfouy/pos_api_express/blob/main/src/app.ts): `src/app.ts`
- [API routes](https://github.com/mannyivfouy/pos_api_express/tree/main/src/routes): `src/routes`

### Identity and access

- [User controller](https://github.com/mannyivfouy/pos_api_express/blob/main/src/controllers/user.controller.ts): `src/controllers/user.controller.ts`
- [User service](https://github.com/mannyivfouy/pos_api_express/blob/main/src/services/user.service.ts): `src/services/user.service.ts`
- [User records](https://github.com/mannyivfouy/pos_api_express/blob/main/src/models/User.ts): `src/models/User.ts`
- [JWT authentication](https://github.com/mannyivfouy/pos_api_express/blob/main/src/middlewares/auth.middleware.ts): `src/middlewares/auth.middleware.ts`
- [Permission lookup](https://github.com/mannyivfouy/pos_api_express/blob/main/src/services/permission.service.ts): `src/services/permission.service.ts`
- [Role permissions](https://github.com/mannyivfouy/pos_api_express/blob/main/src/models/Role-Permission.ts): `src/models/Role-Permission.ts`
- [Permission records](https://github.com/mannyivfouy/pos_api_express/blob/main/src/models/Permission.ts): `src/models/Permission.ts`

### Catalog and inventory

- [Product controller](https://github.com/mannyivfouy/pos_api_express/blob/main/src/controllers/product.controller.ts): `src/controllers/product.controller.ts`
- [Product service](https://github.com/mannyivfouy/pos_api_express/blob/main/src/services/product.service.ts): `src/services/product.service.ts`
- [Product records](https://github.com/mannyivfouy/pos_api_express/blob/main/src/models/Product.ts): `src/models/Product.ts`
- [Category service](https://github.com/mannyivfouy/pos_api_express/blob/main/src/services/category.service.ts): `src/services/category.service.ts`
- [Category records](https://github.com/mannyivfouy/pos_api_express/blob/main/src/models/Category.ts): `src/models/Category.ts`
- [Supplier management](https://github.com/mannyivfouy/pos_api_express/blob/main/src/services/supplier.service.ts): `src/services/supplier.service.ts`

### Sales and purchasing

- [Purchase management](https://github.com/mannyivfouy/pos_api_express/blob/main/src/services/purchase.service.ts): `src/services/purchase.service.ts`
- [Purchase records](https://github.com/mannyivfouy/pos_api_express/blob/main/src/models/Purchase.ts): `src/models/Purchase.ts`
- [Sales controller](https://github.com/mannyivfouy/pos_api_express/blob/main/src/controllers/sale.controller.ts): `src/controllers/sale.controller.ts`
- [Sale processing](https://github.com/mannyivfouy/pos_api_express/blob/main/src/services/sale.service.ts): `src/services/sale.service.ts`
- [Sale records](https://github.com/mannyivfouy/pos_api_express/blob/main/src/models/Sale.ts): `src/models/Sale.ts`
- [Sale items](https://github.com/mannyivfouy/pos_api_express/blob/main/src/models/SaleItem.ts): `src/models/SaleItem.ts`

### Payments and messaging

- [Payment processing](https://github.com/mannyivfouy/pos_api_express/blob/main/src/services/payment.service.ts): `src/services/payment.service.ts`
- [Bakong KHQR](https://github.com/mannyivfouy/pos_api_express/blob/main/src/services/bakong.service.ts): `src/services/bakong.service.ts`
- [Telegram notifications](https://github.com/mannyivfouy/pos_api_express/blob/main/src/services/telegram.service.ts): `src/services/telegram.service.ts`

### Other components

- **API client**

## Connections

- API client → Express app: sends request
- Express app → API routes: mounts routes (evidence: `src/app.ts`)
- API routes → User controller: dispatches (evidence: `src/routes/user.route.ts`)
- API routes → JWT authentication: authenticates (evidence: `src/routes/user.route.ts`)
- API routes → User service: calls profile update (evidence: `src/routes/user.route.ts`)
- User controller → User service: calls (evidence: `src/controllers/user.controller.ts`)
- User service → User records: reads and writes (evidence: `src/services/user.service.ts`)
- JWT authentication → User records: loads user (evidence: `src/middlewares/auth.middleware.ts`)
- JWT authentication → Permission lookup: loads permissions (evidence: `src/middlewares/auth.middleware.ts`)
- Permission lookup → Role permissions: reads mappings (evidence: `src/services/permission.service.ts`)
- Permission lookup → Permission records: reads permissions (evidence: `src/services/permission.service.ts`)
- API routes → Product controller: dispatches (evidence: `src/routes/product.route.ts`)
- Product controller → Product service: calls (evidence: `src/controllers/product.controller.ts`)
- Product service → Product records: reads and writes (evidence: `src/services/product.service.ts`)
- Product service → Category records: checks category (evidence: `src/services/product.service.ts`)
- Product service → Supplier management: checks supplier (evidence: `src/services/product.service.ts`)
- Category service → Category records: reads and writes (evidence: `src/services/category.service.ts`)
- API routes → Sales controller: dispatches
- Sales controller → Sale processing: calls (evidence: `src/controllers/sale.controller.ts`)
- Sale processing → Sale records: reads and writes (evidence: `src/services/sale.service.ts`)
- Sale processing → Sale items: reads and writes (evidence: `src/services/sale.service.ts`)
- Sale processing → Product records: checks and reduces stock (evidence: `src/services/sale.service.ts`)
- Sale processing → Payment processing: requests and verifies payment (evidence: `src/services/sale.service.ts`)
- Sale processing → Telegram notifications: sends notification (evidence: `src/services/sale.service.ts`)
- Purchase management → Purchase records: reads and writes (evidence: `src/services/purchase.service.ts`)
- Purchase management → Product records: updates inventory (evidence: `src/services/purchase.service.ts`)
- Payment processing → Bakong KHQR: uses KHQR
