# aisolutions-hash/erp-system architecture

> Architecture diagram of the GitHub repository aisolutions-hash/erp-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aisolutions-hash/erp-system
- Repository: https://github.com/aisolutions-hash/erp-system

## Overview

Kalika Enterprises ERP manages manufacturing and B2B trading from source-report ingestion through procurement, stock, production, orders, dispatch, and reporting. The principal user workflow is to sign in, use the React pages to manage business records through FastAPI, and read results persisted in PostgreSQL. README documentation describes the GCS Excel migration and core business flows; sampled code confirms frontend authentication, API routing, and shared stock accounting. Some router-to-service wiring is not sampled, so those links are limited to documented flows.

Main entry points: [`backend/app/routers`](https://github.com/aisolutions-hash/erp-system/tree/master/backend/app/routers) (Domain routers), [`backend/app/services/stock_service.py`](https://github.com/aisolutions-hash/erp-system/blob/master/backend/app/services/stock_service.py) (Stock accounting), [`backend/app/main.py`](https://github.com/aisolutions-hash/erp-system/blob/master/backend/app/main.py) (FastAPI application), [`backend/app/services/migration.py`](https://github.com/aisolutions-hash/erp-system/blob/master/backend/app/services/migration.py) (Excel migration)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["User interface"]
  node_spa["React application<br/>[App.jsx]"]
  node_auth_ui["Login state<br/>[AuthContext.jsx]"]
  node_business_pages["ERP pages"]
  node_api_client["API client<br/>[api.js]"]
end

subgraph group_api["API and identity"]
  node_fastapi["FastAPI application<br/>[main.py]"]
  node_auth_routes["Authentication routes<br/>[auth.py]"]
  node_domain_routes["Domain routers"]
  node_db_session["Database sessions<br/>[database.py]"]
end

subgraph group_operations["Business operations"]
  node_procurement["Purchases and materials"]
  node_inventory["Inventory and stock flow"]
  node_stock_engine["Stock accounting<br/>[stock_service.py]"]
  node_manufacturing["Production and BOM"]
  node_sales_dispatch["Orders and dispatch"]
  node_planning["Planning and fulfilment"]
  node_insights["Dashboard and reports"]
end

subgraph group_ingestion["Data ingestion"]
  node_gcs_client["GCS download service<br/>[gcs.py]"]
  node_migration["Excel migration<br/>[migration.py]"]
end

node_staff(("ERP user"))
node_postgres[("ERP database")]
node_gcs["Google Cloud Storage"]
node_smtp["SMTP service"]

node_staff -->|"uses"| node_spa
node_spa -->|"hosts"| node_auth_ui
node_auth_ui -->|"requests login"| node_api_client
node_business_pages -->|"requests data"| node_api_client
node_api_client -->|"calls API"| node_fastapi
node_fastapi -->|"dispatches"| node_auth_routes
node_fastapi -->|"dispatches"| node_domain_routes
node_auth_routes -->|"uses sessions"| node_db_session
node_domain_routes -->|"uses sessions"| node_db_session
node_db_session -->|"reads and writes"| node_postgres
node_domain_routes -->|"routes procurement"| node_procurement
node_domain_routes -->|"routes stock"| node_inventory
node_domain_routes -->|"routes production"| node_manufacturing
node_domain_routes -->|"routes orders"| node_sales_dispatch
node_domain_routes -->|"routes planning"| node_planning
node_domain_routes -->|"routes reports"| node_insights
node_procurement -->|"records receipts"| node_stock_engine
node_manufacturing -->|"records output"| node_stock_engine
node_sales_dispatch -->|"records dispatch"| node_stock_engine
node_inventory -->|"records movements"| node_stock_engine
node_staff -.->|"initiates import"| node_migration
node_migration -->|"downloads report"| node_gcs_client
node_gcs_client -->|"reads workbook"| node_gcs
node_migration -->|"loads records"| node_postgres
node_sales_dispatch -.->|"optional email"| node_smtp

click node_spa "https://github.com/aisolutions-hash/erp-system/blob/master/frontend/src/App.jsx"
click node_auth_ui "https://github.com/aisolutions-hash/erp-system/blob/master/frontend/src/context/AuthContext.jsx"
click node_business_pages "https://github.com/aisolutions-hash/erp-system/tree/master/frontend/src/pages"
click node_api_client "https://github.com/aisolutions-hash/erp-system/blob/master/frontend/src/lib/api.js"
click node_fastapi "https://github.com/aisolutions-hash/erp-system/blob/master/backend/app/main.py"
click node_auth_routes "https://github.com/aisolutions-hash/erp-system/blob/master/backend/app/routers/auth.py"
click node_domain_routes "https://github.com/aisolutions-hash/erp-system/tree/master/backend/app/routers"
click node_db_session "https://github.com/aisolutions-hash/erp-system/blob/master/backend/app/database.py"
click node_procurement "https://github.com/aisolutions-hash/erp-system/tree/master/backend/app/routers"
click node_inventory "https://github.com/aisolutions-hash/erp-system/tree/master/backend/app/routers"
click node_stock_engine "https://github.com/aisolutions-hash/erp-system/blob/master/backend/app/services/stock_service.py"
click node_manufacturing "https://github.com/aisolutions-hash/erp-system/tree/master/backend/app/routers"
click node_sales_dispatch "https://github.com/aisolutions-hash/erp-system/tree/master/backend/app/routers"
click node_planning "https://github.com/aisolutions-hash/erp-system/tree/master/backend/app/routers"
click node_insights "https://github.com/aisolutions-hash/erp-system/tree/master/backend/app/routers"
click node_gcs_client "https://github.com/aisolutions-hash/erp-system/blob/master/backend/app/services/gcs.py"
click node_migration "https://github.com/aisolutions-hash/erp-system/blob/master/backend/app/services/migration.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_spa,node_auth_ui,node_business_pages,node_api_client,node_staff toneBlue
class node_fastapi,node_auth_routes,node_domain_routes,node_db_session,node_postgres,node_gcs toneAmber
class node_procurement,node_inventory,node_stock_engine,node_manufacturing,node_sales_dispatch,node_planning,node_insights toneMint
class node_gcs_client,node_migration toneRose
class node_smtp toneIndigo
```

## Components

### User interface

- [React application](https://github.com/aisolutions-hash/erp-system/blob/master/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Login state](https://github.com/aisolutions-hash/erp-system/blob/master/frontend/src/context/AuthContext.jsx): `frontend/src/context/AuthContext.jsx`
- [ERP pages](https://github.com/aisolutions-hash/erp-system/tree/master/frontend/src/pages): `frontend/src/pages`
- [API client](https://github.com/aisolutions-hash/erp-system/blob/master/frontend/src/lib/api.js): `frontend/src/lib/api.js`

### API and identity

- [FastAPI application](https://github.com/aisolutions-hash/erp-system/blob/master/backend/app/main.py): `backend/app/main.py`
- [Authentication routes](https://github.com/aisolutions-hash/erp-system/blob/master/backend/app/routers/auth.py): `backend/app/routers/auth.py`
- [Domain routers](https://github.com/aisolutions-hash/erp-system/tree/master/backend/app/routers): `backend/app/routers`
- [Database sessions](https://github.com/aisolutions-hash/erp-system/blob/master/backend/app/database.py): `backend/app/database.py`

### Business operations

- [Purchases and materials](https://github.com/aisolutions-hash/erp-system/tree/master/backend/app/routers): `backend/app/routers`
- [Inventory and stock flow](https://github.com/aisolutions-hash/erp-system/tree/master/backend/app/routers): `backend/app/routers`
- [Stock accounting](https://github.com/aisolutions-hash/erp-system/blob/master/backend/app/services/stock_service.py): `backend/app/services/stock_service.py`
- [Production and BOM](https://github.com/aisolutions-hash/erp-system/tree/master/backend/app/routers): `backend/app/routers`
- [Orders and dispatch](https://github.com/aisolutions-hash/erp-system/tree/master/backend/app/routers): `backend/app/routers`
- [Planning and fulfilment](https://github.com/aisolutions-hash/erp-system/tree/master/backend/app/routers): `backend/app/routers`
- [Dashboard and reports](https://github.com/aisolutions-hash/erp-system/tree/master/backend/app/routers): `backend/app/routers`

### Data ingestion

- [GCS download service](https://github.com/aisolutions-hash/erp-system/blob/master/backend/app/services/gcs.py): `backend/app/services/gcs.py`
- [Excel migration](https://github.com/aisolutions-hash/erp-system/blob/master/backend/app/services/migration.py): `backend/app/services/migration.py`

### Other components

- **ERP user**
- **ERP database**
- **Google Cloud Storage**
- **SMTP service**

## Connections

- ERP user → React application: uses
- React application → Login state: hosts
- Login state → API client: requests login
- ERP pages → API client: requests data
- API client → FastAPI application: calls API
- FastAPI application → Authentication routes: dispatches
- FastAPI application → Domain routers: dispatches
- Authentication routes → Database sessions: uses sessions
- Domain routers → Database sessions: uses sessions
- Database sessions → ERP database: reads and writes
- Domain routers → Purchases and materials: routes procurement
- Domain routers → Inventory and stock flow: routes stock
- Domain routers → Production and BOM: routes production
- Domain routers → Orders and dispatch: routes orders
- Domain routers → Planning and fulfilment: routes planning
- Domain routers → Dashboard and reports: routes reports
- Purchases and materials → Stock accounting: records receipts
- Production and BOM → Stock accounting: records output
- Orders and dispatch → Stock accounting: records dispatch
- Inventory and stock flow → Stock accounting: records movements
- ERP user → Excel migration: initiates import
- Excel migration → GCS download service: downloads report
- GCS download service → Google Cloud Storage: reads workbook
- Excel migration → ERP database: loads records
- Orders and dispatch → SMTP service: optional email
