# shashankcm95/aadi architecture

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

- Interactive diagram: https://gitdiagram.com/shashankcm95/aadi
- Repository: https://github.com/shashankcm95/aadi

## Overview

1. **Overall shape**
   - Arrive is a **multi-client, AWS-backed monorepo** with three user-facing apps and four backend Lambda services.
   - The architecture is centered on **order timing and kitchen capacity**, not on a traditional request/response CRUD model.

2. **Client tier**
   - **Customer Mobile iOS app** (`packages/mobile-ios`) is the primary operational client; it handles browsing, cart, favorites, order history, login, and location-based behavior.
   - **Customer Web** (`packages/customer-web`) provides a browser-based ordering experience with similar API dependencies.
   - **Admin Portal** (`packages/admin-portal`) is the operations console for restaurants, capacity settings, menu ingestion, POS settings, and dashboard-style monitoring.

3. **Backend service boundary**
   - The backend is split into purpose-specific services under `services/`:
     - **orders**: core order lifecycle and dispatch orchestration
     - **restaurants**: restaurant catalog, menus, favorites, images, and geofence-related maintenance
     - **users**: user/profile management
     - **pos-integration**: adapter layer for POS connectivity
   - Each service has its own Lambda entrypoint, tests, and SAM template, so the deployment and runtime boundary is service-level rather than a single shared API.

4. **Orders service as the orchestration core**
   - `services/orders` is the main workflow engine for the product.
   - It receives order-related API requests and location-triggered events, evaluates capacity, and moves orders through states such as waiting, reserved, and sent to kitchen.
   - Supporting modules like `capacity.py`, `engine.py`, `expire_orders.py`, and `geofence_events.py` show that it is responsible for **state transitions, retry/expiry behavior, and event-driven dispatch**.

5. **Geofencing and just-in-time dispatch**
   - The mobile app tracks location and triggers geofence logic through **AWS Location Service**.
   - Those geofence events flow through **EventBridge** into the orders service, which decides whether the order is close enough to dispatch.
   - This is the key product-specific boundary: location events are not just telemetry; they directly influence order release timing.

6. **Capacity and consistency model**
   - The repository emphasizes **pessimistic capacity control** using DynamoDB conditional writes.
   - This means the system treats kitchen capacity as a concurrent shared resource and uses the orders service to serialize access to it.
   - The architecture therefore depends on DynamoDB not just for storage, but also for **coordination and locking semantics**.

7. **Restaurants service responsibilities**
   - `services/restaurants` manages restaurant-facing data: restaurant records, menu content, image assets, configuration, and customer favorites.
   - The presence of `geofence_resync_worker.py` suggests it also maintains alignment between restaurant records and geofence/location state.
   - This service is the source of truth for restaurant discovery and menu presentation across clients.

8. **Users service responsibilities**
   - `services/users` is a smaller boundary focused on user records and user-related API behavior.
   - It is distinct from authentication itself; auth appears to be handled upstream by Cognito and shared auth helpers, while this service manages application-level user data.

9. **POS integration as an external adapter**
   - `services/pos-integration` is an integration boundary rather than a core domain service.
   - Its `auth.py` and `pos_mapper.py` indicate it translates between Arrive’s internal model and an external POS interface.
   - This service isolates vendor-specific or webhook-specific logic away from the main order flow.

10. **Shared cross-cutting layer**
    - `services/shared/python/shared` contains reusable Lambda-layer code for **auth, CORS, serialization, and logging**.
    - These utilities are imported by multiple services, which keeps the service implementations focused on domain logic while standardizing API behavior and observability.

11. **Data and platform services**
    - **DynamoDB** is the primary persistence layer across services.
    - **Cognito** provides authentication for API access.
    - **API Gateway** fronts the service Lambdas for the web and mobile clients.
    - **CloudWatch** is used for observability, including dashboards and monitoring scripts in infrastructure tooling.

