# sushant-kae/invoice-generator architecture

> Architecture diagram of the GitHub repository sushant-kae/invoice-generator, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sushant-kae/invoice-generator
- Repository: https://github.com/sushant-kae/invoice-generator

## Overview

Shah Enterprises is an import/export invoice generator. Its principal workflow uploads a manufacturer invoice, extracts and normalizes line items (with OCR/manual fallback), applies internal margins, lets staff review and preview the customer-safe invoice, then saves and generates DOCX/PDF output. Separate product areas cover invoice history/dashboard, buyers, templates, and internal profit reporting. The README documents the frontend workflow; source evidence is strongest for backend routing and extraction, while unsampled frontend API wiring is not asserted.

Main entry points: [`backend/app/api/routes/invoices.py`](https://github.com/sushant-kae/invoice-generator/blob/main/backend/app/api/routes/invoices.py) (Invoice operations), [`backend/app/services/extraction/pipeline.py`](https://github.com/sushant-kae/invoice-generator/blob/main/backend/app/services/extraction/pipeline.py) (Extraction orchestrator), [`backend/app/api/routes/extract.py`](https://github.com/sushant-kae/invoice-generator/blob/main/backend/app/api/routes/extract.py) (Extract and margin API), [`backend/app/models/models.py`](https://github.com/sushant-kae/invoice-generator/blob/main/backend/app/models/models.py) (Invoice and buyer models)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Invoice Workspace"]
  node_workflow["Invoice workflow<br/>[page.tsx]"]
  node_uploadstep["Upload step<br/>[UploadStep.tsx]"]
  node_reviewstep["Review step<br/>[ReviewStep.tsx]"]
  node_previewstep["Customer preview<br/>[PreviewStep.tsx]"]
  node_donestep["Export completion<br/>[DoneStep.tsx]"]
  node_dashboard["Dashboard and profit<br/>[page.tsx]"]
  node_history["Invoice history<br/>[page.tsx]"]
  node_buyersui["Buyer directory<br/>[page.tsx]"]
  node_templatesui["Template management<br/>[page.tsx]"]
  node_profitui["Profit overview<br/>[page.tsx]"]
end

subgraph group_api["API and Business Operations"]
  node_uploadapi["Upload endpoint<br/>[upload.py]"]
  node_extractapi["Extract and margin API<br/>[extract.py]"]
  node_invoiceapi["Invoice operations<br/>[invoices.py]"]
  node_buyerapi["Buyer operations<br/>[buyers.py]"]
  node_templateapi["Template listing<br/>[templates.py]"]
end

subgraph group_extraction["Invoice Extraction"]
  node_extractpipeline["Extraction orchestrator<br/>[pipeline.py]"]
  node_pdfextract["PDF extraction<br/>[pdf_extractor.py]"]
  node_ocr["OCR fallback<br/>[ocr_extractor.py]"]
  node_normalizer["Column normalizer<br/>[normalizer.py]"]
end

subgraph group_domain["Invoice Domain and Storage"]
  node_margin["Margin and tax engine"]
  node_schemas["API data schemas<br/>[schemas.py]"]
  node_models["Invoice and buyer models<br/>[models.py]"]
  node_database[("SQL database<br/>[database.py]")]
end

subgraph group_export["Invoice Export"]
  node_docx["DOCX generator<br/>[generator.py]"]
  node_pdf["PDF converter<br/>[converter.py]"]
end

node_staff(("Staff user"))

node_staff -->|"creates invoice"| node_workflow
node_workflow -->|"starts with"| node_uploadstep
node_uploadstep -->|"uploads file"| node_uploadapi
node_uploadapi -->|"continues extraction"| node_extractapi
node_extractapi -->|"runs extraction"| node_extractpipeline
node_extractpipeline -->|"tries PDF parsing"| node_pdfextract
node_extractpipeline -->|"falls back to OCR"| node_ocr
node_pdfextract -->|"normalizes columns"| node_normalizer
node_ocr -->|"normalizes output"| node_normalizer
node_extractpipeline -->|"returns editable items"| node_reviewstep
node_reviewstep -->|"applies margin"| node_extractapi
node_extractapi -->|"calculates margins"| node_margin
node_margin -->|"uses item schemas"| node_schemas
node_reviewstep -->|"previews invoice"| node_previewstep
node_previewstep -->|"saves invoice"| node_invoiceapi
node_invoiceapi -->|"queries and persists"| node_models
node_models -->|"uses ORM base"| node_database
node_invoiceapi -->|"validates responses"| node_schemas
node_invoiceapi -->|"calculates invoice totals"| node_margin
node_invoiceapi -->|"generates DOCX"| node_docx
node_invoiceapi -->|"converts to PDF"| node_pdf
node_docx -->|"reads invoice data"| node_schemas
node_donestep -->|"requests export"| node_invoiceapi
node_staff -->|"views metrics"| node_dashboard
node_staff -->|"reviews invoices"| node_history
node_staff -->|"manages buyers"| node_buyersui
node_buyersui -.->|"uses buyer records"| node_buyerapi
node_buyerapi -->|"queries buyers"| node_models
node_staff -->|"manages templates"| node_templatesui
node_templatesui -.->|"lists templates"| node_templateapi
node_templateapi -->|"queries templates"| node_models
node_staff -->|"views internal profit"| node_profitui

click node_workflow "https://github.com/sushant-kae/invoice-generator/blob/main/frontend/src/app/new-invoice/page.tsx"
click node_uploadstep "https://github.com/sushant-kae/invoice-generator/blob/main/frontend/src/components/invoice/UploadStep.tsx"
click node_reviewstep "https://github.com/sushant-kae/invoice-generator/blob/main/frontend/src/components/invoice/ReviewStep.tsx"
click node_previewstep "https://github.com/sushant-kae/invoice-generator/blob/main/frontend/src/components/invoice/PreviewStep.tsx"
click node_donestep "https://github.com/sushant-kae/invoice-generator/blob/main/frontend/src/components/invoice/DoneStep.tsx"
click node_dashboard "https://github.com/sushant-kae/invoice-generator/blob/main/frontend/src/app/page.tsx"
click node_history "https://github.com/sushant-kae/invoice-generator/blob/main/frontend/src/app/history/page.tsx"
click node_buyersui "https://github.com/sushant-kae/invoice-generator/blob/main/frontend/src/app/buyers/page.tsx"
click node_templatesui "https://github.com/sushant-kae/invoice-generator/blob/main/frontend/src/app/templates/page.tsx"
click node_profitui "https://github.com/sushant-kae/invoice-generator/blob/main/frontend/src/app/profit/page.tsx"
click node_uploadapi "https://github.com/sushant-kae/invoice-generator/blob/main/backend/app/api/routes/upload.py"
click node_extractapi "https://github.com/sushant-kae/invoice-generator/blob/main/backend/app/api/routes/extract.py"
click node_invoiceapi "https://github.com/sushant-kae/invoice-generator/blob/main/backend/app/api/routes/invoices.py"
click node_buyerapi "https://github.com/sushant-kae/invoice-generator/blob/main/backend/app/api/routes/buyers.py"
click node_templateapi "https://github.com/sushant-kae/invoice-generator/blob/main/backend/app/api/routes/templates.py"
click node_extractpipeline "https://github.com/sushant-kae/invoice-generator/blob/main/backend/app/services/extraction/pipeline.py"
click node_pdfextract "https://github.com/sushant-kae/invoice-generator/blob/main/backend/app/services/extraction/pdf_extractor.py"
click node_ocr "https://github.com/sushant-kae/invoice-generator/blob/main/backend/app/services/extraction/ocr_extractor.py"
click node_normalizer "https://github.com/sushant-kae/invoice-generator/blob/main/backend/app/services/extraction/normalizer.py"
click node_margin "https://github.com/sushant-kae/invoice-generator/blob/main/backend/app/services/margin_calculator.py"
click node_schemas "https://github.com/sushant-kae/invoice-generator/blob/main/backend/app/schemas/schemas.py"
click node_models "https://github.com/sushant-kae/invoice-generator/blob/main/backend/app/models/models.py"
click node_database "https://github.com/sushant-kae/invoice-generator/blob/main/backend/app/db/database.py"
click node_docx "https://github.com/sushant-kae/invoice-generator/blob/main/backend/app/services/docx/generator.py"
click node_pdf "https://github.com/sushant-kae/invoice-generator/blob/main/backend/app/services/pdf/converter.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_workflow,node_uploadstep,node_reviewstep,node_previewstep,node_donestep,node_dashboard,node_history,node_buyersui,node_templatesui,node_profitui,node_staff toneBlue
class node_uploadapi,node_extractapi,node_invoiceapi,node_buyerapi,node_templateapi toneAmber
class node_extractpipeline,node_pdfextract,node_ocr,node_normalizer toneMint
class node_margin,node_schemas,node_models,node_database toneRose
class node_docx,node_pdf toneIndigo
```

## Components

### Invoice Workspace

- [Invoice workflow](https://github.com/sushant-kae/invoice-generator/blob/main/frontend/src/app/new-invoice/page.tsx): `frontend/src/app/new-invoice/page.tsx`
- [Upload step](https://github.com/sushant-kae/invoice-generator/blob/main/frontend/src/components/invoice/UploadStep.tsx): `frontend/src/components/invoice/UploadStep.tsx`
- [Review step](https://github.com/sushant-kae/invoice-generator/blob/main/frontend/src/components/invoice/ReviewStep.tsx): `frontend/src/components/invoice/ReviewStep.tsx`
- [Customer preview](https://github.com/sushant-kae/invoice-generator/blob/main/frontend/src/components/invoice/PreviewStep.tsx): `frontend/src/components/invoice/PreviewStep.tsx`
- [Export completion](https://github.com/sushant-kae/invoice-generator/blob/main/frontend/src/components/invoice/DoneStep.tsx): `frontend/src/components/invoice/DoneStep.tsx`
- [Dashboard and profit](https://github.com/sushant-kae/invoice-generator/blob/main/frontend/src/app/page.tsx): `frontend/src/app/page.tsx`
- [Invoice history](https://github.com/sushant-kae/invoice-generator/blob/main/frontend/src/app/history/page.tsx): `frontend/src/app/history/page.tsx`
- [Buyer directory](https://github.com/sushant-kae/invoice-generator/blob/main/frontend/src/app/buyers/page.tsx): `frontend/src/app/buyers/page.tsx`
- [Template management](https://github.com/sushant-kae/invoice-generator/blob/main/frontend/src/app/templates/page.tsx): `frontend/src/app/templates/page.tsx`
- [Profit overview](https://github.com/sushant-kae/invoice-generator/blob/main/frontend/src/app/profit/page.tsx): `frontend/src/app/profit/page.tsx`

### API and Business Operations

- [Upload endpoint](https://github.com/sushant-kae/invoice-generator/blob/main/backend/app/api/routes/upload.py): `backend/app/api/routes/upload.py`
- [Extract and margin API](https://github.com/sushant-kae/invoice-generator/blob/main/backend/app/api/routes/extract.py): `backend/app/api/routes/extract.py`
- [Invoice operations](https://github.com/sushant-kae/invoice-generator/blob/main/backend/app/api/routes/invoices.py): `backend/app/api/routes/invoices.py`
- [Buyer operations](https://github.com/sushant-kae/invoice-generator/blob/main/backend/app/api/routes/buyers.py): `backend/app/api/routes/buyers.py`
- [Template listing](https://github.com/sushant-kae/invoice-generator/blob/main/backend/app/api/routes/templates.py): `backend/app/api/routes/templates.py`

### Invoice Extraction

- [Extraction orchestrator](https://github.com/sushant-kae/invoice-generator/blob/main/backend/app/services/extraction/pipeline.py): `backend/app/services/extraction/pipeline.py`
- [PDF extraction](https://github.com/sushant-kae/invoice-generator/blob/main/backend/app/services/extraction/pdf_extractor.py): `backend/app/services/extraction/pdf_extractor.py`
- [OCR fallback](https://github.com/sushant-kae/invoice-generator/blob/main/backend/app/services/extraction/ocr_extractor.py): `backend/app/services/extraction/ocr_extractor.py`
- [Column normalizer](https://github.com/sushant-kae/invoice-generator/blob/main/backend/app/services/extraction/normalizer.py): `backend/app/services/extraction/normalizer.py`

### Invoice Domain and Storage

- [Margin and tax engine](https://github.com/sushant-kae/invoice-generator/blob/main/backend/app/services/margin_calculator.py): `backend/app/services/margin_calculator.py`
- [API data schemas](https://github.com/sushant-kae/invoice-generator/blob/main/backend/app/schemas/schemas.py): `backend/app/schemas/schemas.py`
- [Invoice and buyer models](https://github.com/sushant-kae/invoice-generator/blob/main/backend/app/models/models.py): `backend/app/models/models.py`
- [SQL database](https://github.com/sushant-kae/invoice-generator/blob/main/backend/app/db/database.py): `backend/app/db/database.py`

### Invoice Export

- [DOCX generator](https://github.com/sushant-kae/invoice-generator/blob/main/backend/app/services/docx/generator.py): `backend/app/services/docx/generator.py`
- [PDF converter](https://github.com/sushant-kae/invoice-generator/blob/main/backend/app/services/pdf/converter.py): `backend/app/services/pdf/converter.py`

### Other components

- **Staff user**

## Connections

- Staff user → Invoice workflow: creates invoice (evidence: `README.md`)
- Invoice workflow → Upload step: starts with (evidence: `README.md`)
- Upload step → Upload endpoint: uploads file (evidence: `README.md`)
- Upload endpoint → Extract and margin API: continues extraction (evidence: `README.md`)
- Extract and margin API → Extraction orchestrator: runs extraction (evidence: `backend/app/api/routes/extract.py`)
- Extraction orchestrator → PDF extraction: tries PDF parsing (evidence: `backend/app/services/extraction/pipeline.py`)
- Extraction orchestrator → OCR fallback: falls back to OCR (evidence: `backend/app/services/extraction/pipeline.py`)
- PDF extraction → Column normalizer: normalizes columns (evidence: `backend/app/services/extraction/pdf_extractor.py`)
- OCR fallback → Column normalizer: normalizes output (evidence: `backend/app/services/extraction/ocr_extractor.py`)
- Extraction orchestrator → Review step: returns editable items (evidence: `README.md`)
- Review step → Extract and margin API: applies margin (evidence: `README.md`)
- Extract and margin API → Margin and tax engine: calculates margins (evidence: `backend/app/api/routes/extract.py`)
- Margin and tax engine → API data schemas: uses item schemas (evidence: `backend/app/services/margin_calculator.py`)
- Review step → Customer preview: previews invoice (evidence: `README.md`)
- Customer preview → Invoice operations: saves invoice (evidence: `README.md`)
- Invoice operations → Invoice and buyer models: queries and persists (evidence: `backend/app/api/routes/invoices.py`)
- Invoice and buyer models → SQL database: uses ORM base (evidence: `backend/app/models/models.py`)
- Invoice operations → API data schemas: validates responses (evidence: `backend/app/api/routes/invoices.py`)
- Invoice operations → Margin and tax engine: calculates invoice totals (evidence: `backend/app/api/routes/invoices.py`)
- Invoice operations → DOCX generator: generates DOCX (evidence: `backend/app/api/routes/invoices.py`)
- Invoice operations → PDF converter: converts to PDF (evidence: `backend/app/api/routes/invoices.py`)
- DOCX generator → API data schemas: reads invoice data (evidence: `backend/app/services/docx/generator.py`)
- Export completion → Invoice operations: requests export (evidence: `README.md`)
- Staff user → Dashboard and profit: views metrics (evidence: `README.md`)
- Staff user → Invoice history: reviews invoices (evidence: `README.md`)
- Staff user → Buyer directory: manages buyers (evidence: `README.md`)
- Buyer directory → Buyer operations: uses buyer records
- Buyer operations → Invoice and buyer models: queries buyers (evidence: `backend/app/api/routes/buyers.py`)
- Staff user → Template management: manages templates (evidence: `README.md`)
- Template management → Template listing: lists templates
- Template listing → Invoice and buyer models: queries templates (evidence: `backend/app/api/routes/templates.py`)
- Staff user → Profit overview: views internal profit (evidence: `README.md`)
