# forgeblueai/ai-order-processing-agent architecture

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

- Interactive diagram: https://gitdiagram.com/forgeblueai/ai-order-processing-agent
- Repository: https://github.com/forgeblueai/ai-order-processing-agent

## Overview

This FastAPI backend turns unstructured B2B order requests into evidence-checked extractions, deterministic validation results, and persisted orders. Operators submit requests; reviewers and approvers make role-authorized lifecycle decisions; senders record response drafting and confirmation. The main path is API → extraction → business validation → lifecycle service → repository. The README documents evaluation and PostgreSQL support, but those are not expanded into runtime components here. Relationships are based on shown excerpts, source-index references, or README statements; unsampled implementation details are omitted.

Main entry points: [`app/api/orders.py`](https://github.com/forgeblueai/ai-order-processing-agent/blob/main/app/api/orders.py) (Order routes), [`app/ai/provider.py`](https://github.com/forgeblueai/ai-order-processing-agent/blob/main/app/ai/provider.py) (LLM extractor), [`app/services/order_application_service.py`](https://github.com/forgeblueai/ai-order-processing-agent/blob/main/app/services/order_application_service.py) (Order application service), [`app/services/order_service.py`](https://github.com/forgeblueai/ai-order-processing-agent/blob/main/app/services/order_service.py) (Order validation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and access"]
  node_api_app["FastAPI application<br/>[main.py]"]
  node_order_routes["Order routes<br/>[orders.py]"]
  node_authorization["Role authorization<br/>[security.py]"]
end

subgraph group_extraction["Order extraction"]
  node_extraction_contracts["Extraction contracts<br/>[extraction.py]"]
  node_extractor["Extractor interface<br/>[extractor.py]"]
  node_llm_extractor["LLM extractor<br/>[provider.py]"]
  node_prompts["Extraction prompts<br/>[prompts.py]"]
  node_evidence_checks["Source evidence checks<br/>[source_evidence.py]"]
  node_ollama_adapter["Ollama adapter<br/>[ollama_provider.py]"]
end

subgraph group_processing["Validation and lifecycle"]
  node_order_contracts["Order contracts<br/>[order.py]"]
  node_business_validation["Order validation<br/>[order_service.py]"]
  node_inventory_catalog["Product and stock catalog"]
  node_application_service["Order application service"]
  node_lifecycle["Lifecycle rules<br/>[order_lifecycle.py]"]
  node_order_record["Order record<br/>[order.py]"]
  node_response_drafter["Customer response drafter"]
end

subgraph group_persistence["Order persistence"]
  node_repository_port["Order repository port"]
  node_sql_repository["SQLAlchemy repository"]
  node_database[("Configured database<br/>[db.py]")]
end

node_operator(("Operator"))
node_reviewer(("Reviewer and approver"))
node_sender(("Sender"))
node_ollama_service{{"Ollama service"}}

node_operator -->|"submits request"| node_api_app
node_reviewer -->|"reviews orders"| node_order_routes
node_sender -->|"confirms response"| node_order_routes
node_api_app -->|"registers routes"| node_order_routes
node_order_routes -->|"checks roles"| node_authorization
node_order_routes -->|"constructs extractor"| node_llm_extractor
node_order_routes -->|"creates and updates"| node_application_service
node_order_routes -->|"processes request"| node_business_validation
node_order_routes -->|"wires repository"| node_sql_repository
node_order_routes -->|"validates and returns"| node_order_contracts
node_llm_extractor -->|"uses prompt"| node_prompts
node_llm_extractor -->|"validates output"| node_extraction_contracts
node_llm_extractor -->|"checks evidence"| node_evidence_checks
node_llm_extractor -.->|"requests completion"| node_ollama_adapter
node_ollama_adapter -.->|"sends completion"| node_ollama_service
node_business_validation -->|"extracts request"| node_extractor
node_business_validation -->|"checks product and stock"| node_inventory_catalog
node_application_service -->|"loads and saves"| node_repository_port
node_application_service -->|"creates and updates"| node_order_record
node_application_service -->|"validates transitions"| node_lifecycle
node_application_service -->|"drafts response"| node_response_drafter
node_sql_repository -->|"reads and writes"| node_database
node_sql_repository -->|"maps records"| node_order_record

click node_api_app "https://github.com/forgeblueai/ai-order-processing-agent/blob/main/app/main.py"
click node_order_routes "https://github.com/forgeblueai/ai-order-processing-agent/blob/main/app/api/orders.py"
click node_authorization "https://github.com/forgeblueai/ai-order-processing-agent/blob/main/app/api/security.py"
click node_order_contracts "https://github.com/forgeblueai/ai-order-processing-agent/blob/main/app/schemas/order.py"
click node_extraction_contracts "https://github.com/forgeblueai/ai-order-processing-agent/blob/main/app/schemas/extraction.py"
click node_extractor "https://github.com/forgeblueai/ai-order-processing-agent/blob/main/app/ai/extractor.py"
click node_llm_extractor "https://github.com/forgeblueai/ai-order-processing-agent/blob/main/app/ai/provider.py"
click node_prompts "https://github.com/forgeblueai/ai-order-processing-agent/blob/main/app/ai/prompts.py"
click node_evidence_checks "https://github.com/forgeblueai/ai-order-processing-agent/blob/main/app/ai/source_evidence.py"
click node_ollama_adapter "https://github.com/forgeblueai/ai-order-processing-agent/blob/main/app/ai/ollama_provider.py"
click node_business_validation "https://github.com/forgeblueai/ai-order-processing-agent/blob/main/app/services/order_service.py"
click node_inventory_catalog "https://github.com/forgeblueai/ai-order-processing-agent/blob/main/app/services/inventory_service.py"
click node_application_service "https://github.com/forgeblueai/ai-order-processing-agent/blob/main/app/services/order_application_service.py"
click node_lifecycle "https://github.com/forgeblueai/ai-order-processing-agent/blob/main/app/services/order_lifecycle.py"
click node_order_record "https://github.com/forgeblueai/ai-order-processing-agent/blob/main/app/domain/order.py"
click node_response_drafter "https://github.com/forgeblueai/ai-order-processing-agent/blob/main/app/ports/customer_response_drafter.py"
click node_repository_port "https://github.com/forgeblueai/ai-order-processing-agent/blob/main/app/ports/order_repository.py"
click node_sql_repository "https://github.com/forgeblueai/ai-order-processing-agent/blob/main/app/adapters/sqlalchemy_order_repository.py"
click node_database "https://github.com/forgeblueai/ai-order-processing-agent/blob/main/app/db.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_api_app,node_order_routes,node_authorization,node_reviewer toneBlue
class node_extraction_contracts,node_extractor,node_llm_extractor,node_prompts,node_evidence_checks,node_ollama_adapter toneAmber
class node_order_contracts,node_business_validation,node_inventory_catalog,node_application_service,node_lifecycle,node_order_record,node_response_drafter toneMint
class node_repository_port,node_sql_repository,node_database toneRose
class node_operator,node_sender,node_ollama_service toneIndigo
```

## Components

### API and access

- [FastAPI application](https://github.com/forgeblueai/ai-order-processing-agent/blob/main/app/main.py): `app/main.py`
- [Order routes](https://github.com/forgeblueai/ai-order-processing-agent/blob/main/app/api/orders.py): `app/api/orders.py`
- [Role authorization](https://github.com/forgeblueai/ai-order-processing-agent/blob/main/app/api/security.py): `app/api/security.py`

### Order extraction

- [Extraction contracts](https://github.com/forgeblueai/ai-order-processing-agent/blob/main/app/schemas/extraction.py): `app/schemas/extraction.py`
- [Extractor interface](https://github.com/forgeblueai/ai-order-processing-agent/blob/main/app/ai/extractor.py): `app/ai/extractor.py`
- [LLM extractor](https://github.com/forgeblueai/ai-order-processing-agent/blob/main/app/ai/provider.py): `app/ai/provider.py`
- [Extraction prompts](https://github.com/forgeblueai/ai-order-processing-agent/blob/main/app/ai/prompts.py): `app/ai/prompts.py`
- [Source evidence checks](https://github.com/forgeblueai/ai-order-processing-agent/blob/main/app/ai/source_evidence.py): `app/ai/source_evidence.py`
- [Ollama adapter](https://github.com/forgeblueai/ai-order-processing-agent/blob/main/app/ai/ollama_provider.py): `app/ai/ollama_provider.py`

### Validation and lifecycle

- [Order contracts](https://github.com/forgeblueai/ai-order-processing-agent/blob/main/app/schemas/order.py): `app/schemas/order.py`
- [Order validation](https://github.com/forgeblueai/ai-order-processing-agent/blob/main/app/services/order_service.py): `app/services/order_service.py`
- [Product and stock catalog](https://github.com/forgeblueai/ai-order-processing-agent/blob/main/app/services/inventory_service.py): `app/services/inventory_service.py`
- [Order application service](https://github.com/forgeblueai/ai-order-processing-agent/blob/main/app/services/order_application_service.py): `app/services/order_application_service.py`
- [Lifecycle rules](https://github.com/forgeblueai/ai-order-processing-agent/blob/main/app/services/order_lifecycle.py): `app/services/order_lifecycle.py`
- [Order record](https://github.com/forgeblueai/ai-order-processing-agent/blob/main/app/domain/order.py): `app/domain/order.py`
- [Customer response drafter](https://github.com/forgeblueai/ai-order-processing-agent/blob/main/app/ports/customer_response_drafter.py): `app/ports/customer_response_drafter.py`

### Order persistence

- [Order repository port](https://github.com/forgeblueai/ai-order-processing-agent/blob/main/app/ports/order_repository.py): `app/ports/order_repository.py`
- [SQLAlchemy repository](https://github.com/forgeblueai/ai-order-processing-agent/blob/main/app/adapters/sqlalchemy_order_repository.py): `app/adapters/sqlalchemy_order_repository.py`
- [Configured database](https://github.com/forgeblueai/ai-order-processing-agent/blob/main/app/db.py): `app/db.py`

### Other components

- **Operator**
- **Reviewer and approver**
- **Sender**
- **Ollama service**

## Connections

- Operator → FastAPI application: submits request (evidence: `README.md`)
- Reviewer and approver → Order routes: reviews orders (evidence: `README.md`)
- Sender → Order routes: confirms response (evidence: `README.md`)
- FastAPI application → Order routes: registers routes (evidence: `app/main.py`)
- Order routes → Role authorization: checks roles (evidence: `app/api/orders.py`)
- Order routes → LLM extractor: constructs extractor (evidence: `app/api/orders.py`)
- Order routes → Order application service: creates and updates (evidence: `app/api/orders.py`)
- Order routes → Order validation: processes request (evidence: `app/api/orders.py`)
- Order routes → SQLAlchemy repository: wires repository (evidence: `app/api/orders.py`)
- Order routes → Order contracts: validates and returns (evidence: `app/api/orders.py`)
- LLM extractor → Extraction prompts: uses prompt (evidence: `app/ai/provider.py`)
- LLM extractor → Extraction contracts: validates output (evidence: `app/ai/provider.py`)
- LLM extractor → Source evidence checks: checks evidence (evidence: `app/ai/provider.py`)
- LLM extractor → Ollama adapter: requests completion
- Ollama adapter → Ollama service: sends completion
- Order validation → Extractor interface: extracts request (evidence: `app/services/order_service.py`)
- Order validation → Product and stock catalog: checks product and stock (evidence: `app/services/order_service.py`)
- Order application service → Order repository port: loads and saves (evidence: `app/services/order_application_service.py`)
- Order application service → Order record: creates and updates (evidence: `app/services/order_application_service.py`)
- Order application service → Lifecycle rules: validates transitions (evidence: `app/services/order_application_service.py`)
- Order application service → Customer response drafter: drafts response (evidence: `app/services/order_application_service.py`)
- SQLAlchemy repository → Configured database: reads and writes (evidence: `app/adapters/sqlalchemy_order_repository.py`)
- SQLAlchemy repository → Order record: maps records (evidence: `app/adapters/sqlalchemy_order_repository.py`)
