# akramiot/orderbuddy architecture

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

- Interactive diagram: https://gitdiagram.com/akramiot/orderbuddy
- Repository: https://github.com/akramiot/orderbuddy

## Overview

1. **Repo shape**
   - This is a monorepo with three main TypeScript applications under `orderbuddy/src/` and one Python migration service under `orderbuddy/checkout-api/`.
   - The architectural center is the NestJS backend API; the two frontend apps split by audience: customer ordering vs restaurant staff/admin management.

2. **Backend API core**
   - `src/api` is the primary application server, built with **NestJS + TypeScript**.
   - It exposes domain modules for restaurants, menus, orders, stations, printers, campaigns, reports, payments, origins, locations/settings, users, storage, web push, email, and POS.
   - This layer is the main boundary for business logic and persistence access.

3. **Persistent domain model**
   - The backend is wired to **MongoDB** through explicit model files and collection definitions in `src/api/src/db`.
   - The model set includes restaurants, locations, menus, orders, campaigns, origins, and stations, which indicates the system is organized around restaurant/location-specific data rather than a single global catalog.
   - `mongo-index-initializer.ts` suggests startup-time schema/index management.

4. **Customer-facing order app**
   - `src/order` is the guest ordering app, built with **React/Vite/Ionic/Capacitor**.
   - Its flow is: entry/menu browsing → cart → checkout → status tracking, with separate pages for privacy/terms and error handling.
   - It talks to the backend through query/service wrappers for menu fetch, order creation, payment, and order-status reads.

5. **Checkout and payment boundary**
   - The order app contains payment-specific components for **Apple Pay**, **Google Pay**, and a Gravity payment form.
   - The checkout boundary is intentionally split: the UI collects cart and customer data, then delegates payment/order submission to backend APIs and payment-specific query hooks.
   - The separate `checkout-api` folder is a Python **FastAPI** service used for migration/testing around checkout concerns.

6. **FastAPI checkout migration service**
   - `orderbuddy/checkout-api` is a standalone **FastAPI** service with its own schemas, services, dependency wiring, tests, and OpenAPI tooling.
   - It includes checkout-specific logic such as pricing, payment gateway integration, and OpenAPI comparison/export scripts, indicating it is used to validate API compatibility during migration.
   - This service is intentionally isolated from the NestJS backend and operates as a smaller, focused checkout boundary.

7. **Manage/admin app**
   - `src/manage` is the operator-facing app, also built with **React/Vite/Ionic/Capacitor**, and includes Android packaging plus custom native plugins.
   - Its pages cover live orders, order history, menu management, restaurant/location settings, stations, origins, printers, POS, campaigns, and reporting.
   - This app is the operational control plane for restaurant staff, not just a CRUD UI.

8. **Real-time operations and hardware**
   - The manage app has hooks and query modules for sockets, dashboard updates, printer services, and notification sound playback.
   - The Android code includes a custom star-printer integration and notification/audio/native monitoring components, showing the app is designed for kiosk-like or tablet-based operational use.
   - The backend also has an `events` module, which likely feeds real-time order updates into the manage app.

9. **Notifications, email, and external integrations**
   - The backend contains dedicated modules for **email**, **web push**, **payments**, and **AI-related utilities**.
   - Email templates cover order confirmation, QR-code links, and welcome messages; web push and Firebase artifacts in the manage app indicate push notifications are part of the operational loop.
   - The AI module suggests auxiliary services such as translation and working-hours handling rather than core ordering logic.

10. **Auth, session, and tenant boundaries**
   - Authentication in the API is handled through a custom auth layer with **Supertokens**, guards, middleware, and restaurant/session decorators.
   - This implies authorization is scoped by restaurant/session context, which is important for multi-location or multi-tenant access control.
   - The frontend apps both consume this API boundary rather than embedding business rules locally.

11. **Observability and error handling**
   - Both frontend apps and the backend include **Application Insights / logging** support, plus structured error boundary utilities.
   - The manage app has explicit observability documentation and test utilities; the API has middleware and logger transport code.
   - This makes observability a first-class cross-cutting concern across deployment targets.

12. **Docs and deployment workflow**
   - The `docs/` tree acts as the architectural/specification layer: order flow, menu schema, infra naming, Azure infrastructure, and page specs are documented separately from code.
   - Deployment is pipeline-driven: there are Azure DevOps YAMLs for API/manage/order variants and a GitHub Actions workflow for the checkout API.
   - Static web app configs, Android Gradle files, and Capacitor configs show the repo targets both web and mobile-native deployment surfaces.

