# chintan616/ledgerone architecture

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

- Interactive diagram: https://gitdiagram.com/chintan616/ledgerone
- Repository: https://github.com/chintan616/ledgerone

## Overview

1. **Overall shape**
   LedgerOne is a three-part system: a React single-page app, a Spring Boot backend monolith, and a separate Python AI service. The backend is the system of record; the frontend is a thin client; the AI service is called only for chat/AI features.

2. **Frontend boundary**
   The `frontend/` app uses React 18 + Vite + Tailwind. Its structure is route/page driven: landing, auth, dashboard, invoices, clients, expenses, reports, and profile. API calls are split by domain in `src/api/*`, and `AuthContext` handles token storage plus refresh behavior. `ProtectedRoute` and shared layout components enforce the authenticated app shell.

3. **Authentication and identity flow**
   Auth lives in `backend/auth/`. It supports email/password registration and login, Google sign-in with server-side token verification, short-lived JWT access tokens, and database-backed refresh tokens. Requests pass through `JwtAuthFilter` and Spring Security, so every non-auth endpoint is gated by bearer token validation. User-scoped data is keyed by authenticated user email.

4. **Invoice and client subsystem**
   The invoice domain is the largest backend slice: invoices, invoice items, clients, business profiles, PDF generation, and overdue scheduling. Controllers in `invoice/controller` call services that persist to PostgreSQL through repositories. Invoice lifecycle includes draft/sent/paid/overdue states, PDF export, and client lookup. Business profile data is embedded into generated invoice PDFs.

5. **Accounting and reporting subsystem**
   `accounting/` manages expenses and derived financial views. The backend stores expense records and computes financial summary, GST report, and monthly breakdown responses from invoices plus expenses. This is the reporting layer that feeds dashboard charts and reports pages, rather than a separate analytics service.

6. **Caching and read optimization**
   Redis is used as a cache-aside layer for read-heavy endpoints, especially dashboard summary, invoice lists, GST reports, and monthly aggregates. The README indicates short TTLs and explicit eviction on writes, so the architecture intentionally favors fast reads over always recomputing totals from PostgreSQL.

7. **Notification and email delivery**
   `notification/` provides email delivery via Spring Mail and Gmail SMTP. In practice, this supports invoice sending and other user-facing notifications. Email is an integration boundary rather than a separate queueing system; there is no evidence of async messaging infrastructure in the repo.

8. **Overdue invoice automation**
   `invoice/scheduler/OverdueScheduler` is a nightly background job. It scans sent invoices that are past due and marks them overdue automatically. This is a backend-only batch workflow, independent of frontend interaction.

9. **AI/chat subsystem**
   `chat/` is a backend entry point for conversational features, but the actual AI logic is isolated in the separate `ai-service/` Python project. The backend exposes a chat controller and config that likely proxy requests to that service. The Python service includes `main.py`, `agent.py`, and `embed.py`, suggesting it handles response generation and embeddings outside the main Java application.

10. **Persistence model**
   PostgreSQL is the primary database, and Hibernate manages schema creation/update (`ddl-auto: update`). The core entities are users, refresh tokens, clients, invoices, invoice items, business profiles, and expenses. Repositories are organized per domain package, which makes the backend a modular monolith rather than microservices.

11. **Security and configuration**
   `config/` centralizes application security, JWT filtering, and cache configuration. CORS is environment-driven, which matters because the frontend is deployed separately from the backend. Google OAuth client ID, JWT secret, DB credentials, Redis URL, and mail credentials are all externalized as runtime configuration.

12. **Deployment boundary**
   The repo is container-ready: backend and AI service each have Dockerfiles, the frontend is built for Vercel, and `render.yaml` targets backend deployment on Render. Operationally, the architecture is split across three runtime environments: browser-hosted SPA, Java backend API, and Python AI service, with PostgreSQL and Redis as shared infrastructure.

