# rnrinfo2014/garments-erp-api architecture

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

- Interactive diagram: https://gitdiagram.com/rnrinfo2014/garments-erp-api
- Repository: https://github.com/rnrinfo2014/garments-erp-api

## Overview

Garments ERP API serves business-management and accounting workflows, with sales billing as the clearest end-to-end path: a client submits a bill request, the sales route validates and calculates it, and the application persists sales records. Purchase, returns, supplier payments, master data, and ledger operations form related capabilities. The source excerpts show application startup, sales calculations, authentication dependencies, and database setup; several business subsystems are represented from README claims and the source index, so their internal links are limited to documented or indexed references.

Main entry points: [`routes/sales.py`](https://github.com/rnrinfo2014/garments-erp-api/blob/main/routes/sales.py) (Sales API), [`utils/sales_calculator.py`](https://github.com/rnrinfo2014/garments-erp-api/blob/main/utils/sales_calculator.py) (Sales Calculations), [`database.py`](https://github.com/rnrinfo2014/garments-erp-api/blob/main/database.py) (Database Session), [`main.py`](https://github.com/rnrinfo2014/garments-erp-api/blob/main/main.py) (FastAPI App)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and Security"]
  node_app["FastAPI App<br/>[main.py]"]
  node_routes["API Routes<br/>[__init__.py]"]
  node_authdeps["Auth Dependencies<br/>[dependencies.py]"]
  node_auth["JWT Security<br/>[auth.py]"]
end

subgraph group_sales["Sales Billing"]
  node_salesroute["Sales API<br/>[sales.py]"]
  node_salescalc["Sales Calculations"]
  node_salesschema["Sales Schemas<br/>[sales.py]"]
  node_salesmodel["Sales Records<br/>[sales.py]"]
  node_billbooks["Bill Books<br/>[bill_book.py]"]
end

subgraph group_operations["Business Operations"]
  node_products["Products and Stock"]
  node_purchases["Purchases and Orders<br/>[purchase.py]"]
  node_returns["Purchase Returns<br/>[purchase_return.py]"]
  node_supplierpay["Supplier Payments"]
  node_masters["Business Masters<br/>[customers.py]"]
end

subgraph group_core["Data and Finance"]
  node_ledger["Financial Ledger"]
  node_dbsession["Database Session<br/>[database.py]"]
  node_store[("Relational Database")]
  node_seed["Initial Data<br/>[seed.py]"]
end

node_client(("API Client"))

node_client -->|"sends requests"| node_app
node_app -->|"registers routes"| node_routes
node_app -->|"initializes data"| node_seed
node_routes -.->|"dispatches sales"| node_salesroute
node_salesroute -->|"calculates bills"| node_salescalc
node_salesroute -->|"validates requests"| node_salesschema
node_salescalc -->|"creates transactions"| node_salesmodel
node_salescalc -->|"checks numbering"| node_billbooks
node_salescalc -->|"validates items"| node_products
node_salesroute -->|"queries records"| node_salesmodel
node_salesroute -->|"requires identity"| node_authdeps
node_authdeps -->|"verifies tokens"| node_auth
node_authdeps -->|"loads user"| node_dbsession
node_purchases -->|"opens sessions"| node_dbsession
node_purchases -.->|"records transactions"| node_ledger
node_returns -->|"opens sessions"| node_dbsession
node_returns -.->|"records transactions"| node_ledger
node_supplierpay -->|"updates ledger"| node_ledger
node_dbsession -->|"persists records"| node_store
node_seed -->|"creates tables"| node_store
node_salesroute -->|"uses customer data"| node_masters

click node_app "https://github.com/rnrinfo2014/garments-erp-api/blob/main/main.py"
click node_routes "https://github.com/rnrinfo2014/garments-erp-api/blob/main/routes/__init__.py"
click node_authdeps "https://github.com/rnrinfo2014/garments-erp-api/blob/main/dependencies.py"
click node_auth "https://github.com/rnrinfo2014/garments-erp-api/blob/main/auth.py"
click node_salesroute "https://github.com/rnrinfo2014/garments-erp-api/blob/main/routes/sales.py"
click node_salescalc "https://github.com/rnrinfo2014/garments-erp-api/blob/main/utils/sales_calculator.py"
click node_salesschema "https://github.com/rnrinfo2014/garments-erp-api/blob/main/schemas/sales.py"
click node_salesmodel "https://github.com/rnrinfo2014/garments-erp-api/blob/main/models/sales.py"
click node_billbooks "https://github.com/rnrinfo2014/garments-erp-api/blob/main/models/bill_book.py"
click node_products "https://github.com/rnrinfo2014/garments-erp-api/blob/main/models/product_management.py"
click node_purchases "https://github.com/rnrinfo2014/garments-erp-api/blob/main/routes/purchase.py"
click node_returns "https://github.com/rnrinfo2014/garments-erp-api/blob/main/routes/purchase_return.py"
click node_supplierpay "https://github.com/rnrinfo2014/garments-erp-api/blob/main/routes/supplier_payment_old.py"
click node_masters "https://github.com/rnrinfo2014/garments-erp-api/blob/main/models/customers.py"
click node_ledger "https://github.com/rnrinfo2014/garments-erp-api/blob/main/models/ledger_transaction.py"
click node_dbsession "https://github.com/rnrinfo2014/garments-erp-api/blob/main/database.py"
click node_seed "https://github.com/rnrinfo2014/garments-erp-api/blob/main/seed.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_routes,node_authdeps,node_auth,node_client toneBlue
class node_salesroute,node_salescalc,node_salesschema,node_salesmodel,node_billbooks toneAmber
class node_products,node_purchases,node_returns,node_supplierpay,node_masters toneMint
class node_ledger,node_dbsession,node_store,node_seed toneRose
```

## Components

### API and Security

- [FastAPI App](https://github.com/rnrinfo2014/garments-erp-api/blob/main/main.py): `main.py`
- [API Routes](https://github.com/rnrinfo2014/garments-erp-api/blob/main/routes/__init__.py): `routes/__init__.py`
- [Auth Dependencies](https://github.com/rnrinfo2014/garments-erp-api/blob/main/dependencies.py): `dependencies.py`
- [JWT Security](https://github.com/rnrinfo2014/garments-erp-api/blob/main/auth.py): `auth.py`

### Sales Billing

- [Sales API](https://github.com/rnrinfo2014/garments-erp-api/blob/main/routes/sales.py): `routes/sales.py`
- [Sales Calculations](https://github.com/rnrinfo2014/garments-erp-api/blob/main/utils/sales_calculator.py): `utils/sales_calculator.py`
- [Sales Schemas](https://github.com/rnrinfo2014/garments-erp-api/blob/main/schemas/sales.py): `schemas/sales.py`
- [Sales Records](https://github.com/rnrinfo2014/garments-erp-api/blob/main/models/sales.py): `models/sales.py`
- [Bill Books](https://github.com/rnrinfo2014/garments-erp-api/blob/main/models/bill_book.py): `models/bill_book.py`

### Business Operations

- [Products and Stock](https://github.com/rnrinfo2014/garments-erp-api/blob/main/models/product_management.py): `models/product_management.py`
- [Purchases and Orders](https://github.com/rnrinfo2014/garments-erp-api/blob/main/routes/purchase.py): `routes/purchase.py`
- [Purchase Returns](https://github.com/rnrinfo2014/garments-erp-api/blob/main/routes/purchase_return.py): `routes/purchase_return.py`
- [Supplier Payments](https://github.com/rnrinfo2014/garments-erp-api/blob/main/routes/supplier_payment_old.py): `routes/supplier_payment_old.py`
- [Business Masters](https://github.com/rnrinfo2014/garments-erp-api/blob/main/models/customers.py): `models/customers.py`

### Data and Finance

- [Financial Ledger](https://github.com/rnrinfo2014/garments-erp-api/blob/main/models/ledger_transaction.py): `models/ledger_transaction.py`
- [Database Session](https://github.com/rnrinfo2014/garments-erp-api/blob/main/database.py): `database.py`
- **Relational Database**
- [Initial Data](https://github.com/rnrinfo2014/garments-erp-api/blob/main/seed.py): `seed.py`

### Other components

- **API Client**

## Connections

- API Client → FastAPI App: sends requests
- FastAPI App → API Routes: registers routes (evidence: `main.py`)
- FastAPI App → Initial Data: initializes data (evidence: `main.py`)
- API Routes → Sales API: dispatches sales
- Sales API → Sales Calculations: calculates bills (evidence: `routes/sales.py`)
- Sales API → Sales Schemas: validates requests (evidence: `routes/sales.py`)
- Sales Calculations → Sales Records: creates transactions (evidence: `utils/sales_calculator.py`)
- Sales Calculations → Bill Books: checks numbering (evidence: `utils/sales_calculator.py`)
- Sales Calculations → Products and Stock: validates items (evidence: `utils/sales_calculator.py`)
- Sales API → Sales Records: queries records (evidence: `routes/sales.py`)
- Sales API → Auth Dependencies: requires identity (evidence: `dependencies.py`)
- Auth Dependencies → JWT Security: verifies tokens (evidence: `dependencies.py`)
- Auth Dependencies → Database Session: loads user (evidence: `dependencies.py`)
- Purchases and Orders → Database Session: opens sessions (evidence: `routes/purchase.py`)
- Purchases and Orders → Financial Ledger: records transactions (evidence: `routes/purchase.py`)
- Purchase Returns → Database Session: opens sessions (evidence: `routes/purchase_return.py`)
- Purchase Returns → Financial Ledger: records transactions (evidence: `routes/purchase_return.py`)
- Supplier Payments → Financial Ledger: updates ledger (evidence: `routes/supplier_payment_old.py`)
- Database Session → Relational Database: persists records (evidence: `database.py`)
- Initial Data → Relational Database: creates tables (evidence: `seed.py`)
- Sales API → Business Masters: uses customer data (evidence: `routes/sales.py`)
