# gichukikelvin67/qr-code-bckend architecture

> Architecture diagram of the GitHub repository gichukikelvin67/qr-code-bckend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/gichukikelvin67/qr-code-bckend
- Repository: https://github.com/gichukikelvin67/qr-code-bckend

## Overview

This is a restaurant operations API: staff and public clients make HTTP requests for restaurant setup, menus, orders, kitchen preparation, billing, payments, and related operations. The principal order workflow is exposed through public-order and order-management routes, with separate kitchen and bar preparation queues; billing and M-Pesa payment processing are distinct stages. Other major capabilities include inventory and recipes, discounts, refunds, loyalty, and analytics. The graph follows documented route wiring and sampled calls; several service internals and route handlers were not excerpted, so their internal links are omitted.

Main entry points: [`src/app.js`](https://github.com/gichukikelvin67/qr-code-bckend/blob/main/src/app.js) (HTTP application), [`src/modules/payments/mpesa.service.js`](https://github.com/gichukikelvin67/qr-code-bckend/blob/main/src/modules/payments/mpesa.service.js) (M-Pesa payments), [`src/server.js`](https://github.com/gichukikelvin67/qr-code-bckend/blob/main/src/server.js) (Server startup), [`src/modules/orders/order-management.service.js`](https://github.com/gichukikelvin67/qr-code-bckend/blob/main/src/modules/orders/order-management.service.js) (Order management)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["API and access"]
  node_app["HTTP application<br/>[app.js]"]
  node_auth["Authentication<br/>[auth.middleware.js]"]
end

subgraph group_operations["Restaurant operations"]
  node_restaurants["Restaurant setup"]
  node_tables["Tables and sessions<br/>[table.service.js]"]
  node_menus["Menus<br/>[menu.service.js]"]
  node_orders["Order management"]
  node_publicorders["Public ordering"]
  node_preparation["Kitchen preparation"]
  node_inventory["Inventory"]
  node_recipes["Recipes<br/>[recipe.service.js]"]
  node_discounts["Discounts"]
end

subgraph group_finance["Billing and payments"]
  node_billing["Billing<br/>[billing.service.js]"]
  node_payments["M-Pesa payments<br/>[mpesa.service.js]"]
  node_daraja["Daraja integration<br/>[daraja.service.js]"]
  node_refunds["Refunds<br/>[refund.service.js]"]
end

subgraph group_insights["Customer and insights"]
  node_loyalty["Loyalty<br/>[loyalty.service.js]"]
  node_analytics["Analytics and exports"]
end

subgraph group_runtime["Runtime infrastructure"]
  node_database[("Prisma database<br/>[database.js]")]
  node_server["Server startup<br/>[server.js]"]
  node_socket["Socket events<br/>[socket-instance.js]"]
  node_reconciliation["Payment reconciliation job"]
  node_env["Environment config<br/>[env.js]"]
end

node_client(("API clients"))

node_client -->|"sends requests"| node_app
node_app -.->|"routes through"| node_auth
node_app -->|"routes to"| node_restaurants
node_app -->|"routes to"| node_tables
node_app -->|"routes to"| node_menus
node_app -->|"routes to"| node_orders
node_app -->|"routes to"| node_publicorders
node_app -->|"routes to"| node_preparation
node_app -->|"routes to"| node_billing
node_app -->|"routes to"| node_payments
node_app -->|"routes to"| node_inventory
node_app -->|"routes to"| node_recipes
node_app -->|"routes to"| node_discounts
node_app -->|"routes to"| node_refunds
node_app -->|"routes to"| node_loyalty
node_app -->|"routes to"| node_analytics
node_orders -->|"sets instance"| node_socket
node_preparation -.->|"updates status"| node_orders
node_payments -->|"uses gateway"| node_daraja
node_payments -->|"reads and writes"| node_database
node_payments -->|"reconciled by"| node_reconciliation
node_reconciliation -->|"checks payments"| node_payments
node_server -->|"serves"| node_app
node_server -->|"connects"| node_database
node_server -->|"configures"| node_socket
node_server -->|"starts job"| node_reconciliation
node_database -->|"loads config"| node_env

click node_app "https://github.com/gichukikelvin67/qr-code-bckend/blob/main/src/app.js"
click node_auth "https://github.com/gichukikelvin67/qr-code-bckend/blob/main/src/modules/auth/auth.middleware.js"
click node_restaurants "https://github.com/gichukikelvin67/qr-code-bckend/blob/main/src/modules/restaurants/restaurant.service.js"
click node_tables "https://github.com/gichukikelvin67/qr-code-bckend/blob/main/src/modules/tables/table.service.js"
click node_menus "https://github.com/gichukikelvin67/qr-code-bckend/blob/main/src/modules/menu/menu.service.js"
click node_orders "https://github.com/gichukikelvin67/qr-code-bckend/blob/main/src/modules/orders/order-management.service.js"
click node_publicorders "https://github.com/gichukikelvin67/qr-code-bckend/blob/main/src/modules/orders/public-order.routes.js"
click node_preparation "https://github.com/gichukikelvin67/qr-code-bckend/blob/main/src/modules/preparation/preparation.service.js"
click node_inventory "https://github.com/gichukikelvin67/qr-code-bckend/blob/main/src/modules/inventory/inventory.service.js"
click node_recipes "https://github.com/gichukikelvin67/qr-code-bckend/blob/main/src/modules/recipes/recipe.service.js"
click node_discounts "https://github.com/gichukikelvin67/qr-code-bckend/blob/main/src/modules/discounts/discount.service.js"
click node_billing "https://github.com/gichukikelvin67/qr-code-bckend/blob/main/src/modules/billing/billing.service.js"
click node_payments "https://github.com/gichukikelvin67/qr-code-bckend/blob/main/src/modules/payments/mpesa.service.js"
click node_daraja "https://github.com/gichukikelvin67/qr-code-bckend/blob/main/src/modules/payments/daraja.service.js"
click node_refunds "https://github.com/gichukikelvin67/qr-code-bckend/blob/main/src/modules/refunds/refund.service.js"
click node_loyalty "https://github.com/gichukikelvin67/qr-code-bckend/blob/main/src/modules/loyalty/loyalty.service.js"
click node_analytics "https://github.com/gichukikelvin67/qr-code-bckend/blob/main/src/modules/analytics/analytics.controller.js"
click node_database "https://github.com/gichukikelvin67/qr-code-bckend/blob/main/src/config/database.js"
click node_server "https://github.com/gichukikelvin67/qr-code-bckend/blob/main/src/server.js"
click node_socket "https://github.com/gichukikelvin67/qr-code-bckend/blob/main/src/sockets/socket-instance.js"
click node_reconciliation "https://github.com/gichukikelvin67/qr-code-bckend/blob/main/src/jobs/mpesa-reconciliation.job.js"
click node_env "https://github.com/gichukikelvin67/qr-code-bckend/blob/main/src/config/env.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_auth,node_client toneBlue
class node_restaurants,node_tables,node_menus,node_orders,node_publicorders,node_preparation,node_inventory,node_recipes,node_discounts toneAmber
class node_billing,node_payments,node_daraja,node_refunds toneMint
class node_loyalty,node_analytics toneRose
class node_database,node_server,node_socket,node_reconciliation,node_env toneIndigo
```

## Components

### API and access

- [HTTP application](https://github.com/gichukikelvin67/qr-code-bckend/blob/main/src/app.js): `src/app.js`
- [Authentication](https://github.com/gichukikelvin67/qr-code-bckend/blob/main/src/modules/auth/auth.middleware.js): `src/modules/auth/auth.middleware.js`

### Restaurant operations

- [Restaurant setup](https://github.com/gichukikelvin67/qr-code-bckend/blob/main/src/modules/restaurants/restaurant.service.js): `src/modules/restaurants/restaurant.service.js`
- [Tables and sessions](https://github.com/gichukikelvin67/qr-code-bckend/blob/main/src/modules/tables/table.service.js): `src/modules/tables/table.service.js`
- [Menus](https://github.com/gichukikelvin67/qr-code-bckend/blob/main/src/modules/menu/menu.service.js): `src/modules/menu/menu.service.js`
- [Order management](https://github.com/gichukikelvin67/qr-code-bckend/blob/main/src/modules/orders/order-management.service.js): `src/modules/orders/order-management.service.js`
- [Public ordering](https://github.com/gichukikelvin67/qr-code-bckend/blob/main/src/modules/orders/public-order.routes.js): `src/modules/orders/public-order.routes.js`
- [Kitchen preparation](https://github.com/gichukikelvin67/qr-code-bckend/blob/main/src/modules/preparation/preparation.service.js): `src/modules/preparation/preparation.service.js`
- [Inventory](https://github.com/gichukikelvin67/qr-code-bckend/blob/main/src/modules/inventory/inventory.service.js): `src/modules/inventory/inventory.service.js`
- [Recipes](https://github.com/gichukikelvin67/qr-code-bckend/blob/main/src/modules/recipes/recipe.service.js): `src/modules/recipes/recipe.service.js`
- [Discounts](https://github.com/gichukikelvin67/qr-code-bckend/blob/main/src/modules/discounts/discount.service.js): `src/modules/discounts/discount.service.js`

### Billing and payments

- [Billing](https://github.com/gichukikelvin67/qr-code-bckend/blob/main/src/modules/billing/billing.service.js): `src/modules/billing/billing.service.js`
- [M-Pesa payments](https://github.com/gichukikelvin67/qr-code-bckend/blob/main/src/modules/payments/mpesa.service.js): `src/modules/payments/mpesa.service.js`
- [Daraja integration](https://github.com/gichukikelvin67/qr-code-bckend/blob/main/src/modules/payments/daraja.service.js): `src/modules/payments/daraja.service.js`
- [Refunds](https://github.com/gichukikelvin67/qr-code-bckend/blob/main/src/modules/refunds/refund.service.js): `src/modules/refunds/refund.service.js`

### Customer and insights

- [Loyalty](https://github.com/gichukikelvin67/qr-code-bckend/blob/main/src/modules/loyalty/loyalty.service.js): `src/modules/loyalty/loyalty.service.js`
- [Analytics and exports](https://github.com/gichukikelvin67/qr-code-bckend/blob/main/src/modules/analytics/analytics.controller.js): `src/modules/analytics/analytics.controller.js`

### Runtime infrastructure

- [Prisma database](https://github.com/gichukikelvin67/qr-code-bckend/blob/main/src/config/database.js): `src/config/database.js`
- [Server startup](https://github.com/gichukikelvin67/qr-code-bckend/blob/main/src/server.js): `src/server.js`
- [Socket events](https://github.com/gichukikelvin67/qr-code-bckend/blob/main/src/sockets/socket-instance.js): `src/sockets/socket-instance.js`
- [Payment reconciliation job](https://github.com/gichukikelvin67/qr-code-bckend/blob/main/src/jobs/mpesa-reconciliation.job.js): `src/jobs/mpesa-reconciliation.job.js`
- [Environment config](https://github.com/gichukikelvin67/qr-code-bckend/blob/main/src/config/env.js): `src/config/env.js`

### Other components

- **API clients**

## Connections

- API clients → HTTP application: sends requests (evidence: `src/app.js`)
- HTTP application → Authentication: routes through
- HTTP application → Restaurant setup: routes to (evidence: `src/app.js`)
- HTTP application → Tables and sessions: routes to (evidence: `src/app.js`)
- HTTP application → Menus: routes to (evidence: `src/app.js`)
- HTTP application → Order management: routes to (evidence: `src/app.js`)
- HTTP application → Public ordering: routes to (evidence: `src/app.js`)
- HTTP application → Kitchen preparation: routes to (evidence: `src/app.js`)
- HTTP application → Billing: routes to (evidence: `src/app.js`)
- HTTP application → M-Pesa payments: routes to (evidence: `src/app.js`)
- HTTP application → Inventory: routes to (evidence: `src/app.js`)
- HTTP application → Recipes: routes to (evidence: `src/app.js`)
- HTTP application → Discounts: routes to (evidence: `src/app.js`)
- HTTP application → Refunds: routes to (evidence: `src/app.js`)
- HTTP application → Loyalty: routes to (evidence: `src/app.js`)
- HTTP application → Analytics and exports: routes to (evidence: `src/app.js`)
- Order management → Socket events: sets instance (evidence: `src/modules/orders/order-management.controller.js`)
- Kitchen preparation → Order management: updates status
- M-Pesa payments → Daraja integration: uses gateway (evidence: `src/modules/payments/mpesa.service.js`)
- M-Pesa payments → Prisma database: reads and writes (evidence: `src/modules/payments/mpesa.callback.controller.js`)
- M-Pesa payments → Payment reconciliation job: reconciled by (evidence: `src/jobs/mpesa-reconciliation.job.js`)
- Payment reconciliation job → M-Pesa payments: checks payments (evidence: `src/jobs/mpesa-reconciliation.job.js`)
- Server startup → HTTP application: serves (evidence: `src/server.js`)
- Server startup → Prisma database: connects (evidence: `src/server.js`)
- Server startup → Socket events: configures (evidence: `src/server.js`)
- Server startup → Payment reconciliation job: starts job (evidence: `src/server.js`)
- Prisma database → Environment config: loads config (evidence: `src/config/database.js`)