Main entry points: [`frontend/src/api/invoices.js`](https://github.com/chintan616/ledgerone/blob/main/frontend/src/api/invoices.js) (API Layer), [`backend/src/main/java/com/ledgerone/invoice/service/InvoiceService.java`](https://github.com/chintan616/ledgerone/blob/main/backend/src/main/java/com/ledgerone/invoice/service/InvoiceService.java) (Invoice Service), [`backend/src/main/java/com/ledgerone/auth/service/AuthService.java`](https://github.com/chintan616/ledgerone/blob/main/backend/src/main/java/com/ledgerone/auth/service/AuthService.java) (Auth Service), [`frontend/src/pages/Dashboard.jsx`](https://github.com/chintan616/ledgerone/blob/main/frontend/src/pages/Dashboard.jsx) (Pages)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_frontend_app["SPA<br/>React app<br/>[App.jsx]"]
  node_frontend_auth(("Auth State<br/>context<br/>[AuthContext.jsx]"))
  node_frontend_api["API Layer<br/>client modules<br/>[invoices.js]"]
  node_frontend_shell["App Shell<br/>layout<br/>[Layout.jsx]"]
  node_frontend_pages["Pages<br/>routes<br/>[Dashboard.jsx]"]
end

subgraph group_backend_auth["Auth"]
  node_auth_controller["Auth API<br/>controller"]
  node_auth_service["Auth Service<br/>[AuthService.java]"]
  node_jwt_service["JWT Logic<br/>security service<br/>[JwtService.java]"]
  node_user_repo[("User Store")]
end

subgraph group_backend_invoice["Invoicing"]
  node_invoice_controller["Invoice API<br/>controller"]
  node_client_controller["Clients API<br/>controller"]
  node_profile_controller["Profile API<br/>controller"]
  node_invoice_service["Invoice Service"]
  node_pdf_service["PDF Service<br/>document service<br/>[PdfService.java]"]
  node_overdue_scheduler(("Overdue Job<br/>scheduler"))
end

subgraph group_backend_accounting["Accounting"]
  node_accounting_controller["Accounting API<br/>controller"]
  node_accounting_service["Accounting Service"]
end

subgraph group_backend_chat["Chat"]
  node_chat_controller["Chat API<br/>controller"]
  node_ai_config["AI Bridge<br/>integration config"]
end

subgraph group_backend_platform["Platform"]
  node_notification_service["Email Delivery<br/>mail service"]
  node_security_config["Security<br/>config"]
  node_jwt_filter["JWT Filter<br/>[JwtAuthFilter.java]"]
  node_backend_app(("Backend App<br/>spring boot"))
end

subgraph group_ai_service["AI Service"]
  node_ai_main(("AI App<br/>python service<br/>[main.py]"))
  node_ai_agent["Agent<br/>python module<br/>[agent.py]"]
  node_ai_embed["Embeddings<br/>python module<br/>[embed.py]"]
end

node_frontend_app -->|"renders"| node_frontend_pages
node_frontend_app -->|"uses"| node_frontend_shell
node_frontend_shell -->|"reads"| node_frontend_auth
node_frontend_pages -->|"calls"| node_frontend_api
node_frontend_pages -->|"uses"| node_frontend_auth
node_frontend_api -->|"auth calls"| node_auth_controller
node_frontend_api -->|"invoice calls"| node_invoice_controller
node_frontend_api -->|"report calls"| node_accounting_controller
node_frontend_api -->|"chat calls"| node_chat_controller
node_security_config -->|"installs"| node_jwt_filter
node_jwt_filter -->|"validates"| node_auth_service
node_auth_controller -->|"delegates"| node_auth_service
node_auth_service -->|"issues"| node_jwt_service
node_auth_service -->|"persists"| node_user_repo
node_invoice_controller -->|"delegates"| node_invoice_service
node_invoice_controller -.->|"shares domain"| node_client_controller
node_invoice_service -->|"generates"| node_pdf_service
node_invoice_service -->|"notifies"| node_notification_service
node_invoice_service -.->|"updates"| node_overdue_scheduler
node_accounting_controller -->|"delegates"| node_accounting_service
node_chat_controller -->|"proxies"| node_ai_config
node_ai_config -->|"calls"| node_ai_main
node_ai_main -->|"uses"| node_ai_agent
node_ai_main -->|"uses"| node_ai_embed
node_backend_app -->|"boots"| node_security_config

click node_frontend_app "https://github.com/chintan616/ledgerone/blob/main/frontend/src/App.jsx"
click node_frontend_auth "https://github.com/chintan616/ledgerone/blob/main/frontend/src/context/AuthContext.jsx"
click node_frontend_api "https://github.com/chintan616/ledgerone/blob/main/frontend/src/api/invoices.js"
click node_frontend_shell "https://github.com/chintan616/ledgerone/blob/main/frontend/src/components/Layout.jsx"
click node_frontend_pages "https://github.com/chintan616/ledgerone/blob/main/frontend/src/pages/Dashboard.jsx"
click node_auth_controller "https://github.com/chintan616/ledgerone/blob/main/backend/src/main/java/com/ledgerone/auth/controller/AuthController.java"
click node_auth_service "https://github.com/chintan616/ledgerone/blob/main/backend/src/main/java/com/ledgerone/auth/service/AuthService.java"
click node_jwt_service "https://github.com/chintan616/ledgerone/blob/main/backend/src/main/java/com/ledgerone/auth/service/JwtService.java"
click node_user_repo "https://github.com/chintan616/ledgerone/blob/main/backend/src/main/java/com/ledgerone/auth/repository/UserRepository.java"
click node_invoice_controller "https://github.com/chintan616/ledgerone/blob/main/backend/src/main/java/com/ledgerone/invoice/controller/InvoiceController.java"
click node_client_controller "https://github.com/chintan616/ledgerone/blob/main/backend/src/main/java/com/ledgerone/invoice/controller/ClientController.java"
click node_profile_controller "https://github.com/chintan616/ledgerone/blob/main/backend/src/main/java/com/ledgerone/invoice/controller/BusinessProfileController.java"
click node_invoice_service "https://github.com/chintan616/ledgerone/blob/main/backend/src/main/java/com/ledgerone/invoice/service/InvoiceService.java"
click node_pdf_service "https://github.com/chintan616/ledgerone/blob/main/backend/src/main/java/com/ledgerone/invoice/service/PdfService.java"
click node_overdue_scheduler "https://github.com/chintan616/ledgerone/blob/main/backend/src/main/java/com/ledgerone/invoice/scheduler/OverdueScheduler.java"
click node_accounting_controller "https://github.com/chintan616/ledgerone/blob/main/backend/src/main/java/com/ledgerone/accounting/controller/AccountingController.java"
click node_accounting_service "https://github.com/chintan616/ledgerone/blob/main/backend/src/main/java/com/ledgerone/accounting/service/AccountingService.java"
click node_notification_service "https://github.com/chintan616/ledgerone/blob/main/backend/src/main/java/com/ledgerone/notification/service/NotificationService.java"
click node_security_config "https://github.com/chintan616/ledgerone/blob/main/backend/src/main/java/com/ledgerone/config/SecurityConfig.java"
click node_jwt_filter "https://github.com/chintan616/ledgerone/blob/main/backend/src/main/java/com/ledgerone/config/JwtAuthFilter.java"
click node_backend_app "https://github.com/chintan616/ledgerone/blob/main/backend/src/main/java/com/ledgerone/LedgerOneApplication.java"
click node_chat_controller "https://github.com/chintan616/ledgerone/blob/main/backend/src/main/java/com/ledgerone/chat/ChatController.java"
click node_ai_config "https://github.com/chintan616/ledgerone/blob/main/backend/src/main/java/com/ledgerone/chat/AiServiceConfig.java"
click node_ai_main "https://github.com/chintan616/ledgerone/blob/main/ai-service/main.py"
click node_ai_agent "https://github.com/chintan616/ledgerone/blob/main/ai-service/agent.py"
click node_ai_embed "https://github.com/chintan616/ledgerone/blob/main/ai-service/embed.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_app,node_frontend_auth,node_frontend_api,node_frontend_shell,node_frontend_pages,node_ai_main,node_ai_agent,node_ai_embed toneBlue
class node_auth_controller,node_auth_service,node_jwt_service,node_user_repo toneAmber
class node_invoice_controller,node_client_controller,node_profile_controller,node_invoice_service,node_pdf_service,node_overdue_scheduler toneMint
class node_accounting_controller,node_accounting_service toneRose
class node_chat_controller,node_ai_config toneIndigo
class node_notification_service,node_security_config,node_jwt_filter,node_backend_app toneTeal
```

## Components

### Frontend

React SPA client

- [SPA](https://github.com/chintan616/ledgerone/blob/main/frontend/src/App.jsx): React app · Browser client shell and routes · `frontend/src/App.jsx`
- [Auth State](https://github.com/chintan616/ledgerone/blob/main/frontend/src/context/AuthContext.jsx): context · Stores tokens and refresh state · `frontend/src/context/AuthContext.jsx`
- [API Layer](https://github.com/chintan616/ledgerone/blob/main/frontend/src/api/invoices.js): client modules · Domain-split HTTP calls · `frontend/src/api/invoices.js`
- [App Shell](https://github.com/chintan616/ledgerone/blob/main/frontend/src/components/Layout.jsx): layout · Protected layout and navigation · `frontend/src/components/Layout.jsx`
- [Pages](https://github.com/chintan616/ledgerone/blob/main/frontend/src/pages/Dashboard.jsx): routes · Landing, auth, dashboard, invoices, clients, expenses, reports, profile · `frontend/src/pages/Dashboard.jsx`

### Auth

Identity and token handling

- [Auth API](https://github.com/chintan616/ledgerone/blob/main/backend/src/main/java/com/ledgerone/auth/controller/AuthController.java): controller · Register, login, Google sign-in, refresh · `backend/src/main/java/com/ledgerone/auth/controller/AuthController.java`
- [Auth Service](https://github.com/chintan616/ledgerone/blob/main/backend/src/main/java/com/ledgerone/auth/service/AuthService.java): service · Issues JWTs and manages refresh tokens · `backend/src/main/java/com/ledgerone/auth/service/AuthService.java`
- [JWT Logic](https://github.com/chintan616/ledgerone/blob/main/backend/src/main/java/com/ledgerone/auth/service/JwtService.java): security service · Signs and validates access tokens · `backend/src/main/java/com/ledgerone/auth/service/JwtService.java`
- [User Store](https://github.com/chintan616/ledgerone/blob/main/backend/src/main/java/com/ledgerone/auth/repository/UserRepository.java): repository · Users and refresh token persistence · `backend/src/main/java/com/ledgerone/auth/repository/UserRepository.java`

### Invoicing

Invoices, clients, profiles, PDFs, overdue jobs

- [Invoice API](https://github.com/chintan616/ledgerone/blob/main/backend/src/main/java/com/ledgerone/invoice/controller/InvoiceController.java): controller · Invoices, status updates, PDF flows · `backend/src/main/java/com/ledgerone/invoice/controller/InvoiceController.java`
- [Clients API](https://github.com/chintan616/ledgerone/blob/main/backend/src/main/java/com/ledgerone/invoice/controller/ClientController.java): controller · Client CRUD and lookup · `backend/src/main/java/com/ledgerone/invoice/controller/ClientController.java`
- [Profile API](https://github.com/chintan616/ledgerone/blob/main/backend/src/main/java/com/ledgerone/invoice/controller/BusinessProfileController.java): controller · Business profile management · `backend/src/main/java/com/ledgerone/invoice/controller/BusinessProfileController.java`
- [Invoice Service](https://github.com/chintan616/ledgerone/blob/main/backend/src/main/java/com/ledgerone/invoice/service/InvoiceService.java): service · Invoice lifecycle and user-scoped persistence · `backend/src/main/java/com/ledgerone/invoice/service/InvoiceService.java`
- [PDF Service](https://github.com/chintan616/ledgerone/blob/main/backend/src/main/java/com/ledgerone/invoice/service/PdfService.java): document service · Generates invoice PDFs with business profile data · `backend/src/main/java/com/ledgerone/invoice/service/PdfService.java`
- [Overdue Job](https://github.com/chintan616/ledgerone/blob/main/backend/src/main/java/com/ledgerone/invoice/scheduler/OverdueScheduler.java): scheduler · Marks past-due sent invoices overdue · `backend/src/main/java/com/ledgerone/invoice/scheduler/OverdueScheduler.java`

### Accounting

Expenses and financial reports

- [Accounting API](https://github.com/chintan616/ledgerone/blob/main/backend/src/main/java/com/ledgerone/accounting/controller/AccountingController.java): controller · Expenses and derived financial reports · `backend/src/main/java/com/ledgerone/accounting/controller/AccountingController.java`
- [Accounting Service](https://github.com/chintan616/ledgerone/blob/main/backend/src/main/java/com/ledgerone/accounting/service/AccountingService.java): service · Computes summaries, GST, and monthly breakdowns · `backend/src/main/java/com/ledgerone/accounting/service/AccountingService.java`

### Chat

Backend chat gateway to AI service

- [Chat API](https://github.com/chintan616/ledgerone/blob/main/backend/src/main/java/com/ledgerone/chat/ChatController.java): controller · Backend chat entry point · `backend/src/main/java/com/ledgerone/chat/ChatController.java`
- [AI Bridge](https://github.com/chintan616/ledgerone/blob/main/backend/src/main/java/com/ledgerone/chat/AiServiceConfig.java): integration config · Backend client for the Python AI service · `backend/src/main/java/com/ledgerone/chat/AiServiceConfig.java`

### Platform

Security, caching, exceptions, app bootstrap

- [Email Delivery](https://github.com/chintan616/ledgerone/blob/main/backend/src/main/java/com/ledgerone/notification/service/NotificationService.java): mail service · Sends invoice and user-facing emails · `backend/src/main/java/com/ledgerone/notification/service/NotificationService.java`
- [Security](https://github.com/chintan616/ledgerone/blob/main/backend/src/main/java/com/ledgerone/config/SecurityConfig.java): config · Spring Security, JWT filter, CORS, cache config · `backend/src/main/java/com/ledgerone/config/SecurityConfig.java`
- [JWT Filter](https://github.com/chintan616/ledgerone/blob/main/backend/src/main/java/com/ledgerone/config/JwtAuthFilter.java): filter · Validates bearer tokens on protected requests · `backend/src/main/java/com/ledgerone/config/JwtAuthFilter.java`
- [Backend App](https://github.com/chintan616/ledgerone/blob/main/backend/src/main/java/com/ledgerone/LedgerOneApplication.java): spring boot · Monolithic API entry point · `backend/src/main/java/com/ledgerone/LedgerOneApplication.java`

### AI Service

Separate Python AI runtime

- [AI App](https://github.com/chintan616/ledgerone/blob/main/ai-service/main.py): python service · Separate AI runtime for chat features · `ai-service/main.py`
- [Agent](https://github.com/chintan616/ledgerone/blob/main/ai-service/agent.py): python module · Response generation logic · `ai-service/agent.py`
- [Embeddings](https://github.com/chintan616/ledgerone/blob/main/ai-service/embed.py): python module · Embedding pipeline support · `ai-service/embed.py`

## Connections

- SPA → Pages: renders · Route-driven screen composition
- SPA → App Shell: uses · Authenticated app shell
- App Shell → Auth State: reads · Session and token state
- Pages → API Layer: calls · Domain API requests
- Pages → Auth State: uses · Login and refresh flow
- API Layer → Auth API: auth calls · Register, login, refresh, Google sign-in
- API Layer → Invoice API: invoice calls · Invoice and client operations
- API Layer → Accounting API: report calls · Dashboard and reporting reads
- API Layer → Chat API: chat calls · Chat widget requests
- Security → JWT Filter: installs · Protects non-auth endpoints
- JWT Filter → Auth Service: validates · Bearer token checks
- Auth API → Auth Service: delegates · Login, registration, refresh, Google auth
- Auth Service → JWT Logic: issues · Creates and verifies JWTs
- Auth Service → User Store: persists · Users and refresh tokens
- Invoice API → Invoice Service: delegates · Invoice lifecycle operations
- Invoice API → Clients API: shares domain · Client lookup and CRUD
- Invoice Service → PDF Service: generates · Invoice PDF export
- Invoice Service → Email Delivery: notifies · Invoice email delivery
- Invoice Service → Overdue Job: updates · Status transitions to overdue
- Accounting API → Accounting Service: delegates · Expense and summary endpoints
- Chat API → AI Bridge: proxies · Connects backend chat to AI service
- AI Bridge → AI App: calls · Remote AI runtime boundary
- AI App → Agent: uses · Conversation logic
- AI App → Embeddings: uses · Embedding support
- Backend App → Security: boots · Loads application security and cache setup
