# abhioriganti/supplychain_copilot architecture

> Architecture diagram of the GitHub repository abhioriganti/supplychain_copilot, 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/abhioriganti/supplychain_copilot
- Repository: https://github.com/abhioriganti/supplychain_copilot

## Overview

SupplyChain Copilot is a governed supply-chain analytics and supplier-document Q&A application. A user asks in the Streamlit interface; the Cortex Agent routes to governed warehouse analytics, document search, or both, and the interface presents the answer with SQL/results and page citations. Separate branches prepare warehouse and document data, surface late-delivery risk, and support a simulated human-approved incident workflow. Evaluation and request logging provide quality and operational oversight. The README documents the major product capabilities; some implementation links below rely on those statements or the source index because their source was not excerpted.

Main entry points: [`src/supplychain_copilot/agent/client.py`](https://github.com/abhioriganti/supplychain_copilot/blob/main/src/supplychain_copilot/agent/client.py) (Cortex Agent client), [`app/streamlit_app.py`](https://github.com/abhioriganti/supplychain_copilot/blob/main/app/streamlit_app.py) (Streamlit app), [`src/supplychain_copilot/incidents/service.py`](https://github.com/abhioriganti/supplychain_copilot/blob/main/src/supplychain_copilot/incidents/service.py) (Incident workflow), [`src/supplychain_copilot/documents/pipeline.py`](https://github.com/abhioriganti/supplychain_copilot/blob/main/src/supplychain_copilot/documents/pipeline.py) (Document processing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["User experience"]
  node_app["Streamlit app<br/>[streamlit_app.py]"]
  node_answer_ui["Answer presentation<br/>[components.py]"]
  node_risk_ui["Risk display<br/>[risk.py]"]
  node_incident_ui["Incident interface<br/>[incidents.py]"]
end

subgraph group_evidence["Evidence preparation"]
  node_warehouse_prep["Order ingestion"]
  node_warehouse_model[("Warehouse model")]
  node_semantic["Governed metrics<br/>[analyst.py]"]
  node_doc_pipeline["Document processing<br/>[pipeline.py]"]
  node_doc_extract["PDF extraction<br/>[extract.py]"]
  node_doc_registry["Document registry<br/>[registry.py]"]
end

subgraph group_intelligence["Answering and risk"]
  node_agent["Cortex Agent client<br/>[client.py]"]
  node_search["Document search<br/>[search_client.py]"]
  node_risk["Late-risk model<br/>[late_risk.py]"]
end

subgraph group_operations["Operations and oversight"]
  node_incident_service["Incident workflow<br/>[service.py]"]
  node_incident_store[("Audit event store<br/>[store.py]")]
  node_n8n["n8n approval<br/>[n8n_workflow.py]"]
  node_incident_api["Incident callback API<br/>[api.py]"]
  node_observability["Request logging<br/>[observability.py]"]
  node_evaluation["Answer evaluation<br/>[runner.py]"]
end

node_user(("Business user"))
node_snowflake{{"Snowflake Cortex"}}
node_slack{{"Slack"}}

node_user -->|"asks"| node_app
node_app -->|"submits question"| node_agent
node_agent -->|"runs tools"| node_snowflake
node_snowflake -->|"returns answer"| node_agent
node_agent -.->|"search tool"| node_search
node_agent -.->|"analytics tool"| node_semantic
node_app -->|"renders answer"| node_answer_ui
node_app -->|"logs request"| node_observability
node_warehouse_prep -->|"loads data"| node_warehouse_model
node_warehouse_model -->|"defines metrics"| node_semantic
node_doc_pipeline -->|"extracts PDFs"| node_doc_extract
node_doc_pipeline -->|"checks provenance"| node_doc_registry
node_doc_pipeline -.->|"indexes chunks"| node_snowflake
node_search -->|"queries index"| node_snowflake
node_app -->|"shows risk"| node_risk_ui
node_risk_ui -.->|"uses predictions"| node_risk
node_app -->|"offers incidents"| node_incident_ui
node_incident_ui -->|"manages incident"| node_incident_service
node_incident_service -->|"drafts response"| node_agent
node_incident_service -.->|"appends events"| node_incident_store
node_incident_service -->|"posts approval"| node_n8n
node_n8n -.->|"notifies approver"| node_slack
node_n8n -.->|"sends callback"| node_incident_api
node_evaluation -->|"evaluates answers"| node_agent
node_evaluation -.->|"checks SQL results"| node_snowflake

click node_app "https://github.com/abhioriganti/supplychain_copilot/blob/main/app/streamlit_app.py"
click node_answer_ui "https://github.com/abhioriganti/supplychain_copilot/blob/main/src/supplychain_copilot/ui/components.py"
click node_warehouse_prep "https://github.com/abhioriganti/supplychain_copilot/tree/main/src/supplychain_copilot/ingestion"
click node_warehouse_model "https://github.com/abhioriganti/supplychain_copilot/tree/main/src/supplychain_copilot/warehouse"
click node_semantic "https://github.com/abhioriganti/supplychain_copilot/blob/main/src/supplychain_copilot/semantic/analyst.py"
click node_doc_pipeline "https://github.com/abhioriganti/supplychain_copilot/blob/main/src/supplychain_copilot/documents/pipeline.py"
click node_doc_extract "https://github.com/abhioriganti/supplychain_copilot/blob/main/src/supplychain_copilot/documents/extract.py"
click node_doc_registry "https://github.com/abhioriganti/supplychain_copilot/blob/main/src/supplychain_copilot/documents/registry.py"
click node_agent "https://github.com/abhioriganti/supplychain_copilot/blob/main/src/supplychain_copilot/agent/client.py"
click node_search "https://github.com/abhioriganti/supplychain_copilot/blob/main/src/supplychain_copilot/retrieval/search_client.py"
click node_risk "https://github.com/abhioriganti/supplychain_copilot/blob/main/src/supplychain_copilot/ml/late_risk.py"
click node_risk_ui "https://github.com/abhioriganti/supplychain_copilot/blob/main/src/supplychain_copilot/ui/risk.py"
click node_incident_ui "https://github.com/abhioriganti/supplychain_copilot/blob/main/src/supplychain_copilot/ui/incidents.py"
click node_incident_service "https://github.com/abhioriganti/supplychain_copilot/blob/main/src/supplychain_copilot/incidents/service.py"
click node_incident_store "https://github.com/abhioriganti/supplychain_copilot/blob/main/src/supplychain_copilot/incidents/store.py"
click node_n8n "https://github.com/abhioriganti/supplychain_copilot/blob/main/src/supplychain_copilot/incidents/n8n_workflow.py"
click node_incident_api "https://github.com/abhioriganti/supplychain_copilot/blob/main/src/supplychain_copilot/incidents/api.py"
click node_observability "https://github.com/abhioriganti/supplychain_copilot/blob/main/src/supplychain_copilot/observability.py"
click node_evaluation "https://github.com/abhioriganti/supplychain_copilot/blob/main/src/supplychain_copilot/evaluation/runner.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_app,node_answer_ui,node_risk_ui,node_incident_ui,node_user toneBlue
class node_warehouse_prep,node_warehouse_model,node_semantic,node_doc_pipeline,node_doc_extract,node_doc_registry toneAmber
class node_agent,node_search,node_risk toneMint
class node_incident_service,node_incident_store,node_n8n,node_incident_api,node_observability,node_evaluation toneRose
class node_snowflake,node_slack toneIndigo
```

## Components

### User experience

- [Streamlit app](https://github.com/abhioriganti/supplychain_copilot/blob/main/app/streamlit_app.py): `app/streamlit_app.py`
- [Answer presentation](https://github.com/abhioriganti/supplychain_copilot/blob/main/src/supplychain_copilot/ui/components.py): `src/supplychain_copilot/ui/components.py`
- [Risk display](https://github.com/abhioriganti/supplychain_copilot/blob/main/src/supplychain_copilot/ui/risk.py): `src/supplychain_copilot/ui/risk.py`
- [Incident interface](https://github.com/abhioriganti/supplychain_copilot/blob/main/src/supplychain_copilot/ui/incidents.py): `src/supplychain_copilot/ui/incidents.py`

### Evidence preparation

- [Order ingestion](https://github.com/abhioriganti/supplychain_copilot/tree/main/src/supplychain_copilot/ingestion): `src/supplychain_copilot/ingestion`
- [Warehouse model](https://github.com/abhioriganti/supplychain_copilot/tree/main/src/supplychain_copilot/warehouse): `src/supplychain_copilot/warehouse`
- [Governed metrics](https://github.com/abhioriganti/supplychain_copilot/blob/main/src/supplychain_copilot/semantic/analyst.py): `src/supplychain_copilot/semantic/analyst.py`
- [Document processing](https://github.com/abhioriganti/supplychain_copilot/blob/main/src/supplychain_copilot/documents/pipeline.py): `src/supplychain_copilot/documents/pipeline.py`
- [PDF extraction](https://github.com/abhioriganti/supplychain_copilot/blob/main/src/supplychain_copilot/documents/extract.py): `src/supplychain_copilot/documents/extract.py`
- [Document registry](https://github.com/abhioriganti/supplychain_copilot/blob/main/src/supplychain_copilot/documents/registry.py): `src/supplychain_copilot/documents/registry.py`

### Answering and risk

- [Cortex Agent client](https://github.com/abhioriganti/supplychain_copilot/blob/main/src/supplychain_copilot/agent/client.py): `src/supplychain_copilot/agent/client.py`
- [Document search](https://github.com/abhioriganti/supplychain_copilot/blob/main/src/supplychain_copilot/retrieval/search_client.py): `src/supplychain_copilot/retrieval/search_client.py`
- [Late-risk model](https://github.com/abhioriganti/supplychain_copilot/blob/main/src/supplychain_copilot/ml/late_risk.py): `src/supplychain_copilot/ml/late_risk.py`

### Operations and oversight

- [Incident workflow](https://github.com/abhioriganti/supplychain_copilot/blob/main/src/supplychain_copilot/incidents/service.py): `src/supplychain_copilot/incidents/service.py`
- [Audit event store](https://github.com/abhioriganti/supplychain_copilot/blob/main/src/supplychain_copilot/incidents/store.py): `src/supplychain_copilot/incidents/store.py`
- [n8n approval](https://github.com/abhioriganti/supplychain_copilot/blob/main/src/supplychain_copilot/incidents/n8n_workflow.py): `src/supplychain_copilot/incidents/n8n_workflow.py`
- [Incident callback API](https://github.com/abhioriganti/supplychain_copilot/blob/main/src/supplychain_copilot/incidents/api.py): `src/supplychain_copilot/incidents/api.py`
- [Request logging](https://github.com/abhioriganti/supplychain_copilot/blob/main/src/supplychain_copilot/observability.py): `src/supplychain_copilot/observability.py`
- [Answer evaluation](https://github.com/abhioriganti/supplychain_copilot/blob/main/src/supplychain_copilot/evaluation/runner.py): `src/supplychain_copilot/evaluation/runner.py`

### Other components

- **Business user**
- **Snowflake Cortex**
- **Slack**

## Connections

- Business user → Streamlit app: asks
- Streamlit app → Cortex Agent client: submits question (evidence: `app/streamlit_app.py`)
- Cortex Agent client → Snowflake Cortex: runs tools (evidence: `src/supplychain_copilot/agent/client.py`)
- Snowflake Cortex → Cortex Agent client: returns answer
- Cortex Agent client → Document search: search tool
- Cortex Agent client → Governed metrics: analytics tool
- Streamlit app → Answer presentation: renders answer (evidence: `app/streamlit_app.py`)
- Streamlit app → Request logging: logs request (evidence: `app/streamlit_app.py`)
- Order ingestion → Warehouse model: loads data (evidence: `src/supplychain_copilot/warehouse/reconcile.py`)
- Warehouse model → Governed metrics: defines metrics
- Document processing → PDF extraction: extracts PDFs (evidence: `src/supplychain_copilot/documents/pipeline.py`)
- Document processing → Document registry: checks provenance (evidence: `src/supplychain_copilot/documents/pipeline.py`)
- Document processing → Snowflake Cortex: indexes chunks
- Document search → Snowflake Cortex: queries index (evidence: `src/supplychain_copilot/retrieval/search_client.py`)
- Streamlit app → Risk display: shows risk (evidence: `app/streamlit_app.py`)
- Risk display → Late-risk model: uses predictions
- Streamlit app → Incident interface: offers incidents (evidence: `app/streamlit_app.py`)
- Incident interface → Incident workflow: manages incident (evidence: `src/supplychain_copilot/ui/incidents.py`)
- Incident workflow → Cortex Agent client: drafts response (evidence: `src/supplychain_copilot/incidents/service.py`)
- Incident workflow → Audit event store: appends events (evidence: `src/supplychain_copilot/incidents/service.py`)
- Incident workflow → n8n approval: posts approval (evidence: `src/supplychain_copilot/incidents/service.py`)
- n8n approval → Slack: notifies approver
- n8n approval → Incident callback API: sends callback
- Answer evaluation → Cortex Agent client: evaluates answers (evidence: `src/supplychain_copilot/evaluation/runner.py`)
- Answer evaluation → Snowflake Cortex: checks SQL results
