# barwaqt/server architecture

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

- Interactive diagram: https://gitdiagram.com/barwaqt/server
- Repository: https://github.com/barwaqt/server

## Overview

Barwaqt is a commerce and delivery API for customers, vendors, riders, finance staff, and administrators. The main workflow runs from customer discovery and COD checkout through independent vendor fulfillment, rider dispatch/delivery, cash reconciliation, and settlement. Authentication and administration support that workflow; catalog discovery, customer account features, notifications, maps, marketing, and support are additional capabilities. The README documents the business stages; sampled source confirms application mounting, authentication, and selected service calls, but not every workflow implementation.

Main entry points: [`src/app.js`](https://github.com/barwaqt/server/blob/main/src/app.js) (HTTP API), [`src/services/order.service.js`](https://github.com/barwaqt/server/blob/main/src/services/order.service.js) (Order workflow), [`src/services/rider.service.js`](https://github.com/barwaqt/server/blob/main/src/services/rider.service.js) (Rider operations), [`src/services/finance.service.js`](https://github.com/barwaqt/server/blob/main/src/services/finance.service.js) (Finance operations)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_access["Access and API"]
  node_api["HTTP API<br/>[app.js]"]
  node_auth["Authentication<br/>[auth.service.js]"]
  node_phone_auth["Phone authentication"]
  node_sessions["Sessions<br/>[session.service.js]"]
  node_database[("PostgreSQL<br/>[database.js]")]
end

subgraph group_commerce["Commerce"]
  node_catalog["Catalog discovery"]
  node_search["Product search<br/>[search.service.js]"]
  node_customer_account["Customer account"]
  node_checkout["Order workflow<br/>[order.service.js]"]
end

subgraph group_fulfillment["Fulfillment"]
  node_vendor_fulfillment["Vendor fulfillment<br/>[vendor.service.js]"]
  node_dispatch["Dispatch and delivery"]
  node_rider_ops["Rider operations<br/>[rider.service.js]"]
  node_returns["Returns<br/>[return.service.js]"]
end

subgraph group_finance["Finance"]
  node_finance_ops["Finance operations<br/>[finance.service.js]"]
  node_reconcile["Cash reconciliation"]
end

subgraph group_operations["Operations"]
  node_admin_ops["Administration<br/>[admin.service.js]"]
  node_marketing["Marketing campaigns"]
  node_notifications["Notifications"]
  node_maps["Maps and location<br/>[maps.service.js]"]
  node_support["Support<br/>[support.service.js]"]
  node_veevo["Veevo SMS<br/>[veevo.service.js]"]
end

node_customer(("Customer"))
node_vendor_actor(("Vendor"))
node_rider_actor(("Rider"))
node_finance_actor(("Finance staff"))
node_admin_actor(("Administrator"))
node_sms_provider(("SMS provider"))

node_customer -->|"uses"| node_api
node_vendor_actor -->|"uses"| node_api
node_rider_actor -->|"uses"| node_api
node_finance_actor -->|"uses"| node_api
node_admin_actor -->|"uses"| node_api
node_api -->|"routes auth"| node_auth
node_api -->|"routes catalog"| node_catalog
node_api -->|"routes customer"| node_customer_account
node_api -->|"routes orders"| node_checkout
node_api -->|"routes finance"| node_finance_ops
node_auth -->|"creates sessions"| node_sessions
node_phone_auth -->|"creates sessions"| node_sessions
node_phone_auth -->|"sends SMS"| node_veevo
node_veevo -.->|"sends messages"| node_sms_provider
node_customer -->|"discovers products"| node_catalog
node_catalog -->|"supports search"| node_search
node_customer -->|"manages cart"| node_customer_account
node_customer -->|"places COD order"| node_checkout
node_checkout -->|"creates vendor orders"| node_vendor_fulfillment
node_vendor_actor -->|"fulfills orders"| node_vendor_fulfillment
node_vendor_fulfillment -->|"marks ready"| node_dispatch
node_dispatch -->|"assigns rider"| node_rider_ops
node_rider_actor -->|"updates delivery"| node_rider_ops
node_rider_ops -->|"initiates returns"| node_returns
node_rider_ops -->|"remits cash"| node_reconcile
node_finance_actor -->|"records cash"| node_reconcile
node_reconcile -->|"enables settlement"| node_finance_ops
node_finance_actor -->|"records settlements"| node_finance_ops
node_admin_actor -->|"manages platform"| node_admin_ops
node_admin_actor -->|"manages campaigns"| node_marketing
node_admin_actor -->|"manages support"| node_support
node_api -->|"serves notifications"| node_notifications
node_api -->|"serves maps"| node_maps
node_checkout -->|"persists orders"| node_database
node_finance_ops -->|"records finance"| node_database

click node_api "https://github.com/barwaqt/server/blob/main/src/app.js"
click node_auth "https://github.com/barwaqt/server/blob/main/src/services/auth.service.js"
click node_phone_auth "https://github.com/barwaqt/server/blob/main/src/services/phone-auth.service.js"
click node_sessions "https://github.com/barwaqt/server/blob/main/src/services/session.service.js"
click node_catalog "https://github.com/barwaqt/server/blob/main/src/controllers/catalog.controller.js"
click node_search "https://github.com/barwaqt/server/blob/main/src/services/search.service.js"
click node_customer_account "https://github.com/barwaqt/server/blob/main/src/controllers/customer.controller.js"
click node_checkout "https://github.com/barwaqt/server/blob/main/src/services/order.service.js"
click node_vendor_fulfillment "https://github.com/barwaqt/server/blob/main/src/services/vendor.service.js"
click node_dispatch "https://github.com/barwaqt/server/blob/main/src/services/delivery.service.js"
click node_rider_ops "https://github.com/barwaqt/server/blob/main/src/services/rider.service.js"
click node_returns "https://github.com/barwaqt/server/blob/main/src/services/return.service.js"
click node_finance_ops "https://github.com/barwaqt/server/blob/main/src/services/finance.service.js"
click node_reconcile "https://github.com/barwaqt/server/blob/main/src/services/reconciliation.service.js"
click node_database "https://github.com/barwaqt/server/blob/main/src/config/database.js"
click node_admin_ops "https://github.com/barwaqt/server/blob/main/src/services/admin.service.js"
click node_marketing "https://github.com/barwaqt/server/blob/main/src/services/marketing.service.js"
click node_notifications "https://github.com/barwaqt/server/blob/main/src/services/notification.service.js"
click node_maps "https://github.com/barwaqt/server/blob/main/src/services/maps.service.js"
click node_support "https://github.com/barwaqt/server/blob/main/src/services/support.service.js"
click node_veevo "https://github.com/barwaqt/server/blob/main/src/services/veevo.service.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_api,node_auth,node_phone_auth,node_sessions,node_database toneBlue
class node_catalog,node_search,node_customer_account,node_checkout toneAmber
class node_vendor_fulfillment,node_dispatch,node_rider_ops,node_returns toneMint
class node_finance_ops,node_reconcile toneRose
class node_admin_ops,node_marketing,node_notifications,node_maps,node_support,node_veevo,node_customer,node_vendor_actor,node_rider_actor,node_finance_actor,node_admin_actor,node_sms_provider toneIndigo
```

## Components

### Access and API

- [HTTP API](https://github.com/barwaqt/server/blob/main/src/app.js): `src/app.js`
- [Authentication](https://github.com/barwaqt/server/blob/main/src/services/auth.service.js): `src/services/auth.service.js`
- [Phone authentication](https://github.com/barwaqt/server/blob/main/src/services/phone-auth.service.js): `src/services/phone-auth.service.js`
- [Sessions](https://github.com/barwaqt/server/blob/main/src/services/session.service.js): `src/services/session.service.js`
- [PostgreSQL](https://github.com/barwaqt/server/blob/main/src/config/database.js): `src/config/database.js`

### Commerce

- [Catalog discovery](https://github.com/barwaqt/server/blob/main/src/controllers/catalog.controller.js): `src/controllers/catalog.controller.js`
- [Product search](https://github.com/barwaqt/server/blob/main/src/services/search.service.js): `src/services/search.service.js`
- [Customer account](https://github.com/barwaqt/server/blob/main/src/controllers/customer.controller.js): `src/controllers/customer.controller.js`
- [Order workflow](https://github.com/barwaqt/server/blob/main/src/services/order.service.js): `src/services/order.service.js`

### Fulfillment

- [Vendor fulfillment](https://github.com/barwaqt/server/blob/main/src/services/vendor.service.js): `src/services/vendor.service.js`
- [Dispatch and delivery](https://github.com/barwaqt/server/blob/main/src/services/delivery.service.js): `src/services/delivery.service.js`
- [Rider operations](https://github.com/barwaqt/server/blob/main/src/services/rider.service.js): `src/services/rider.service.js`
- [Returns](https://github.com/barwaqt/server/blob/main/src/services/return.service.js): `src/services/return.service.js`

### Finance

- [Finance operations](https://github.com/barwaqt/server/blob/main/src/services/finance.service.js): `src/services/finance.service.js`
- [Cash reconciliation](https://github.com/barwaqt/server/blob/main/src/services/reconciliation.service.js): `src/services/reconciliation.service.js`

### Operations

- [Administration](https://github.com/barwaqt/server/blob/main/src/services/admin.service.js): `src/services/admin.service.js`
- [Marketing campaigns](https://github.com/barwaqt/server/blob/main/src/services/marketing.service.js): `src/services/marketing.service.js`
- [Notifications](https://github.com/barwaqt/server/blob/main/src/services/notification.service.js): `src/services/notification.service.js`
- [Maps and location](https://github.com/barwaqt/server/blob/main/src/services/maps.service.js): `src/services/maps.service.js`
- [Support](https://github.com/barwaqt/server/blob/main/src/services/support.service.js): `src/services/support.service.js`
- [Veevo SMS](https://github.com/barwaqt/server/blob/main/src/services/veevo.service.js): `src/services/veevo.service.js`

### Other components

- **Customer**
- **Vendor**
- **Rider**
- **Finance staff**
- **Administrator**
- **SMS provider**

## Connections

- Customer → HTTP API: uses
- Vendor → HTTP API: uses
- Rider → HTTP API: uses
- Finance staff → HTTP API: uses
- Administrator → HTTP API: uses
- HTTP API → Authentication: routes auth
- HTTP API → Catalog discovery: routes catalog (evidence: `src/app.js`)
- HTTP API → Customer account: routes customer (evidence: `src/app.js`)
- HTTP API → Order workflow: routes orders (evidence: `src/app.js`)
- HTTP API → Finance operations: routes finance (evidence: `src/app.js`)
- Authentication → Sessions: creates sessions (evidence: `src/services/auth.service.js`)
- Phone authentication → Sessions: creates sessions (evidence: `src/services/phone-auth.service.js`)
- Phone authentication → Veevo SMS: sends SMS (evidence: `src/services/phone-auth.service.js`)
- Veevo SMS → SMS provider: sends messages
- Customer → Catalog discovery: discovers products
- Catalog discovery → Product search: supports search (evidence: `src/routes/catalog.routes.js`)
- Customer → Customer account: manages cart
- Customer → Order workflow: places COD order
- Order workflow → Vendor fulfillment: creates vendor orders
- Vendor → Vendor fulfillment: fulfills orders
- Vendor fulfillment → Dispatch and delivery: marks ready
- Dispatch and delivery → Rider operations: assigns rider
- Rider → Rider operations: updates delivery
- Rider operations → Returns: initiates returns
- Rider operations → Cash reconciliation: remits cash
- Finance staff → Cash reconciliation: records cash
- Cash reconciliation → Finance operations: enables settlement
- Finance staff → Finance operations: records settlements
- Administrator → Administration: manages platform
- Administrator → Marketing campaigns: manages campaigns
- Administrator → Support: manages support
- HTTP API → Notifications: serves notifications (evidence: `src/app.js`)
- HTTP API → Maps and location: serves maps (evidence: `src/app.js`)
- Order workflow → PostgreSQL: persists orders
- Finance operations → PostgreSQL: records finance (evidence: `src/services/finance.service.js`)