Main entry points: [`orderbuddy/src/api/src/app.module.ts`](https://github.com/akramiot/orderbuddy/blob/main/orderbuddy/src/api/src/app.module.ts) (API app), [`orderbuddy/src/api/src`](https://github.com/akramiot/orderbuddy/tree/main/orderbuddy/src/api/src) (Domain modules), [`.github/workflows/checkout-api-ci.yml`](https://github.com/akramiot/orderbuddy/blob/main/.github/workflows/checkout-api-ci.yml) (Pipelines), [`orderbuddy/src/manage/src/App.tsx`](https://github.com/akramiot/orderbuddy/blob/main/orderbuddy/src/manage/src/App.tsx) (Manage app)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_g_backend["Backend API"]
  node_n_api_app["API app<br/>NestJS server<br/>[app.module.ts]"]
  node_n_api_auth["Auth"]
  node_n_api_domain["Domain modules<br/>Business modules"]
  node_n_api_db[("Mongo models<br/>MongoDB persistence")]
  node_n_api_events["Events<br/>Realtime gateway"]
  node_n_api_integrations["Integrations<br/>Email push AI"]
end

subgraph group_g_order["Customer Order App"]
  node_n_order_app["Order app<br/>React/Ionic client<br/>[App.tsx]"]
  node_n_order_flow["Order flow<br/>Pages"]
  node_n_order_payments["Payments UI<br/>Checkout components"]
  node_n_order_queries["Order queries<br/>API hooks"]
end

subgraph group_g_manage["Manage App"]
  node_n_manage_app["Manage app<br/>React/Ionic client<br/>[App.tsx]"]
  node_n_manage_ops["Ops pages<br/>Operational UI"]
  node_n_manage_realtime["Realtime tools<br/>Sockets printer sound"]
  node_n_manage_native["Android bridge<br/>Capacitor plugin layer"]
end

subgraph group_g_checkout["Checkout Migration Service"]
  node_n_checkout_api["Checkout API<br/>FastAPI service<br/>[main.py]"]
  node_n_checkout_logic["Checkout logic<br/>Pricing gateway"]
  node_n_checkout_openapi["OpenAPI tools<br/>Spec compare tools"]
end

subgraph group_g_shared["Shared Ops"]
  node_n_docs["Docs<br/>Architecture specs"]
  node_n_ci["Pipelines<br/>CI/CD"]
end

node_n_api_app -->|"uses"| node_n_api_auth
node_n_api_app -->|"composes"| node_n_api_domain
node_n_api_domain -->|"persists"| node_n_api_db
node_n_api_domain -->|"publishes"| node_n_api_events
node_n_api_domain -->|"integrates"| node_n_api_integrations
node_n_order_app -->|"renders"| node_n_order_flow
node_n_order_flow -->|"fetches"| node_n_order_queries
node_n_order_flow -->|"collects"| node_n_order_payments
node_n_order_queries -->|"calls"| node_n_api_app
node_n_manage_app -->|"renders"| node_n_manage_ops
node_n_manage_app -->|"uses"| node_n_manage_realtime
node_n_manage_app -->|"bridges"| node_n_manage_native
node_n_manage_ops -->|"calls"| node_n_api_app
node_n_manage_realtime -->|"subscribes"| node_n_api_events
node_n_checkout_api -->|"implements"| node_n_checkout_logic
node_n_checkout_logic -->|"validated by"| node_n_checkout_openapi
node_n_checkout_api -.->|"mirrors"| node_n_api_app
node_n_docs -->|"describes"| node_n_api_domain
node_n_docs -->|"specs"| node_n_order_flow
node_n_docs -->|"guides"| node_n_manage_ops
node_n_ci -->|"deploys"| node_n_api_app
node_n_ci -->|"deploys"| node_n_manage_app
node_n_ci -->|"deploys"| node_n_order_app
node_n_ci -->|"tests"| node_n_checkout_api

click node_n_api_app "https://github.com/akramiot/orderbuddy/blob/main/orderbuddy/src/api/src/app.module.ts"
click node_n_api_auth "https://github.com/akramiot/orderbuddy/tree/main/orderbuddy/src/api/src/auth"
click node_n_api_domain "https://github.com/akramiot/orderbuddy/tree/main/orderbuddy/src/api/src"
click node_n_api_db "https://github.com/akramiot/orderbuddy/tree/main/orderbuddy/src/api/src/db"
click node_n_api_events "https://github.com/akramiot/orderbuddy/tree/main/orderbuddy/src/api/src/events"
click node_n_api_integrations "https://github.com/akramiot/orderbuddy/tree/main/orderbuddy/src/api/src"
click node_n_order_app "https://github.com/akramiot/orderbuddy/blob/main/orderbuddy/src/order/src/App.tsx"
click node_n_order_flow "https://github.com/akramiot/orderbuddy/tree/main/orderbuddy/src/order/src/pages"
click node_n_order_payments "https://github.com/akramiot/orderbuddy/tree/main/orderbuddy/src/order/src/components"
click node_n_order_queries "https://github.com/akramiot/orderbuddy/tree/main/orderbuddy/src/order/src/queries"
click node_n_manage_app "https://github.com/akramiot/orderbuddy/blob/main/orderbuddy/src/manage/src/App.tsx"
click node_n_manage_ops "https://github.com/akramiot/orderbuddy/tree/main/orderbuddy/src/manage/src/pages"
click node_n_manage_realtime "https://github.com/akramiot/orderbuddy/tree/main/orderbuddy/src/manage/src/queries"
click node_n_manage_native "https://github.com/akramiot/orderbuddy/tree/main/orderbuddy/src/manage/android/app/src/main/java/com/orderbuddy"
click node_n_checkout_api "https://github.com/akramiot/orderbuddy/blob/main/orderbuddy/checkout-api/app/main.py"
click node_n_checkout_logic "https://github.com/akramiot/orderbuddy/tree/main/orderbuddy/checkout-api/app/services"
click node_n_checkout_openapi "https://github.com/akramiot/orderbuddy/tree/main/orderbuddy/checkout-api/scripts"
click node_n_docs "https://github.com/akramiot/orderbuddy/tree/main/orderbuddy/docs"
click node_n_ci "https://github.com/akramiot/orderbuddy/blob/main/.github/workflows/checkout-api-ci.yml"

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_n_api_app,node_n_api_auth,node_n_api_domain,node_n_api_db,node_n_api_events,node_n_api_integrations toneBlue
class node_n_order_app,node_n_order_flow,node_n_order_payments,node_n_order_queries toneAmber
class node_n_manage_app,node_n_manage_ops,node_n_manage_realtime,node_n_manage_native toneMint
class node_n_checkout_api,node_n_checkout_logic,node_n_checkout_openapi toneRose
class node_n_docs,node_n_ci toneIndigo
```

## Components

### Backend API

NestJS business API, auth, data access, and integrations

- [API app](https://github.com/akramiot/orderbuddy/blob/main/orderbuddy/src/api/src/app.module.ts): NestJS server · Main business API entrypoint and module composition · `orderbuddy/src/api/src/app.module.ts`
- [Auth](https://github.com/akramiot/orderbuddy/tree/main/orderbuddy/src/api/src/auth): Supertokens auth · Guards, middleware, decorators, and session scoping · `orderbuddy/src/api/src/auth`
- [Domain modules](https://github.com/akramiot/orderbuddy/tree/main/orderbuddy/src/api/src): Business modules · Restaurants, menus, orders, stations, printers, campaigns, reports, payments, origins, locations, users, storage, web push, email, POS · `orderbuddy/src/api/src`
- [Mongo models](https://github.com/akramiot/orderbuddy/tree/main/orderbuddy/src/api/src/db): MongoDB persistence · Collections, models, and index initialization for restaurant-scoped data · `orderbuddy/src/api/src/db`
- [Events](https://github.com/akramiot/orderbuddy/tree/main/orderbuddy/src/api/src/events): Realtime gateway · Socket and event delivery for operational updates · `orderbuddy/src/api/src/events`
- [Integrations](https://github.com/akramiot/orderbuddy/tree/main/orderbuddy/src/api/src): Email push AI · Email templates, web push, payments, and AI utilities · `orderbuddy/src/api/src`

### Customer Order App

Guest-facing ordering client and checkout flow

- [Order app](https://github.com/akramiot/orderbuddy/blob/main/orderbuddy/src/order/src/App.tsx): React/Ionic client · Guest-facing ordering application shell · `orderbuddy/src/order/src/App.tsx`
- [Order flow](https://github.com/akramiot/orderbuddy/tree/main/orderbuddy/src/order/src/pages): Pages · Entry, menu, cart, checkout, status, privacy, terms, and error pages · `orderbuddy/src/order/src/pages`
- [Payments UI](https://github.com/akramiot/orderbuddy/tree/main/orderbuddy/src/order/src/components): Checkout components · Apple Pay, Google Pay, and Gravity payment form boundary · `orderbuddy/src/order/src/components`
- [Order queries](https://github.com/akramiot/orderbuddy/tree/main/orderbuddy/src/order/src/queries): API hooks · Menu fetch, order creation, payment submission, and order-status reads · `orderbuddy/src/order/src/queries`

### Manage App

Restaurant staff control plane for operations and administration

- [Manage app](https://github.com/akramiot/orderbuddy/blob/main/orderbuddy/src/manage/src/App.tsx): React/Ionic client · Restaurant staff control plane shell · `orderbuddy/src/manage/src/App.tsx`
- [Ops pages](https://github.com/akramiot/orderbuddy/tree/main/orderbuddy/src/manage/src/pages): Operational UI · Live orders, history, menu, restaurant, location, station, origin, printer, POS, campaign, and reports pages · `orderbuddy/src/manage/src/pages`
- [Realtime tools](https://github.com/akramiot/orderbuddy/tree/main/orderbuddy/src/manage/src/queries): Sockets printer sound · Socket hooks, dashboard updates, notification sound, and printer services · `orderbuddy/src/manage/src/queries`
- [Android bridge](https://github.com/akramiot/orderbuddy/tree/main/orderbuddy/src/manage/android/app/src/main/java/com/orderbuddy): Capacitor plugin layer · Custom Android monitor, printer, and notification components · `orderbuddy/src/manage/android/app/src/main/java/com/orderbuddy`

### Checkout Migration Service

Standalone FastAPI checkout boundary used for migration and compatibility checks

- [Checkout API](https://github.com/akramiot/orderbuddy/blob/main/orderbuddy/checkout-api/app/main.py): FastAPI service · Standalone Python checkout service for migration and compatibility validation · `orderbuddy/checkout-api/app/main.py`
- [Checkout logic](https://github.com/akramiot/orderbuddy/tree/main/orderbuddy/checkout-api/app/services): Pricing gateway · Checkout schemas, pricing, payment gateway integration, and service orchestration · `orderbuddy/checkout-api/app/services`
- [OpenAPI tools](https://github.com/akramiot/orderbuddy/tree/main/orderbuddy/checkout-api/scripts): Spec compare tools · Export, fetch, and compare OpenAPI specs during migration · `orderbuddy/checkout-api/scripts`

### Shared Ops

Docs, deployment, and cross-cutting support

- [Docs](https://github.com/akramiot/orderbuddy/tree/main/orderbuddy/docs): Architecture specs · Order flow, menu schema, infra, observability, and page specifications · `orderbuddy/docs`
- [Pipelines](https://github.com/akramiot/orderbuddy/blob/main/.github/workflows/checkout-api-ci.yml): CI/CD · Azure DevOps deployment YAMLs and GitHub Actions workflow · `.github/workflows/checkout-api-ci.yml`

## Connections

- API app → Auth: uses · Application wiring depends on auth and session boundaries
- API app → Domain modules: composes · Main server is assembled from domain modules
- Domain modules → Mongo models: persists · Domain modules read and write Mongo-backed models
- Domain modules → Events: publishes · Operational changes flow through realtime events
- Domain modules → Integrations: integrates · Business logic triggers messaging, push, payment, and AI helpers
- Order app → Order flow: renders · Guest app is organized around the ordering journey
- Order flow → Order queries: fetches · Pages call API hooks for menu, checkout, and status data
- Order flow → Payments UI: collects · Checkout page embeds payment-specific UI controls
- Order queries → API app: calls · Guest app communicates with the backend API
- Manage app → Ops pages: renders · Staff app centers on operational screens
- Manage app → Realtime tools: uses · App consumes sockets, printer, and sound hooks
- Manage app → Android bridge: bridges · Android packaging exposes custom native capabilities
- Ops pages → API app: calls · Operator workflows are backed by the API
- Realtime tools → Events: subscribes · Dashboard and order views rely on event-driven updates
- Checkout API → Checkout logic: implements · FastAPI service is built from checkout services and schemas
- Checkout logic → OpenAPI tools: validated by · Migration workflow compares exported and fetched API specs
- Checkout API → API app: mirrors · Standalone service tracks compatibility with the main backend boundary
- Docs → Domain modules: describes · Docs capture API, menu, order flow, and infrastructure contracts
- Docs → Order flow: specs · Order app page specs define the guest experience
- Docs → Ops pages: guides · Manage app documentation covers logging and observability
- Pipelines → API app: deploys · Pipeline variants target the API environment slices
- Pipelines → Manage app: deploys · Pipeline variants target the manage application
- Pipelines → Order app: deploys · Pipeline variants target the order application
- Pipelines → Checkout API: tests · GitHub Actions workflow validates the checkout service
