# allanboyd/24hr-onechain-app architecture

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

- Interactive diagram: https://gitdiagram.com/allanboyd/24hr-onechain-app
- Repository: https://github.com/allanboyd/24hr-onechain-app

## Overview

BTW Supply Chain Platform supports office workflows, field loading/driver/receiver work, and an office-role phone PWA. Users sign in, work within role and company scopes, then manage plans and purchase orders, record loading and shipment events, and follow stock, money, and reports. The README documents both real-API and in-browser-mock modes. The graph preserves those product branches; several domain services and UI areas are represented by their exact source directories because their implementation was not excerpted.

Main entry points: [`apps/api/src/http/controllers.ts`](https://github.com/allanboyd/24hr-onechain-app/blob/main/apps/api/src/http/controllers.ts) (HTTP controllers), [`apps/api/src/db/client.ts`](https://github.com/allanboyd/24hr-onechain-app/blob/main/apps/api/src/db/client.ts) (PostgreSQL data), [`apps/api/src/integrations`](https://github.com/allanboyd/24hr-onechain-app/tree/main/apps/api/src/integrations) (External integrations), [`apps/api/src/domain/logistics.service.ts`](https://github.com/allanboyd/24hr-onechain-app/blob/main/apps/api/src/domain/logistics.service.ts) (Loading and shipments)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_clients["User applications"]
  node_office["Office web app"]
  node_field["Field and team app"]
end

subgraph group_shared["Shared client logic"]
  node_api_client["API client<br/>[client.ts]"]
  node_mock["Mock client<br/>[mock-client.ts]"]
  node_rules["Shared rules<br/>[rules.ts]"]
  node_reports_client["Report functions<br/>[reports.ts]"]
  node_dashboards_client["Dashboard definitions<br/>[dashboards.ts]"]
end

subgraph group_workflow["Supply workflows"]
  node_companies["Company master data<br/>[companies.ts]"]
  node_planning["Plans and purchase orders"]
  node_logistics["Loading and shipments"]
  node_stock["Stock and re-exports<br/>[stock.service.ts]"]
end

subgraph group_insight["Money and insight"]
  node_finance["Finance and money<br/>[finance.service.ts]"]
  node_reports["Reports and performance<br/>[reports.service.ts]"]
  node_dashboards["Dashboard service"]
end

subgraph group_platform["API platform"]
  node_auth["Authentication and scopes"]
  node_http["HTTP controllers<br/>[controllers.ts]"]
  node_db[("PostgreSQL data<br/>[client.ts]")]
  node_integrations["External integrations"]
end

node_web_user(("Office user"))
node_field_user(("Field user"))
node_sms["SMS and USSD providers"]
node_pdf["PDF generation"]
node_routing["Route service"]

node_web_user -->|"uses"| node_office
node_field_user -->|"uses"| node_field
node_office -->|"imports client"| node_api_client
node_field -->|"imports client"| node_api_client
node_api_client -->|"selects mock"| node_mock
node_api_client -.->|"calls real API"| node_http
node_mock -->|"applies rules"| node_rules
node_mock -->|"uses reports"| node_reports_client
node_mock -->|"uses dashboards"| node_dashboards_client
node_office -.->|"signs in"| node_auth
node_field -->|"signs in"| node_auth
node_http -->|"authenticates requests"| node_auth
node_http -.->|"routes planning"| node_planning
node_http -->|"calls logistics"| node_logistics
node_http -->|"routes money"| node_finance
node_http -->|"routes dashboards"| node_dashboards
node_http -->|"seeds data"| node_db
node_planning -->|"reads and writes"| node_db
node_logistics -->|"reads and writes"| node_db
node_logistics -->|"uses company data"| node_companies
node_logistics -->|"uses integration ports"| node_integrations
node_integrations -.->|"sends messages"| node_sms
node_integrations -.->|"renders documents"| node_pdf
node_integrations -->|"requests routes"| node_routing
node_integrations -.->|"handles check-ins"| node_logistics
node_stock -.->|"reads and writes"| node_db
node_finance -.->|"reads and writes"| node_db
node_reports -.->|"queries scoped data"| node_db
node_dashboards -.->|"queries dashboard data"| node_db

click node_office "https://github.com/allanboyd/24hr-onechain-app/tree/main/apps/web/src"
click node_field "https://github.com/allanboyd/24hr-onechain-app/tree/main/apps/field/src"
click node_api_client "https://github.com/allanboyd/24hr-onechain-app/blob/main/packages/api/src/client.ts"
click node_mock "https://github.com/allanboyd/24hr-onechain-app/blob/main/packages/api/src/mock-client.ts"
click node_rules "https://github.com/allanboyd/24hr-onechain-app/blob/main/packages/api/src/rules.ts"
click node_reports_client "https://github.com/allanboyd/24hr-onechain-app/blob/main/packages/api/src/reports.ts"
click node_dashboards_client "https://github.com/allanboyd/24hr-onechain-app/blob/main/packages/api/src/dashboards.ts"
click node_auth "https://github.com/allanboyd/24hr-onechain-app/tree/main/apps/api/src/auth"
click node_http "https://github.com/allanboyd/24hr-onechain-app/blob/main/apps/api/src/http/controllers.ts"
click node_db "https://github.com/allanboyd/24hr-onechain-app/blob/main/apps/api/src/db/client.ts"
click node_companies "https://github.com/allanboyd/24hr-onechain-app/blob/main/apps/api/src/domain/companies.ts"
click node_planning "https://github.com/allanboyd/24hr-onechain-app/blob/main/apps/api/src/domain/planning.service.ts"
click node_logistics "https://github.com/allanboyd/24hr-onechain-app/blob/main/apps/api/src/domain/logistics.service.ts"
click node_stock "https://github.com/allanboyd/24hr-onechain-app/blob/main/apps/api/src/domain/stock.service.ts"
click node_finance "https://github.com/allanboyd/24hr-onechain-app/blob/main/apps/api/src/domain/finance.service.ts"
click node_reports "https://github.com/allanboyd/24hr-onechain-app/blob/main/apps/api/src/domain/reports.service.ts"
click node_dashboards "https://github.com/allanboyd/24hr-onechain-app/blob/main/apps/api/src/domain/dashboards.service.ts"
click node_integrations "https://github.com/allanboyd/24hr-onechain-app/tree/main/apps/api/src/integrations"

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_office,node_field,node_web_user,node_field_user toneBlue
class node_api_client,node_mock,node_rules,node_reports_client,node_dashboards_client toneAmber
class node_companies,node_planning,node_logistics,node_stock,node_routing toneMint
class node_finance,node_reports,node_dashboards toneRose
class node_auth,node_http,node_db,node_integrations,node_sms,node_pdf toneIndigo
```

## Components

### User applications

- [Office web app](https://github.com/allanboyd/24hr-onechain-app/tree/main/apps/web/src): `apps/web/src`
- [Field and team app](https://github.com/allanboyd/24hr-onechain-app/tree/main/apps/field/src): `apps/field/src`

### Shared client logic

- [API client](https://github.com/allanboyd/24hr-onechain-app/blob/main/packages/api/src/client.ts): `packages/api/src/client.ts`
- [Mock client](https://github.com/allanboyd/24hr-onechain-app/blob/main/packages/api/src/mock-client.ts): `packages/api/src/mock-client.ts`
- [Shared rules](https://github.com/allanboyd/24hr-onechain-app/blob/main/packages/api/src/rules.ts): `packages/api/src/rules.ts`
- [Report functions](https://github.com/allanboyd/24hr-onechain-app/blob/main/packages/api/src/reports.ts): `packages/api/src/reports.ts`
- [Dashboard definitions](https://github.com/allanboyd/24hr-onechain-app/blob/main/packages/api/src/dashboards.ts): `packages/api/src/dashboards.ts`

### Supply workflows

- [Company master data](https://github.com/allanboyd/24hr-onechain-app/blob/main/apps/api/src/domain/companies.ts): `apps/api/src/domain/companies.ts`
- [Plans and purchase orders](https://github.com/allanboyd/24hr-onechain-app/blob/main/apps/api/src/domain/planning.service.ts): `apps/api/src/domain/planning.service.ts`
- [Loading and shipments](https://github.com/allanboyd/24hr-onechain-app/blob/main/apps/api/src/domain/logistics.service.ts): `apps/api/src/domain/logistics.service.ts`
- [Stock and re-exports](https://github.com/allanboyd/24hr-onechain-app/blob/main/apps/api/src/domain/stock.service.ts): `apps/api/src/domain/stock.service.ts`

### Money and insight

- [Finance and money](https://github.com/allanboyd/24hr-onechain-app/blob/main/apps/api/src/domain/finance.service.ts): `apps/api/src/domain/finance.service.ts`
- [Reports and performance](https://github.com/allanboyd/24hr-onechain-app/blob/main/apps/api/src/domain/reports.service.ts): `apps/api/src/domain/reports.service.ts`
- [Dashboard service](https://github.com/allanboyd/24hr-onechain-app/blob/main/apps/api/src/domain/dashboards.service.ts): `apps/api/src/domain/dashboards.service.ts`

### API platform

- [Authentication and scopes](https://github.com/allanboyd/24hr-onechain-app/tree/main/apps/api/src/auth): `apps/api/src/auth`
- [HTTP controllers](https://github.com/allanboyd/24hr-onechain-app/blob/main/apps/api/src/http/controllers.ts): `apps/api/src/http/controllers.ts`
- [PostgreSQL data](https://github.com/allanboyd/24hr-onechain-app/blob/main/apps/api/src/db/client.ts): `apps/api/src/db/client.ts`
- [External integrations](https://github.com/allanboyd/24hr-onechain-app/tree/main/apps/api/src/integrations): `apps/api/src/integrations`

### Other components

- **Office user**
- **Field user**
- **SMS and USSD providers**
- **PDF generation**
- **Route service**

## Connections

- Office user → Office web app: uses (evidence: `README.md`)
- Field user → Field and team app: uses (evidence: `README.md`)
- Office web app → API client: imports client (evidence: `README.md`)
- Field and team app → API client: imports client (evidence: `apps/field/src/App.svelte`)
- API client → Mock client: selects mock (evidence: `packages/api/src/client.ts`)
- API client → HTTP controllers: calls real API (evidence: `README.md`)
- Mock client → Shared rules: applies rules (evidence: `packages/api/src/mock-client.ts`)
- Mock client → Report functions: uses reports (evidence: `packages/api/src/mock-client.ts`)
- Mock client → Dashboard definitions: uses dashboards (evidence: `packages/api/src/mock-client.ts`)
- Office web app → Authentication and scopes: signs in (evidence: `README.md`)
- Field and team app → Authentication and scopes: signs in (evidence: `apps/field/src/App.svelte`)
- HTTP controllers → Authentication and scopes: authenticates requests (evidence: `apps/api/src/http/controllers.ts`)
- HTTP controllers → Plans and purchase orders: routes planning (evidence: `apps/api/src/http/controllers.ts`)
- HTTP controllers → Loading and shipments: calls logistics (evidence: `apps/api/src/http/controllers.ts`)
- HTTP controllers → Finance and money: routes money (evidence: `apps/api/src/http/controllers.ts`)
- HTTP controllers → Dashboard service: routes dashboards
- HTTP controllers → PostgreSQL data: seeds data (evidence: `apps/api/src/http/controllers.ts`)
- Plans and purchase orders → PostgreSQL data: reads and writes (evidence: `apps/api/src/domain/planning.service.ts`)
- Loading and shipments → PostgreSQL data: reads and writes (evidence: `apps/api/src/domain/logistics.service.ts`)
- Loading and shipments → Company master data: uses company data (evidence: `apps/api/src/domain/logistics.service.ts`)
- Loading and shipments → External integrations: uses integration ports (evidence: `apps/api/src/domain/logistics.service.ts`)
- External integrations → SMS and USSD providers: sends messages (evidence: `apps/api/src/integrations/ports.ts`)
- External integrations → PDF generation: renders documents (evidence: `apps/api/src/integrations/controllers.ts`)
- External integrations → Route service: requests routes (evidence: `apps/api/src/integrations/controllers.ts`)
- External integrations → Loading and shipments: handles check-ins (evidence: `apps/api/src/integrations/ports.ts`)
- Stock and re-exports → PostgreSQL data: reads and writes
- Finance and money → PostgreSQL data: reads and writes
- Reports and performance → PostgreSQL data: queries scoped data
- Dashboard service → PostgreSQL data: queries dashboard data
