# jasraj1111/swiggy-instamart-agent architecture

> Architecture diagram of the GitHub repository jasraj1111/swiggy-instamart-agent, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jasraj1111/swiggy-instamart-agent
- Repository: https://github.com/jasraj1111/swiggy-instamart-agent

## Overview

SmartCart AI is an autonomous grocery-reordering product, but the checked-in runtime is an early FastAPI foundation: account authentication and preference management work, while purchase-history and prediction endpoints are stubs. The README describes later consumption analysis, depletion forecasting, agent orchestration, reorder execution, and Swiggy MCP integration; these are shown as planned capabilities, not implemented flows. Source excerpts support the authentication, settings, and API wiring shown below. Planned-stage links follow the README architecture; frontend/API wiring and external grocery execution are not evidenced in source, so are marked unverified.

Main entry points: [`backend/main.py`](https://github.com/jasraj1111/swiggy-instamart-agent/blob/main/backend/main.py) (FastAPI application), [`backend/services/auth_service.py`](https://github.com/jasraj1111/swiggy-instamart-agent/blob/main/backend/services/auth_service.py) (Authentication service), [`backend/api/deps.py`](https://github.com/jasraj1111/swiggy-instamart-agent/blob/main/backend/api/deps.py) (Current-user dependency), [`backend/models/models.py`](https://github.com/jasraj1111/swiggy-instamart-agent/blob/main/backend/models/models.py) (Domain data models)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and user access"]
  node_frontend["Web frontend"]
  node_app["FastAPI application<br/>[main.py]"]
  node_config["Application configuration<br/>[config.py]"]
end

subgraph group_identity["Identity and preferences"]
  node_auth_routes["Authentication routes<br/>[auth.py]"]
  node_auth_service["Authentication service<br/>[auth_service.py]"]
  node_security["Password and JWT security<br/>[security.py]"]
  node_auth_schemas["Authentication schemas<br/>[auth.py]"]
  node_auth_deps["Current-user dependency<br/>[deps.py]"]
  node_settings_routes["Preference settings<br/>[settings.py]"]
  node_user_schemas["User schemas<br/>[user.py]"]
  node_models["Domain data models<br/>[models.py]"]
  node_db_sessions["Async database sessions<br/>[session.py]"]
end

subgraph group_intelligence["Grocery intelligence"]
  node_history_routes["Purchase history API<br/>[history.py]"]
  node_prediction_routes["Prediction API<br/>[predictions.py]"]
  node_consumption["Consumption analysis"]
  node_prediction_engine["Depletion forecasting"]
end

subgraph group_reordering["Reorder execution"]
  node_agent["LangGraph agent"]
  node_tool_layer["Tool execution layer"]
  node_reorder["Autonomous reorder logic"]
  node_swiggy["Swiggy MCP / mock tools"]
end

node_user(("SmartCart user"))
node_postgres[("PostgreSQL")]
node_grocery_service["Grocery service"]

node_user -.->|"uses"| node_frontend
node_frontend -.->|"calls API"| node_app
node_app -->|"loads settings"| node_config
node_app -->|"registers router"| node_auth_routes
node_app -->|"registers router"| node_history_routes
node_app -->|"registers router"| node_prediction_routes
node_app -->|"registers router"| node_settings_routes
node_auth_routes -->|"calls"| node_auth_service
node_auth_routes -->|"uses"| node_auth_schemas
node_auth_service -->|"hashes and signs"| node_security
node_auth_service -->|"queries and creates"| node_models
node_auth_service -->|"returns responses"| node_auth_schemas
node_auth_deps -->|"decodes token"| node_security
node_auth_deps -->|"looks up user"| node_auth_service
node_history_routes -->|"requires user"| node_auth_deps
node_history_routes -->|"references user model"| node_models
node_prediction_routes -->|"requires user"| node_auth_deps
node_prediction_routes -->|"references user model"| node_models
node_settings_routes -->|"requires user"| node_auth_deps
node_settings_routes -->|"reads and updates"| node_models
node_settings_routes -->|"validates preferences"| node_user_schemas
node_db_sessions -->|"reads database URL"| node_config
node_models -->|"uses ORM base"| node_db_sessions
node_db_sessions -.->|"opens sessions"| node_postgres
node_history_routes -.->|"planned input"| node_consumption
node_consumption -->|"feeds forecasts"| node_prediction_engine
node_prediction_engine -->|"supplies predictions"| node_agent
node_agent -->|"dispatches tools"| node_tool_layer
node_tool_layer -->|"invokes integration"| node_swiggy
node_agent -.->|"supports automation"| node_reorder
node_reorder -.->|"executes reorder"| node_grocery_service

click node_frontend "https://github.com/jasraj1111/swiggy-instamart-agent/tree/main/frontend"
click node_app "https://github.com/jasraj1111/swiggy-instamart-agent/blob/main/backend/main.py"
click node_auth_routes "https://github.com/jasraj1111/swiggy-instamart-agent/blob/main/backend/api/routes/auth.py"
click node_auth_service "https://github.com/jasraj1111/swiggy-instamart-agent/blob/main/backend/services/auth_service.py"
click node_security "https://github.com/jasraj1111/swiggy-instamart-agent/blob/main/backend/utils/security.py"
click node_auth_schemas "https://github.com/jasraj1111/swiggy-instamart-agent/blob/main/backend/schemas/auth.py"
click node_auth_deps "https://github.com/jasraj1111/swiggy-instamart-agent/blob/main/backend/api/deps.py"
click node_settings_routes "https://github.com/jasraj1111/swiggy-instamart-agent/blob/main/backend/api/routes/settings.py"
click node_user_schemas "https://github.com/jasraj1111/swiggy-instamart-agent/blob/main/backend/schemas/user.py"
click node_history_routes "https://github.com/jasraj1111/swiggy-instamart-agent/blob/main/backend/api/routes/history.py"
click node_prediction_routes "https://github.com/jasraj1111/swiggy-instamart-agent/blob/main/backend/api/routes/predictions.py"
click node_consumption "https://github.com/jasraj1111/swiggy-instamart-agent/tree/main/backend"
click node_prediction_engine "https://github.com/jasraj1111/swiggy-instamart-agent/tree/main/backend"
click node_agent "https://github.com/jasraj1111/swiggy-instamart-agent/tree/main/backend"
click node_tool_layer "https://github.com/jasraj1111/swiggy-instamart-agent/tree/main/backend"
click node_reorder "https://github.com/jasraj1111/swiggy-instamart-agent/tree/main/backend"
click node_swiggy "https://github.com/jasraj1111/swiggy-instamart-agent/tree/main/backend"
click node_models "https://github.com/jasraj1111/swiggy-instamart-agent/blob/main/backend/models/models.py"
click node_db_sessions "https://github.com/jasraj1111/swiggy-instamart-agent/blob/main/backend/database/session.py"
click node_config "https://github.com/jasraj1111/swiggy-instamart-agent/blob/main/backend/config.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_app,node_config,node_user toneBlue
class node_auth_routes,node_auth_service,node_security,node_auth_schemas,node_auth_deps,node_settings_routes,node_user_schemas,node_models,node_db_sessions,node_postgres toneAmber
class node_history_routes,node_prediction_routes,node_consumption,node_prediction_engine toneMint
class node_agent,node_tool_layer,node_reorder,node_swiggy toneRose
class node_grocery_service toneIndigo
```

## Components

### API and user access

- [Web frontend](https://github.com/jasraj1111/swiggy-instamart-agent/tree/main/frontend): `frontend`
- [FastAPI application](https://github.com/jasraj1111/swiggy-instamart-agent/blob/main/backend/main.py): `backend/main.py`
- [Application configuration](https://github.com/jasraj1111/swiggy-instamart-agent/blob/main/backend/config.py): `backend/config.py`

### Identity and preferences

- [Authentication routes](https://github.com/jasraj1111/swiggy-instamart-agent/blob/main/backend/api/routes/auth.py): `backend/api/routes/auth.py`
- [Authentication service](https://github.com/jasraj1111/swiggy-instamart-agent/blob/main/backend/services/auth_service.py): `backend/services/auth_service.py`
- [Password and JWT security](https://github.com/jasraj1111/swiggy-instamart-agent/blob/main/backend/utils/security.py): `backend/utils/security.py`
- [Authentication schemas](https://github.com/jasraj1111/swiggy-instamart-agent/blob/main/backend/schemas/auth.py): `backend/schemas/auth.py`
- [Current-user dependency](https://github.com/jasraj1111/swiggy-instamart-agent/blob/main/backend/api/deps.py): `backend/api/deps.py`
- [Preference settings](https://github.com/jasraj1111/swiggy-instamart-agent/blob/main/backend/api/routes/settings.py): `backend/api/routes/settings.py`
- [User schemas](https://github.com/jasraj1111/swiggy-instamart-agent/blob/main/backend/schemas/user.py): `backend/schemas/user.py`
- [Domain data models](https://github.com/jasraj1111/swiggy-instamart-agent/blob/main/backend/models/models.py): `backend/models/models.py`
- [Async database sessions](https://github.com/jasraj1111/swiggy-instamart-agent/blob/main/backend/database/session.py): `backend/database/session.py`

### Grocery intelligence

- [Purchase history API](https://github.com/jasraj1111/swiggy-instamart-agent/blob/main/backend/api/routes/history.py): `backend/api/routes/history.py`
- [Prediction API](https://github.com/jasraj1111/swiggy-instamart-agent/blob/main/backend/api/routes/predictions.py): `backend/api/routes/predictions.py`
- [Consumption analysis](https://github.com/jasraj1111/swiggy-instamart-agent/tree/main/backend): `backend`
- [Depletion forecasting](https://github.com/jasraj1111/swiggy-instamart-agent/tree/main/backend): `backend`

### Reorder execution

- [LangGraph agent](https://github.com/jasraj1111/swiggy-instamart-agent/tree/main/backend): `backend`
- [Tool execution layer](https://github.com/jasraj1111/swiggy-instamart-agent/tree/main/backend): `backend`
- [Autonomous reorder logic](https://github.com/jasraj1111/swiggy-instamart-agent/tree/main/backend): `backend`
- [Swiggy MCP / mock tools](https://github.com/jasraj1111/swiggy-instamart-agent/tree/main/backend): `backend`

### Other components

- **SmartCart user**
- **PostgreSQL**
- **Grocery service**

## Connections

- SmartCart user → Web frontend: uses
- Web frontend → FastAPI application: calls API
- FastAPI application → Application configuration: loads settings (evidence: `backend/main.py`)
- FastAPI application → Authentication routes: registers router (evidence: `backend/main.py`)
- FastAPI application → Purchase history API: registers router (evidence: `backend/main.py`)
- FastAPI application → Prediction API: registers router (evidence: `backend/main.py`)
- FastAPI application → Preference settings: registers router (evidence: `backend/main.py`)
- Authentication routes → Authentication service: calls (evidence: `backend/api/routes/auth.py`)
- Authentication routes → Authentication schemas: uses (evidence: `backend/api/routes/auth.py`)
- Authentication service → Password and JWT security: hashes and signs (evidence: `backend/services/auth_service.py`)
- Authentication service → Domain data models: queries and creates (evidence: `backend/services/auth_service.py`)
- Authentication service → Authentication schemas: returns responses (evidence: `backend/services/auth_service.py`)
- Current-user dependency → Password and JWT security: decodes token (evidence: `backend/api/deps.py`)
- Current-user dependency → Authentication service: looks up user (evidence: `backend/api/deps.py`)
- Purchase history API → Current-user dependency: requires user (evidence: `backend/api/routes/history.py`)
- Purchase history API → Domain data models: references user model (evidence: `backend/api/routes/history.py`)
- Prediction API → Current-user dependency: requires user (evidence: `backend/api/routes/predictions.py`)
- Prediction API → Domain data models: references user model (evidence: `backend/api/routes/predictions.py`)
- Preference settings → Current-user dependency: requires user (evidence: `backend/api/routes/settings.py`)
- Preference settings → Domain data models: reads and updates (evidence: `backend/api/routes/settings.py`)
- Preference settings → User schemas: validates preferences (evidence: `backend/api/routes/settings.py`)
- Async database sessions → Application configuration: reads database URL (evidence: `backend/database/session.py`)
- Domain data models → Async database sessions: uses ORM base (evidence: `backend/models/models.py`)
- Async database sessions → PostgreSQL: opens sessions
- Purchase history API → Consumption analysis: planned input (evidence: `README.md`)
- Consumption analysis → Depletion forecasting: feeds forecasts (evidence: `README.md`)
- Depletion forecasting → LangGraph agent: supplies predictions (evidence: `README.md`)
- LangGraph agent → Tool execution layer: dispatches tools (evidence: `README.md`)
- Tool execution layer → Swiggy MCP / mock tools: invokes integration (evidence: `README.md`)
- LangGraph agent → Autonomous reorder logic: supports automation (evidence: `README.md`)
- Autonomous reorder logic → Grocery service: executes reorder
