# atharvpatil8147/nexcart-scm architecture

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

- Interactive diagram: https://gitdiagram.com/atharvpatil8147/nexcart-scm
- Repository: https://github.com/atharvpatil8147/nexcart-scm

## Overview

NexCart monitors external supply-chain signals, evaluates disruption risk against inventory, and supports customer recovery through personalized restock nudges. Users sign in to role-based workspaces to review live signals, SKU risk, disruptions, campaigns, and analytics; the frontend calls a FastAPI API backed by MongoDB. The README documents the two-agent prediction-to-nudge workflow and assistant, digest, analytics, SSE, and scheduling capabilities. Several implementation paths are unsampled, so those branches are included only where documented, with uncertain links omitted.

Main entry points: [`backend/main.py`](https://github.com/atharvpatil8147/nexcart-scm/blob/main/backend/main.py) (FastAPI application), [`backend/agents/disruption_agent.py`](https://github.com/atharvpatil8147/nexcart-scm/blob/main/backend/agents/disruption_agent.py) (Disruption agent), [`backend/database/connection.py`](https://github.com/atharvpatil8147/nexcart-scm/blob/main/backend/database/connection.py) (MongoDB), [`backend/routers/nudges.py`](https://github.com/atharvpatil8147/nexcart-scm/blob/main/backend/routers/nudges.py) (Nudge routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web application"]
  node_frontend["Role workspaces<br/>[App.jsx]"]
  node_authui["Session context<br/>[AuthContext.jsx]"]
  node_apiclient["API client<br/>[client.js]"]
  node_skurisk["SKU risk view<br/>[SKURisk.jsx]"]
  node_roleworkspaces["Role dashboards<br/>[RoleWorkspaces.jsx]"]
  node_assistantui["Assistant widget"]
end

subgraph group_api["API and access"]
  node_apiapp["FastAPI application<br/>[main.py]"]
  node_authroutes["Authentication routes<br/>[auth.py]"]
  node_skuroutes["SKU routes<br/>[skus.py]"]
  node_disruptionroutes["Disruption routes<br/>[disruptions.py]"]
  node_signalroutes["Signal routes<br/>[signals.py]"]
  node_nudgeroutes["Nudge routes<br/>[nudges.py]"]
  node_dashroutes["Dashboard routes<br/>[dashboard.py]"]
  node_assistantroutes["Assistant routes<br/>[assistant.py]"]
  node_security["Tokens and RBAC<br/>[security.py]"]
  node_permissions["Permission rules<br/>[permissions.py]"]
end

subgraph group_risk["Risk intelligence"]
  node_riskagent["Disruption agent"]
  node_riskscorer["Risk scoring<br/>[risk_scorer.py]"]
  node_news["News signals<br/>[news_service.py]"]
  node_weather["Weather signals<br/>[weather_service.py]"]
  node_shipping["Shipping signals"]
end

subgraph group_recovery["Customer recovery"]
  node_nudgeagent["Personalization agent<br/>[nudge_agent.py]"]
  node_llm["LLM providers<br/>[llm_provider.py]"]
  node_assistantservice["Operations assistant"]
  node_notifications["Customer notifications<br/>[notification.py]"]
end

subgraph group_state["Persistence and integrations"]
  node_mongo[("MongoDB<br/>[connection.py]")]
  node_models["Domain models<br/>[models.py]"]
  node_collections["Collection definitions<br/>[collections.py]"]
  node_audit["Audit logging<br/>[audit.py]"]
  node_eventbridge["EventBridge<br/>[eventbridge.py]"]
end

node_operator(("Operations user"))
node_signalproviders(("News, weather, shipping"))
node_customerchannels(("Push and email"))
node_llmproviders(("Groq and Gemini"))

node_operator -->|"uses"| node_frontend
node_frontend -->|"provides session"| node_authui
node_frontend -->|"routes to"| node_skurisk
node_frontend -->|"routes to"| node_roleworkspaces
node_skurisk -->|"requests data"| node_apiclient
node_roleworkspaces -->|"requests data"| node_apiclient
node_assistantui -->|"sends questions"| node_apiclient
node_authui -->|"checks session"| node_apiclient
node_apiclient -->|"HTTP requests"| node_apiapp
node_apiapp -->|"mounts routes"| node_authroutes
node_apiapp -->|"mounts routes"| node_skuroutes
node_apiapp -->|"mounts routes"| node_disruptionroutes
node_apiapp -->|"mounts routes"| node_signalroutes
node_apiapp -->|"mounts routes"| node_nudgeroutes
node_apiapp -->|"mounts routes"| node_dashroutes
node_apiapp -->|"mounts routes"| node_assistantroutes
node_authroutes -->|"uses tokens"| node_security
node_apiapp -->|"checks requests"| node_security
node_security -->|"checks roles"| node_permissions
node_signalproviders -.->|"provides signals"| node_riskagent
node_riskagent -->|"collects signals"| node_news
node_riskagent -->|"collects signals"| node_weather
node_riskagent -->|"collects signals"| node_shipping
node_riskagent -->|"analyzes risk"| node_llm
node_riskagent -->|"updates records"| node_mongo
node_riskagent -->|"publishes events"| node_eventbridge
node_skuroutes -->|"scores risk"| node_riskscorer
node_nudgeroutes -->|"runs campaign"| node_nudgeagent
node_nudgeagent -->|"generates copy"| node_llm
node_llmproviders -.->|"model requests"| node_llm
node_nudgeagent -->|"dispatches nudges"| node_notifications
node_notifications -.->|"sends messages"| node_customerchannels
node_assistantroutes -->|"handles questions"| node_assistantservice
node_assistantservice -->|"uses model"| node_llm
node_skuroutes -->|"reads and writes"| node_mongo
node_disruptionroutes -->|"reads records"| node_mongo
node_signalroutes -->|"reads records"| node_mongo
node_nudgeroutes -->|"reads and writes"| node_mongo
node_dashroutes -->|"reads metrics"| node_mongo
node_mongo -->|"uses names"| node_collections
node_skuroutes -->|"validates data"| node_models
node_disruptionroutes -->|"validates data"| node_models
node_signalroutes -->|"validates data"| node_models
node_nudgeroutes -->|"validates data"| node_models
node_authroutes -->|"records actions"| node_audit
node_disruptionroutes -->|"records actions"| node_audit
node_nudgeroutes -->|"records actions"| node_audit

click node_frontend "https://github.com/atharvpatil8147/nexcart-scm/blob/main/frontend/src/App.jsx"
click node_authui "https://github.com/atharvpatil8147/nexcart-scm/blob/main/frontend/src/auth/AuthContext.jsx"
click node_apiclient "https://github.com/atharvpatil8147/nexcart-scm/blob/main/frontend/src/api/client.js"
click node_skurisk "https://github.com/atharvpatil8147/nexcart-scm/blob/main/frontend/src/pages/SKURisk.jsx"
click node_roleworkspaces "https://github.com/atharvpatil8147/nexcart-scm/blob/main/frontend/src/pages/RoleWorkspaces.jsx"
click node_assistantui "https://github.com/atharvpatil8147/nexcart-scm/blob/main/frontend/src/components/AssistantWidget.jsx"
click node_apiapp "https://github.com/atharvpatil8147/nexcart-scm/blob/main/backend/main.py"
click node_authroutes "https://github.com/atharvpatil8147/nexcart-scm/blob/main/backend/routers/auth.py"
click node_skuroutes "https://github.com/atharvpatil8147/nexcart-scm/blob/main/backend/routers/skus.py"
click node_disruptionroutes "https://github.com/atharvpatil8147/nexcart-scm/blob/main/backend/routers/disruptions.py"
click node_signalroutes "https://github.com/atharvpatil8147/nexcart-scm/blob/main/backend/routers/signals.py"
click node_nudgeroutes "https://github.com/atharvpatil8147/nexcart-scm/blob/main/backend/routers/nudges.py"
click node_dashroutes "https://github.com/atharvpatil8147/nexcart-scm/blob/main/backend/routers/dashboard.py"
click node_assistantroutes "https://github.com/atharvpatil8147/nexcart-scm/blob/main/backend/routers/assistant.py"
click node_security "https://github.com/atharvpatil8147/nexcart-scm/blob/main/backend/security.py"
click node_permissions "https://github.com/atharvpatil8147/nexcart-scm/blob/main/backend/permissions.py"
click node_riskagent "https://github.com/atharvpatil8147/nexcart-scm/blob/main/backend/agents/disruption_agent.py"
click node_riskscorer "https://github.com/atharvpatil8147/nexcart-scm/blob/main/backend/utils/risk_scorer.py"
click node_news "https://github.com/atharvpatil8147/nexcart-scm/blob/main/backend/services/news_service.py"
click node_weather "https://github.com/atharvpatil8147/nexcart-scm/blob/main/backend/services/weather_service.py"
click node_shipping "https://github.com/atharvpatil8147/nexcart-scm/blob/main/backend/services/shipping_service.py"
click node_nudgeagent "https://github.com/atharvpatil8147/nexcart-scm/blob/main/backend/agents/nudge_agent.py"
click node_llm "https://github.com/atharvpatil8147/nexcart-scm/blob/main/backend/services/llm_provider.py"
click node_assistantservice "https://github.com/atharvpatil8147/nexcart-scm/blob/main/backend/services/assistant_service.py"
click node_notifications "https://github.com/atharvpatil8147/nexcart-scm/blob/main/backend/services/notification.py"
click node_mongo "https://github.com/atharvpatil8147/nexcart-scm/blob/main/backend/database/connection.py"
click node_models "https://github.com/atharvpatil8147/nexcart-scm/blob/main/backend/database/models.py"
click node_collections "https://github.com/atharvpatil8147/nexcart-scm/blob/main/backend/database/collections.py"
click node_audit "https://github.com/atharvpatil8147/nexcart-scm/blob/main/backend/audit.py"
click node_eventbridge "https://github.com/atharvpatil8147/nexcart-scm/blob/main/backend/services/eventbridge.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_frontend,node_authui,node_apiclient,node_skurisk,node_roleworkspaces,node_assistantui,node_operator toneBlue
class node_apiapp,node_authroutes,node_skuroutes,node_disruptionroutes,node_signalroutes,node_nudgeroutes,node_dashroutes,node_assistantroutes,node_security,node_permissions toneAmber
class node_riskagent,node_riskscorer,node_news,node_weather,node_shipping toneMint
class node_nudgeagent,node_llm,node_assistantservice,node_notifications toneRose
class node_mongo,node_models,node_collections,node_audit,node_eventbridge,node_signalproviders,node_customerchannels,node_llmproviders toneIndigo
```

## Components

### Web application

- [Role workspaces](https://github.com/atharvpatil8147/nexcart-scm/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Session context](https://github.com/atharvpatil8147/nexcart-scm/blob/main/frontend/src/auth/AuthContext.jsx): `frontend/src/auth/AuthContext.jsx`
- [API client](https://github.com/atharvpatil8147/nexcart-scm/blob/main/frontend/src/api/client.js): `frontend/src/api/client.js`
- [SKU risk view](https://github.com/atharvpatil8147/nexcart-scm/blob/main/frontend/src/pages/SKURisk.jsx): `frontend/src/pages/SKURisk.jsx`
- [Role dashboards](https://github.com/atharvpatil8147/nexcart-scm/blob/main/frontend/src/pages/RoleWorkspaces.jsx): `frontend/src/pages/RoleWorkspaces.jsx`
- [Assistant widget](https://github.com/atharvpatil8147/nexcart-scm/blob/main/frontend/src/components/AssistantWidget.jsx): `frontend/src/components/AssistantWidget.jsx`

### API and access

- [FastAPI application](https://github.com/atharvpatil8147/nexcart-scm/blob/main/backend/main.py): `backend/main.py`
- [Authentication routes](https://github.com/atharvpatil8147/nexcart-scm/blob/main/backend/routers/auth.py): `backend/routers/auth.py`
- [SKU routes](https://github.com/atharvpatil8147/nexcart-scm/blob/main/backend/routers/skus.py): `backend/routers/skus.py`
- [Disruption routes](https://github.com/atharvpatil8147/nexcart-scm/blob/main/backend/routers/disruptions.py): `backend/routers/disruptions.py`
- [Signal routes](https://github.com/atharvpatil8147/nexcart-scm/blob/main/backend/routers/signals.py): `backend/routers/signals.py`
- [Nudge routes](https://github.com/atharvpatil8147/nexcart-scm/blob/main/backend/routers/nudges.py): `backend/routers/nudges.py`
- [Dashboard routes](https://github.com/atharvpatil8147/nexcart-scm/blob/main/backend/routers/dashboard.py): `backend/routers/dashboard.py`
- [Assistant routes](https://github.com/atharvpatil8147/nexcart-scm/blob/main/backend/routers/assistant.py): `backend/routers/assistant.py`
- [Tokens and RBAC](https://github.com/atharvpatil8147/nexcart-scm/blob/main/backend/security.py): `backend/security.py`
- [Permission rules](https://github.com/atharvpatil8147/nexcart-scm/blob/main/backend/permissions.py): `backend/permissions.py`

### Risk intelligence

- [Disruption agent](https://github.com/atharvpatil8147/nexcart-scm/blob/main/backend/agents/disruption_agent.py): `backend/agents/disruption_agent.py`
- [Risk scoring](https://github.com/atharvpatil8147/nexcart-scm/blob/main/backend/utils/risk_scorer.py): `backend/utils/risk_scorer.py`
- [News signals](https://github.com/atharvpatil8147/nexcart-scm/blob/main/backend/services/news_service.py): `backend/services/news_service.py`
- [Weather signals](https://github.com/atharvpatil8147/nexcart-scm/blob/main/backend/services/weather_service.py): `backend/services/weather_service.py`
- [Shipping signals](https://github.com/atharvpatil8147/nexcart-scm/blob/main/backend/services/shipping_service.py): `backend/services/shipping_service.py`

### Customer recovery

- [Personalization agent](https://github.com/atharvpatil8147/nexcart-scm/blob/main/backend/agents/nudge_agent.py): `backend/agents/nudge_agent.py`
- [LLM providers](https://github.com/atharvpatil8147/nexcart-scm/blob/main/backend/services/llm_provider.py): `backend/services/llm_provider.py`
- [Operations assistant](https://github.com/atharvpatil8147/nexcart-scm/blob/main/backend/services/assistant_service.py): `backend/services/assistant_service.py`
- [Customer notifications](https://github.com/atharvpatil8147/nexcart-scm/blob/main/backend/services/notification.py): `backend/services/notification.py`

### Persistence and integrations

- [MongoDB](https://github.com/atharvpatil8147/nexcart-scm/blob/main/backend/database/connection.py): `backend/database/connection.py`
- [Domain models](https://github.com/atharvpatil8147/nexcart-scm/blob/main/backend/database/models.py): `backend/database/models.py`
- [Collection definitions](https://github.com/atharvpatil8147/nexcart-scm/blob/main/backend/database/collections.py): `backend/database/collections.py`
- [Audit logging](https://github.com/atharvpatil8147/nexcart-scm/blob/main/backend/audit.py): `backend/audit.py`
- [EventBridge](https://github.com/atharvpatil8147/nexcart-scm/blob/main/backend/services/eventbridge.py): `backend/services/eventbridge.py`

### Other components

- **Operations user**
- **News, weather, shipping**
- **Push and email**
- **Groq and Gemini**

## Connections

- Operations user → Role workspaces: uses (evidence: `frontend/src/App.jsx`)
- Role workspaces → Session context: provides session (evidence: `frontend/src/App.jsx`)
- Role workspaces → SKU risk view: routes to (evidence: `frontend/src/App.jsx`)
- Role workspaces → Role dashboards: routes to (evidence: `frontend/src/App.jsx`)
- SKU risk view → API client: requests data (evidence: `frontend/src/pages/SKURisk.jsx`)
- Role dashboards → API client: requests data (evidence: `frontend/src/pages/RoleWorkspaces.jsx`)
- Assistant widget → API client: sends questions (evidence: `frontend/src/components/AssistantWidget.jsx`)
- Session context → API client: checks session (evidence: `frontend/src/auth/AuthContext.jsx`)
- API client → FastAPI application: HTTP requests (evidence: `frontend/src/api/client.js`)
- FastAPI application → Authentication routes: mounts routes (evidence: `backend/main.py`)
- FastAPI application → SKU routes: mounts routes (evidence: `backend/main.py`)
- FastAPI application → Disruption routes: mounts routes (evidence: `backend/main.py`)
- FastAPI application → Signal routes: mounts routes (evidence: `backend/main.py`)
- FastAPI application → Nudge routes: mounts routes (evidence: `backend/main.py`)
- FastAPI application → Dashboard routes: mounts routes (evidence: `backend/main.py`)
- FastAPI application → Assistant routes: mounts routes (evidence: `backend/main.py`)
- Authentication routes → Tokens and RBAC: uses tokens (evidence: `backend/routers/auth.py`)
- FastAPI application → Tokens and RBAC: checks requests (evidence: `backend/main.py`)
- Tokens and RBAC → Permission rules: checks roles (evidence: `backend/security.py`)
- News, weather, shipping → Disruption agent: provides signals (evidence: `README.md`)
- Disruption agent → News signals: collects signals (evidence: `backend/agents/disruption_agent.py`)
- Disruption agent → Weather signals: collects signals (evidence: `backend/agents/disruption_agent.py`)
- Disruption agent → Shipping signals: collects signals (evidence: `backend/agents/disruption_agent.py`)
- Disruption agent → LLM providers: analyzes risk (evidence: `backend/agents/disruption_agent.py`)
- Disruption agent → MongoDB: updates records (evidence: `backend/agents/disruption_agent.py`)
- Disruption agent → EventBridge: publishes events (evidence: `backend/agents/disruption_agent.py`)
- SKU routes → Risk scoring: scores risk (evidence: `backend/routers/skus.py`)
- Nudge routes → Personalization agent: runs campaign (evidence: `backend/routers/nudges.py`)
- Personalization agent → LLM providers: generates copy (evidence: `backend/agents/nudge_agent.py`)
- Groq and Gemini → LLM providers: model requests (evidence: `README.md`)
- Personalization agent → Customer notifications: dispatches nudges (evidence: `backend/agents/nudge_agent.py`)
- Customer notifications → Push and email: sends messages (evidence: `README.md`)
- Assistant routes → Operations assistant: handles questions (evidence: `backend/routers/assistant.py`)
- Operations assistant → LLM providers: uses model (evidence: `backend/services/assistant_service.py`)
- SKU routes → MongoDB: reads and writes (evidence: `backend/routers/skus.py`)
- Disruption routes → MongoDB: reads records (evidence: `backend/routers/disruptions.py`)
- Signal routes → MongoDB: reads records (evidence: `backend/routers/signals.py`)
- Nudge routes → MongoDB: reads and writes (evidence: `backend/routers/nudges.py`)
- Dashboard routes → MongoDB: reads metrics (evidence: `backend/routers/dashboard.py`)
- MongoDB → Collection definitions: uses names (evidence: `backend/database/connection.py`)
- SKU routes → Domain models: validates data (evidence: `backend/routers/skus.py`)
- Disruption routes → Domain models: validates data (evidence: `backend/routers/disruptions.py`)
- Signal routes → Domain models: validates data (evidence: `backend/routers/signals.py`)
- Nudge routes → Domain models: validates data (evidence: `backend/routers/nudges.py`)
- Authentication routes → Audit logging: records actions (evidence: `backend/routers/auth.py`)
- Disruption routes → Audit logging: records actions (evidence: `backend/routers/disruptions.py`)
- Nudge routes → Audit logging: records actions (evidence: `backend/routers/nudges.py`)