12. **Infrastructure and delivery**
    - Infrastructure is defined with **AWS SAM** in `infrastructure/` and each backend service’s `template.yaml`.
    - There are deployment and verification scripts for local smoke tests, stage verification, and dashboard setup.
    - Frontend delivery is split across web/admin hosting flows and **Expo EAS** for mobile builds, reflected by `mobile-eas.yml` and the mobile app’s EAS config.

13. **Local development and test topology**
    - The repo includes strong support for isolated testing: separate Python test suites per backend service, frontend tests, and infrastructure contract tests.
    - `tools/mock-server` and the various `scripts/dev/*` helpers indicate a local simulation layer for seed data and end-to-end smoke validation.
    - This suggests the architecture is designed to be validated at the service boundary, not only through a single integrated environment.

14. **How to draw the architecture**
    - A good diagram should show three clients on the left, API Gateway plus Cognito in the middle, four backend services behind it, and DynamoDB as the shared persistence substrate.
    - Separately, draw the geofence path from the mobile app to AWS Location Service to EventBridge to the orders service.
    - Highlight the orders service as the decision engine that governs capacity and dispatch timing, with restaurants and users as supporting domain services and POS integration as the external-system bridge.

Main entry points: [`infrastructure/template.yaml`](https://github.com/shashankcm95/aadi/blob/main/infrastructure/template.yaml) (API Gateway), [`services/orders`](https://github.com/shashankcm95/aadi/tree/main/services/orders) (Orders), [`services/restaurants`](https://github.com/shashankcm95/aadi/tree/main/services/restaurants) (Restaurants), [`services/shared/python/shared`](https://github.com/shashankcm95/aadi/tree/main/services/shared/python/shared) (Shared Layer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_clients["Clients"]
  node_mobile_ios["Mobile iOS<br/>customer app"]
  node_customer_web["Customer Web<br/>customer app"]
  node_admin_portal["Admin Portal<br/>ops app"]
end

subgraph group_backend["Backend"]
  node_orders_service["Orders<br/>workflow service"]
  node_orders_engine(("Engine<br/>state machine<br/>[engine.py]"))
  node_orders_capacity(("Capacity<br/>coordination logic<br/>[capacity.py]"))
  node_orders_geofence(("Geofence Flow<br/>event handler<br/>[geofence_events.py]"))
  node_restaurants_service["Restaurants<br/>catalog service"]
  node_users_service["Users<br/>profile service"]
  node_pos_service["POS Integration<br/>adapter service"]
  node_shared_layer["Shared Layer<br/>lambda shared code"]
end

subgraph group_platform["Platform"]
  node_api_gateway{{"API Gateway<br/>api front door<br/>[template.yaml]"}}
  node_cognito{{"Cognito<br/>auth provider<br/>[template.yaml]"}}
  node_dynamodb[("DynamoDB<br/>state store<br/>[template.yaml]")]
  node_aws_location{{"AWS Location<br/>geofence service"}}
  node_eventbridge{{"EventBridge<br/>event bus<br/>[template.yaml]"}}
end

node_mobile_ios -->|"orders, profile, catalog"| node_api_gateway
node_customer_web -->|"orders, profile, catalog"| node_api_gateway
node_admin_portal -->|"ops APIs"| node_api_gateway
node_api_gateway -->|"auth"| node_cognito
node_api_gateway -->|"order APIs"| node_orders_service
node_api_gateway -->|"catalog APIs"| node_restaurants_service
node_api_gateway -->|"user APIs"| node_users_service
node_api_gateway -->|"integration APIs"| node_pos_service
node_orders_service -->|"orchestrates"| node_orders_engine
node_orders_service -->|"serializes capacity"| node_orders_capacity
node_orders_service -->|"dispatch timing"| node_orders_geofence
node_orders_service -->|"orders state"| node_dynamodb
node_orders_capacity -->|"conditional writes"| node_dynamodb
node_orders_geofence -->|"consumes events"| node_eventbridge
node_mobile_ios -->|"location tracking"| node_aws_location
node_orders_service -->|"restaurant lookup"| node_restaurants_service
node_restaurants_service -->|"catalog state"| node_dynamodb
node_users_service -->|"user state"| node_dynamodb
node_pos_service -->|"integration state"| node_dynamodb
node_restaurants_service -->|"helpers"| node_shared_layer
node_orders_service -->|"helpers"| node_shared_layer
node_users_service -->|"helpers"| node_shared_layer
node_pos_service -->|"helpers"| node_shared_layer
node_mobile_ios -->|"geofence signal"| node_eventbridge
node_aws_location -->|"event feed"| node_eventbridge

click node_mobile_ios "https://github.com/shashankcm95/aadi/tree/main/packages/mobile-ios"
click node_customer_web "https://github.com/shashankcm95/aadi/tree/main/packages/customer-web"
click node_admin_portal "https://github.com/shashankcm95/aadi/tree/main/packages/admin-portal"
click node_api_gateway "https://github.com/shashankcm95/aadi/blob/main/infrastructure/template.yaml"
click node_cognito "https://github.com/shashankcm95/aadi/blob/main/infrastructure/template.yaml"
click node_dynamodb "https://github.com/shashankcm95/aadi/blob/main/infrastructure/template.yaml"
click node_aws_location "https://github.com/shashankcm95/aadi/tree/main/packages/mobile-ios/src/services/location"
click node_eventbridge "https://github.com/shashankcm95/aadi/blob/main/infrastructure/template.yaml"
click node_orders_service "https://github.com/shashankcm95/aadi/tree/main/services/orders"
click node_orders_engine "https://github.com/shashankcm95/aadi/blob/main/services/orders/src/engine.py"
click node_orders_capacity "https://github.com/shashankcm95/aadi/blob/main/services/orders/src/capacity.py"
click node_orders_geofence "https://github.com/shashankcm95/aadi/blob/main/services/orders/src/geofence_events.py"
click node_restaurants_service "https://github.com/shashankcm95/aadi/tree/main/services/restaurants"
click node_users_service "https://github.com/shashankcm95/aadi/tree/main/services/users"
click node_pos_service "https://github.com/shashankcm95/aadi/tree/main/services/pos-integration"
click node_shared_layer "https://github.com/shashankcm95/aadi/tree/main/services/shared/python/shared"

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_mobile_ios,node_customer_web,node_admin_portal toneBlue
class node_orders_service,node_orders_engine,node_orders_capacity,node_orders_geofence,node_restaurants_service,node_users_service,node_pos_service,node_shared_layer toneAmber
class node_api_gateway,node_cognito,node_dynamodb,node_aws_location,node_eventbridge toneMint
```

## Components

### Clients

User-facing applications

- [Mobile iOS](https://github.com/shashankcm95/aadi/tree/main/packages/mobile-ios): customer app · Primary customer app for browsing, cart, favorites, orders, login, and location-aware behavior · `packages/mobile-ios`
- [Customer Web](https://github.com/shashankcm95/aadi/tree/main/packages/customer-web): customer app · Browser ordering experience for customers · `packages/customer-web`
- [Admin Portal](https://github.com/shashankcm95/aadi/tree/main/packages/admin-portal): ops app · Operations console for restaurants, capacity, menu ingestion, POS settings, and monitoring · `packages/admin-portal`

### Backend

Lambda services and shared code

- [Orders](https://github.com/shashankcm95/aadi/tree/main/services/orders): workflow service · Core order lifecycle engine for capacity, reservation, expiry, and kitchen dispatch · `services/orders`
- [Engine](https://github.com/shashankcm95/aadi/blob/main/services/orders/src/engine.py): state machine · Evaluates order transitions and dispatch decisions · `services/orders/src/engine.py`
- [Capacity](https://github.com/shashankcm95/aadi/blob/main/services/orders/src/capacity.py): coordination logic · Pessimistic capacity control using conditional writes · `services/orders/src/capacity.py`
- [Geofence Flow](https://github.com/shashankcm95/aadi/blob/main/services/orders/src/geofence_events.py): event handler · Consumes location-triggered events and decides when to release orders · `services/orders/src/geofence_events.py`
- [Restaurants](https://github.com/shashankcm95/aadi/tree/main/services/restaurants): catalog service · Restaurant source of truth for menus, favorites, images, config, and geofence alignment · `services/restaurants`
- [Users](https://github.com/shashankcm95/aadi/tree/main/services/users): profile service · Application-level user records and user API behavior · `services/users`
- [POS Integration](https://github.com/shashankcm95/aadi/tree/main/services/pos-integration): adapter service · External POS bridge that translates internal models to vendor-specific interfaces · `services/pos-integration`
- [Shared Layer](https://github.com/shashankcm95/aadi/tree/main/services/shared/python/shared): lambda shared code · Reusable auth, CORS, serialization, and logging helpers across services · `services/shared/python/shared`

### Platform

AWS and deployment layer

- [API Gateway](https://github.com/shashankcm95/aadi/blob/main/infrastructure/template.yaml): api front door · Shared HTTP entry point for client requests to backend services · `infrastructure/template.yaml`
- [Cognito](https://github.com/shashankcm95/aadi/blob/main/infrastructure/template.yaml): auth provider · Authentication boundary for API access · `infrastructure/template.yaml`
- [DynamoDB](https://github.com/shashankcm95/aadi/blob/main/infrastructure/template.yaml): state store · Primary persistence and coordination layer, including capacity contention control · `infrastructure/template.yaml`
- [AWS Location](https://github.com/shashankcm95/aadi/tree/main/packages/mobile-ios/src/services/location): geofence service · Location and geofencing source for mobile-triggered dispatch signals · `packages/mobile-ios/src/services/location`
- [EventBridge](https://github.com/shashankcm95/aadi/blob/main/infrastructure/template.yaml): event bus · Carries geofence and location events into order orchestration · `infrastructure/template.yaml`

## Connections

- Mobile iOS → API Gateway: orders, profile, catalog · Customer app calls backend APIs through the shared gateway
- Customer Web → API Gateway: orders, profile, catalog · Web app calls backend APIs through the shared gateway
- Admin Portal → API Gateway: ops APIs · Admin console reaches service APIs through the gateway
- API Gateway → Cognito: auth · Gateway-protected access uses Cognito authentication
- API Gateway → Orders: order APIs · Routes order lifecycle requests to the orders service
- API Gateway → Restaurants: catalog APIs · Routes restaurant, menu, image, and favorites traffic
- API Gateway → Users: user APIs · Routes user profile traffic
- API Gateway → POS Integration: integration APIs · Routes POS-facing integration traffic
- Orders → Engine: orchestrates · Order service delegates state transition decisions to the engine
- Orders → Capacity: serializes capacity · Orders service coordinates kitchen capacity using conditional writes
- Orders → Geofence Flow: dispatch timing · Orders service processes geofence events for just-in-time release
- Orders → DynamoDB: orders state · Stores order lifecycle state and coordination records
- Capacity → DynamoDB: conditional writes · Capacity control depends on DynamoDB concurrency semantics
- Geofence Flow → EventBridge: consumes events · Location-triggered events arrive via EventBridge
- Mobile iOS → AWS Location: location tracking · Mobile client tracks location for geofence behavior
- Orders → Restaurants: restaurant lookup · Orders depend on restaurant/menu data for dispatch and availability
- Restaurants → DynamoDB: catalog state · Persists restaurant and menu data in DynamoDB
- Users → DynamoDB: user state · Persists application user data in DynamoDB
- POS Integration → DynamoDB: integration state · Stores integration-side records and mappings in DynamoDB
- Restaurants → Shared Layer: helpers · Service uses shared auth, CORS, serialization, and logging code
- Orders → Shared Layer: helpers · Service uses shared auth, CORS, serialization, and logging code
- Users → Shared Layer: helpers · Service uses shared auth, CORS, serialization, and logging code
- POS Integration → Shared Layer: helpers · Service uses shared auth, CORS, serialization, and logging code
- Mobile iOS → EventBridge: geofence signal · Location changes can influence dispatch through the event bus
- AWS Location → EventBridge: event feed · AWS Location emits geofence-related events into EventBridge
