# siwarattia6191/smart-delivery-ops architecture

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

- Interactive diagram: https://gitdiagram.com/siwarattia6191/smart-delivery-ops
- Repository: https://github.com/siwarattia6191/smart-delivery-ops

## Overview

Smart Delivery Ops is a multi-tenant food-delivery operations platform with an API-driven order-to-delivery workflow and an AI operations copilot. A customer submits an order; the backend resolves delivery location, prices it, matches a driver, estimates ETA, and records lifecycle events. Payments, reviews, restaurant operations, bulk onboarding, analytics, forecasting, and event export form related product branches. The graph reflects documented capabilities and sampled source references; some route-to-service wiring and unsampled subsystems are documented only at the product level, so those relationships cite the README rather than implying source inspection.

Main entry points: [`apps/api/main.py`](https://github.com/siwarattia6191/smart-delivery-ops/blob/main/apps/api/main.py) (Operations API), [`domain/services/order_service.py`](https://github.com/siwarattia6191/smart-delivery-ops/blob/main/domain/services/order_service.py) (Order lifecycle), [`core/database.py`](https://github.com/siwarattia6191/smart-delivery-ops/blob/main/core/database.py) (Tenant data store), [`apps/copilot/graph.py`](https://github.com/siwarattia6191/smart-delivery-ops/blob/main/apps/copilot/graph.py) (Copilot agent)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_operations["Delivery operations"]
  node_orders["Order lifecycle<br/>[order_service.py]"]
  node_geo["Address and routing<br/>[geocoder.py]"]
  node_distance["Distance rules<br/>[geo.py]"]
  node_pricing["Pricing and coupons<br/>[pricing_service.py]"]
  node_dispatch["Driver matching"]
  node_eta["ETA estimation"]
  node_payments["Payment settlement<br/>[payment_service.py]"]
  node_restaurant["Restaurant and menu<br/>[restaurants.py]"]
  node_reviews["Order reviews<br/>[review_service.py]"]
end

subgraph group_platform["API and tenancy"]
  node_api["Operations API<br/>[main.py]"]
  node_auth["Auth and tenant scope"]
  node_tenant["Tenant services<br/>[tenant_service.py]"]
  node_database[("Tenant data store<br/>[database.py]")]
end

subgraph group_copilot["AI copilot"]
  node_copilot_api["Copilot endpoint<br/>[copilot.py]"]
  node_agent["Copilot agent<br/>[graph.py]"]
  node_tools["Read-only tools<br/>[tools.py]"]
  node_retrieval["RAG retrieval<br/>[retriever.py]"]
  node_knowledge["Knowledge ingestion<br/>[knowledge.py]"]
end

subgraph group_data["Data and intelligence"]
  node_relay["Event relay<br/>[relay.py]"]
  node_warehouse["Analytics warehouse"]
  node_analytics["Operational analytics<br/>[analytics.py]"]
  node_forecast["Demand forecasting<br/>[forecast_demand.py]"]
end

subgraph group_onboarding["Restaurant onboarding"]
  node_import["Bulk import<br/>[import_service.py]"]
  node_onboarding["Onboarding wizard<br/>[onboarding.py]"]
end

node_customer(("Customer"))
node_kafka["Kafka"]
node_mlflow["MLflow registry"]
node_ops_user(("Operations user"))

node_customer -->|"places order"| node_api
node_api -->|"scopes requests"| node_auth
node_auth -->|"sets tenant context"| node_tenant
node_api -.->|"handles lifecycle"| node_orders
node_orders -->|"resolves address"| node_geo
node_orders -->|"quotes delivery"| node_pricing
node_orders -->|"matches driver"| node_dispatch
node_orders -->|"estimates arrival"| node_eta
node_geo -->|"checks road distance"| node_distance
node_orders -->|"stores lifecycle"| node_database
node_api -.->|"settles payment"| node_payments
node_api -.->|"serves restaurant portal"| node_restaurant
node_api -.->|"accepts ratings"| node_reviews
node_reviews -->|"reads and writes"| node_database
node_orders -.->|"publishes events"| node_kafka
node_relay -.->|"relays outbox events"| node_kafka
node_kafka -.->|"feeds raw layer"| node_warehouse
node_api -->|"serves KPI queries"| node_analytics
node_warehouse -.->|"provides analytics data"| node_analytics
node_forecast -.->|"stores forecasts"| node_database
node_mlflow -->|"serves registered model"| node_eta
node_ops_user -->|"asks question"| node_copilot_api
node_copilot_api -.->|"runs supervisor"| node_agent
node_agent -.->|"dispatches tools"| node_tools
node_agent -.->|"retrieves knowledge"| node_retrieval
node_knowledge -.->|"stores tenant documents"| node_database
node_api -.->|"imports client data"| node_import
node_onboarding -.->|"submits setup"| node_api
node_import -->|"geocodes addresses"| node_geo

click node_api "https://github.com/siwarattia6191/smart-delivery-ops/blob/main/apps/api/main.py"
click node_auth "https://github.com/siwarattia6191/smart-delivery-ops/blob/main/apps/api/tenancy_middleware.py"
click node_tenant "https://github.com/siwarattia6191/smart-delivery-ops/blob/main/domain/services/tenant_service.py"
click node_orders "https://github.com/siwarattia6191/smart-delivery-ops/blob/main/domain/services/order_service.py"
click node_geo "https://github.com/siwarattia6191/smart-delivery-ops/blob/main/domain/services/geocoder.py"
click node_distance "https://github.com/siwarattia6191/smart-delivery-ops/blob/main/domain/rules/geo.py"
click node_pricing "https://github.com/siwarattia6191/smart-delivery-ops/blob/main/domain/services/pricing_service.py"
click node_dispatch "https://github.com/siwarattia6191/smart-delivery-ops/blob/main/domain/services/driver_matching_service.py"
click node_eta "https://github.com/siwarattia6191/smart-delivery-ops/blob/main/domain/services/eta_model_service.py"
click node_payments "https://github.com/siwarattia6191/smart-delivery-ops/blob/main/domain/services/payment_service.py"
click node_restaurant "https://github.com/siwarattia6191/smart-delivery-ops/blob/main/apps/api/routes/restaurants.py"
click node_reviews "https://github.com/siwarattia6191/smart-delivery-ops/blob/main/domain/services/review_service.py"
click node_database "https://github.com/siwarattia6191/smart-delivery-ops/blob/main/core/database.py"
click node_relay "https://github.com/siwarattia6191/smart-delivery-ops/blob/main/apps/worker/relay.py"
click node_warehouse "https://github.com/siwarattia6191/smart-delivery-ops/blob/main/dags/warehouse_daily_build.py"
click node_analytics "https://github.com/siwarattia6191/smart-delivery-ops/blob/main/apps/api/routes/analytics.py"
click node_forecast "https://github.com/siwarattia6191/smart-delivery-ops/blob/main/ml/pipelines/forecast_demand.py"
click node_copilot_api "https://github.com/siwarattia6191/smart-delivery-ops/blob/main/apps/api/routes/copilot.py"
click node_agent "https://github.com/siwarattia6191/smart-delivery-ops/blob/main/apps/copilot/graph.py"
click node_tools "https://github.com/siwarattia6191/smart-delivery-ops/blob/main/apps/copilot/tools.py"
click node_retrieval "https://github.com/siwarattia6191/smart-delivery-ops/blob/main/apps/copilot/retriever.py"
click node_knowledge "https://github.com/siwarattia6191/smart-delivery-ops/blob/main/apps/api/routes/knowledge.py"
click node_import "https://github.com/siwarattia6191/smart-delivery-ops/blob/main/domain/services/import_service.py"
click node_onboarding "https://github.com/siwarattia6191/smart-delivery-ops/blob/main/apps/api/routes/onboarding.py"

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_orders,node_geo,node_distance,node_pricing,node_dispatch,node_eta,node_payments,node_restaurant,node_reviews,node_ops_user toneBlue
class node_api,node_auth,node_tenant,node_database toneAmber
class node_copilot_api,node_agent,node_tools,node_retrieval,node_knowledge toneMint
class node_relay,node_warehouse,node_analytics,node_forecast toneRose
class node_import,node_onboarding,node_customer,node_kafka,node_mlflow toneIndigo
```

## Components

### Delivery operations

- [Order lifecycle](https://github.com/siwarattia6191/smart-delivery-ops/blob/main/domain/services/order_service.py): `domain/services/order_service.py`
- [Address and routing](https://github.com/siwarattia6191/smart-delivery-ops/blob/main/domain/services/geocoder.py): `domain/services/geocoder.py`
- [Distance rules](https://github.com/siwarattia6191/smart-delivery-ops/blob/main/domain/rules/geo.py): `domain/rules/geo.py`
- [Pricing and coupons](https://github.com/siwarattia6191/smart-delivery-ops/blob/main/domain/services/pricing_service.py): `domain/services/pricing_service.py`
- [Driver matching](https://github.com/siwarattia6191/smart-delivery-ops/blob/main/domain/services/driver_matching_service.py): `domain/services/driver_matching_service.py`
- [ETA estimation](https://github.com/siwarattia6191/smart-delivery-ops/blob/main/domain/services/eta_model_service.py): `domain/services/eta_model_service.py`
- [Payment settlement](https://github.com/siwarattia6191/smart-delivery-ops/blob/main/domain/services/payment_service.py): `domain/services/payment_service.py`
- [Restaurant and menu](https://github.com/siwarattia6191/smart-delivery-ops/blob/main/apps/api/routes/restaurants.py): `apps/api/routes/restaurants.py`
- [Order reviews](https://github.com/siwarattia6191/smart-delivery-ops/blob/main/domain/services/review_service.py): `domain/services/review_service.py`

### API and tenancy

- [Operations API](https://github.com/siwarattia6191/smart-delivery-ops/blob/main/apps/api/main.py): `apps/api/main.py`
- [Auth and tenant scope](https://github.com/siwarattia6191/smart-delivery-ops/blob/main/apps/api/tenancy_middleware.py): `apps/api/tenancy_middleware.py`
- [Tenant services](https://github.com/siwarattia6191/smart-delivery-ops/blob/main/domain/services/tenant_service.py): `domain/services/tenant_service.py`
- [Tenant data store](https://github.com/siwarattia6191/smart-delivery-ops/blob/main/core/database.py): `core/database.py`

### AI copilot

- [Copilot endpoint](https://github.com/siwarattia6191/smart-delivery-ops/blob/main/apps/api/routes/copilot.py): `apps/api/routes/copilot.py`
- [Copilot agent](https://github.com/siwarattia6191/smart-delivery-ops/blob/main/apps/copilot/graph.py): `apps/copilot/graph.py`
- [Read-only tools](https://github.com/siwarattia6191/smart-delivery-ops/blob/main/apps/copilot/tools.py): `apps/copilot/tools.py`
- [RAG retrieval](https://github.com/siwarattia6191/smart-delivery-ops/blob/main/apps/copilot/retriever.py): `apps/copilot/retriever.py`
- [Knowledge ingestion](https://github.com/siwarattia6191/smart-delivery-ops/blob/main/apps/api/routes/knowledge.py): `apps/api/routes/knowledge.py`

### Data and intelligence

- [Event relay](https://github.com/siwarattia6191/smart-delivery-ops/blob/main/apps/worker/relay.py): `apps/worker/relay.py`
- [Analytics warehouse](https://github.com/siwarattia6191/smart-delivery-ops/blob/main/dags/warehouse_daily_build.py): `dags/warehouse_daily_build.py`
- [Operational analytics](https://github.com/siwarattia6191/smart-delivery-ops/blob/main/apps/api/routes/analytics.py): `apps/api/routes/analytics.py`
- [Demand forecasting](https://github.com/siwarattia6191/smart-delivery-ops/blob/main/ml/pipelines/forecast_demand.py): `ml/pipelines/forecast_demand.py`

### Restaurant onboarding

- [Bulk import](https://github.com/siwarattia6191/smart-delivery-ops/blob/main/domain/services/import_service.py): `domain/services/import_service.py`
- [Onboarding wizard](https://github.com/siwarattia6191/smart-delivery-ops/blob/main/apps/api/routes/onboarding.py): `apps/api/routes/onboarding.py`

### Other components

- **Customer**
- **Kafka**
- **MLflow registry**
- **Operations user**

## Connections

- Customer → Operations API: places order
- Operations API → Auth and tenant scope: scopes requests (evidence: `apps/api/main.py`)
- Auth and tenant scope → Tenant services: sets tenant context (evidence: `domain/services/tenant_service.py`)
- Operations API → Order lifecycle: handles lifecycle
- Order lifecycle → Address and routing: resolves address (evidence: `domain/services/order_service.py`)
- Order lifecycle → Pricing and coupons: quotes delivery (evidence: `domain/services/order_service.py`)
- Order lifecycle → Driver matching: matches driver (evidence: `domain/services/order_service.py`)
- Order lifecycle → ETA estimation: estimates arrival (evidence: `domain/services/order_service.py`)
- Address and routing → Distance rules: checks road distance
- Order lifecycle → Tenant data store: stores lifecycle (evidence: `domain/services/order_service.py`)
- Operations API → Payment settlement: settles payment
- Operations API → Restaurant and menu: serves restaurant portal (evidence: `apps/api/main.py`)
- Operations API → Order reviews: accepts ratings
- Order reviews → Tenant data store: reads and writes (evidence: `domain/services/review_service.py`)
- Order lifecycle → Kafka: publishes events
- Event relay → Kafka: relays outbox events
- Kafka → Analytics warehouse: feeds raw layer
- Operations API → Operational analytics: serves KPI queries (evidence: `apps/api/main.py`)
- Analytics warehouse → Operational analytics: provides analytics data
- Demand forecasting → Tenant data store: stores forecasts
- MLflow registry → ETA estimation: serves registered model (evidence: `domain/services/eta_model_service.py`)
- Operations user → Copilot endpoint: asks question
- Copilot endpoint → Copilot agent: runs supervisor
- Copilot agent → Read-only tools: dispatches tools
- Copilot agent → RAG retrieval: retrieves knowledge
- Knowledge ingestion → Tenant data store: stores tenant documents
- Operations API → Bulk import: imports client data
- Onboarding wizard → Operations API: submits setup (evidence: `apps/api/main.py`)
- Bulk import → Address and routing: geocodes addresses (evidence: `domain/services/import_service.py`)
