# deepakkumarsray2026-dev/mini-erp architecture

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

- Interactive diagram: https://gitdiagram.com/deepakkumarsray2026-dev/mini-erp
- Repository: https://github.com/deepakkumarsray2026-dev/mini-erp

## Overview

1. **System shape**
   - This is a monorepo with three major runtime surfaces: a **FastAPI backend**, a **React/Vite frontend**, and **deployment/infrastructure assets** for Docker, Nginx, PostgreSQL, Redis, monitoring, and MLflow.

2. **Primary request flow**
   - User traffic enters the **frontend** in the browser, which calls typed API clients under `frontend/src/services`.
   - Those calls hit the **FastAPI routers** in `backend/app/api/v1`, which delegate to service classes, ORM models, and background jobs.

3. **Backend domain boundaries**
   - The backend is organized by ERP domain: **auth**, **workforce/HCM**, **payroll**, **accounts payable**, **expenses**, **procurement**, **general ledger**, and **admin**.
   - Each domain has its own router, schemas, services, and corresponding SQLAlchemy models, which keeps module boundaries aligned across API, business logic, and persistence.

4. **Persistence and schema management**
   - PostgreSQL is the system of record.
   - Database changes are managed with **Alembic migrations** in `backend/alembic`, and the schema is split into logical namespaces: `auth`, `hcm`, `payroll`, `ap`, `expenses`, `procurement`, `gl`, and `mlops`.
   - Seed scripts in `backend/app/data` populate demo data and default RBAC data.

5. **Security and access control**
   - Authentication is JWT-based and centralized in `backend/app/services/auth_service.py` and `backend/app/core/security.py`.
   - Authorization is enforced through RBAC helpers in `backend/app/core/permissions.py`, with protected frontend routing via `ProtectedRoute` and permission helpers on the client side.

6. **ML/MLOps subsystem**
   - Machine learning is first-class, not an add-on: `backend/app/ml` contains feature engineering, model definitions, and training/inference pipelines.
   - The current shipped models include attrition prediction, expense violation detection, payroll anomaly detection, and invoice classification.
   - MLOps API routes expose model registry, prediction logs, training jobs, and batch insight endpoints that power the AI dashboard.

7. **Model lifecycle and storage**
   - Trained artifacts are written to `backend/models_store`, while `backend/app/ml/pipelines` coordinates training, evaluation, inference, drift detection, and retraining.
   - The repo also includes a dedicated **MLflow compose setup**, showing that model experimentation/registry is intended to be tracked separately from the transactional ERP database.

8. **Asynchronous work**
   - Background processing is handled with **Celery + Redis** via `backend/app/celery_app.py`.
   - Task groups are separated by concern: agent tasks, ML tasks, notification tasks, payroll tasks, and report tasks.
   - This keeps longer-running actions like retraining, notifications, and batch reporting out of the synchronous API path.

9. **Agent layer**
   - There is a dedicated `backend/app/agents` package for higher-level AI workflows: compliance, expense audit, financial close, invoice processing, onboarding, payroll discrepancy, and workforce planning.
   - In architecture terms, this is a separate orchestration layer above core services and below any future LLM/agent UI; it is present even though the README roadmap marks several agentic phases as pending.

10. **Frontend composition**
   - The frontend is a modular SPA built around ERP domains, with route bundles under `frontend/src/modules/*`.
   - Shared UI lives in `components`, cross-cutting state in `store`, and API integration in `services`.
   - State and data fetching use **Zustand** and **TanStack Query**, while forms are handled with **React Hook Form**.

11. **AI dashboard as a cross-cutting consumer**
   - The `/ai` frontend area is the primary consumer of MLOps endpoints.
   - It combines batch risk/insight views, model registry cards, and prediction audit logs, making it the visual bridge between operational ERP data and ML outputs.

12. **Operational and deployment boundary**
   - The repo is designed to run through Docker Compose in dev/prod variants, with **Nginx** as the edge/proxy layer and GCP bootstrap scripts for cloud provisioning.
   - Monitoring assets for **Prometheus** and **Grafana** are included, and backend/frontend have separate Dockerfiles for isolated builds.
   - `start.sh` and `stop.sh` show the intended unit of deployment is the full stack, not individual services.

13. **Data bootstrap and developer workflow**
   - `seed_all.py` plus per-domain seeders create realistic demo data across ERP and ML domains.
   - Tests are split by concern (`api`, `services`, `ml`, `agents`), which mirrors the system’s architectural boundaries and suggests the main integration seams are API, service, and model layers.

14. **Diagram takeaway**
   - A good architecture diagram should show: **browser/UI → FastAPI domain routers → service layer → PostgreSQL**, with side paths to **Redis/Celery**, **ML pipelines/model store**, and **agent workflows**.
   - The frontend should be drawn as a modular SPA consuming the backend through typed service clients, while infrastructure should include Docker/Nginx, database, queue, and observability as supporting platform components.

Main entry points: [`docker-compose.prod.yml`](https://github.com/deepakkumarsray2026-dev/mini-erp/blob/main/docker-compose.prod.yml) (Compose stack), [`frontend/src/modules`](https://github.com/deepakkumarsray2026-dev/mini-erp/tree/main/frontend/src/modules) (Domain modules), [`backend/app/api/v1`](https://github.com/deepakkumarsray2026-dev/mini-erp/tree/main/backend/app/api/v1) (API routers), [`backend/app/services`](https://github.com/deepakkumarsray2026-dev/mini-erp/tree/main/backend/app/services) (ERP services)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_frontend_app["App shell<br/>spa shell<br/>[App.tsx]"]
  node_frontend_modules["Domain modules<br/>feature modules"]
  node_frontend_services["API clients<br/>typed clients"]
  node_frontend_store["State store<br/>zustand slices"]
  node_frontend_ui["UI kit<br/>shared components"]
  node_frontend_guard["Route guard<br/>access control<br/>[ProtectedRoute.tsx]"]
  node_frontend_ai["AI dashboard<br/>ui surface"]
end

subgraph group_backend["Backend"]
  node_backend_main["App entry<br/>fastapi app<br/>[main.py]"]
  node_backend_routers["API routers<br/>rest endpoints"]
  node_backend_core["Core services<br/>platform core"]
  node_backend_auth["Auth stack<br/>jwt + rbac<br/>[auth_service.py]"]
  node_backend_domains["ERP services<br/>domain services"]
  node_backend_models[("ORM models<br/>sqlalchemy models")]
  node_backend_schemas["Schemas<br/>pydantic dto"]
  node_backend_migrations["Migrations<br/>alembic"]
  node_backend_seed["Seed data<br/>bootstrap data<br/>[seed_all.py]"]
  node_backend_celery["Celery app<br/>async runtime<br/>[celery_app.py]"]
  node_backend_tasks["Task groups<br/>background jobs"]
  node_backend_ml["ML pipelines<br/>ml system"]
  node_backend_agents["Agents<br/>ai orchestration"]
end

subgraph group_platform["Platform"]
  node_platform_compose["Compose stack<br/>deployment"]
  node_platform_nginx["Edge proxy<br/>nginx<br/>[prod.conf]"]
  node_platform_db[("Postgres<br/>system of record<br/>[init.sql]")]
  node_platform_redis["Redis<br/>queue cache"]
  node_platform_mlflow["MLflow<br/>model registry"]
  node_platform_observability["Monitoring<br/>metrics + dashboards<br/>[prometheus.yml]"]
end

node_frontend_app -->|"routes to"| node_frontend_modules
node_frontend_app -->|"renders with"| node_frontend_ui
node_frontend_modules -->|"calls"| node_frontend_services
node_frontend_modules -->|"protects"| node_frontend_guard
node_frontend_services -->|"HTTP API"| node_backend_routers
node_frontend_store -->|"feeds"| node_frontend_modules
node_frontend_ai -->|"consumes"| node_frontend_services
node_backend_main -->|"mounts"| node_backend_routers
node_backend_main -->|"configures"| node_backend_core
node_backend_routers -->|"delegates to"| node_backend_domains
node_backend_routers -->|"secures"| node_backend_auth
node_backend_domains -->|"persists via"| node_backend_models
node_backend_domains -->|"validates with"| node_backend_schemas
node_backend_auth -->|"uses"| node_backend_core
node_backend_seed -->|"loads"| node_platform_db
node_backend_migrations -->|"evolves"| node_platform_db
node_backend_celery -->|"brokers via"| node_platform_redis
node_backend_tasks -->|"runs on"| node_backend_celery
node_backend_tasks -->|"orchestrates"| node_backend_ml
node_backend_tasks -->|"orchestrates"| node_backend_agents
node_backend_ml -->|"stores metadata in"| node_backend_models
node_backend_ml -->|"registers to"| node_platform_mlflow
node_backend_agents -->|"uses"| node_backend_domains
node_platform_compose -->|"includes"| node_platform_db
node_platform_compose -->|"includes"| node_platform_redis
node_platform_compose -->|"fronts with"| node_platform_nginx
node_platform_compose -->|"includes"| node_platform_mlflow
node_platform_observability -->|"watches"| node_platform_compose

click node_frontend_app "https://github.com/deepakkumarsray2026-dev/mini-erp/blob/main/frontend/src/App.tsx"
click node_frontend_modules "https://github.com/deepakkumarsray2026-dev/mini-erp/tree/main/frontend/src/modules"
click node_frontend_services "https://github.com/deepakkumarsray2026-dev/mini-erp/tree/main/frontend/src/services"
click node_frontend_store "https://github.com/deepakkumarsray2026-dev/mini-erp/tree/main/frontend/src/store"
click node_frontend_ui "https://github.com/deepakkumarsray2026-dev/mini-erp/tree/main/frontend/src/components"
click node_frontend_guard "https://github.com/deepakkumarsray2026-dev/mini-erp/blob/main/frontend/src/components/common/ProtectedRoute.tsx"
click node_frontend_ai "https://github.com/deepakkumarsray2026-dev/mini-erp/blob/main/frontend/src/modules/ai_dashboard/pages/AIDashboardPage.tsx"
click node_backend_main "https://github.com/deepakkumarsray2026-dev/mini-erp/blob/main/backend/app/main.py"
click node_backend_routers "https://github.com/deepakkumarsray2026-dev/mini-erp/tree/main/backend/app/api/v1"
click node_backend_core "https://github.com/deepakkumarsray2026-dev/mini-erp/tree/main/backend/app/core"
click node_backend_auth "https://github.com/deepakkumarsray2026-dev/mini-erp/blob/main/backend/app/services/auth_service.py"
click node_backend_domains "https://github.com/deepakkumarsray2026-dev/mini-erp/tree/main/backend/app/services"
click node_backend_models "https://github.com/deepakkumarsray2026-dev/mini-erp/tree/main/backend/app/models"
click node_backend_schemas "https://github.com/deepakkumarsray2026-dev/mini-erp/tree/main/backend/app/schemas"
click node_backend_migrations "https://github.com/deepakkumarsray2026-dev/mini-erp/tree/main/backend/alembic"
click node_backend_seed "https://github.com/deepakkumarsray2026-dev/mini-erp/blob/main/backend/app/data/seed_all.py"
click node_backend_celery "https://github.com/deepakkumarsray2026-dev/mini-erp/blob/main/backend/app/celery_app.py"
click node_backend_tasks "https://github.com/deepakkumarsray2026-dev/mini-erp/tree/main/backend/app/tasks"
click node_backend_ml "https://github.com/deepakkumarsray2026-dev/mini-erp/tree/main/backend/app/ml/pipelines"
click node_backend_agents "https://github.com/deepakkumarsray2026-dev/mini-erp/tree/main/backend/app/agents"
click node_platform_compose "https://github.com/deepakkumarsray2026-dev/mini-erp/blob/main/docker-compose.prod.yml"
click node_platform_nginx "https://github.com/deepakkumarsray2026-dev/mini-erp/blob/main/infrastructure/nginx/prod.conf"
click node_platform_db "https://github.com/deepakkumarsray2026-dev/mini-erp/blob/main/infrastructure/db/init.sql"
click node_platform_redis "https://github.com/deepakkumarsray2026-dev/mini-erp/blob/main/docker-compose.dev.yml"
click node_platform_mlflow "https://github.com/deepakkumarsray2026-dev/mini-erp/blob/main/docker-compose.mlflow.yml"
click node_platform_observability "https://github.com/deepakkumarsray2026-dev/mini-erp/blob/main/infrastructure/monitoring/prometheus/prometheus.yml"

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_modules,node_frontend_services,node_frontend_store,node_frontend_ui,node_frontend_guard,node_frontend_ai toneBlue
class node_backend_main,node_backend_routers,node_backend_core,node_backend_auth,node_backend_domains,node_backend_models,node_backend_schemas,node_backend_migrations,node_backend_seed,node_backend_celery,node_backend_tasks,node_backend_ml,node_backend_agents toneAmber
class node_platform_compose,node_platform_nginx,node_platform_db,node_platform_redis,node_platform_mlflow,node_platform_observability toneMint
```

## Components

### Frontend

React/Vite SPA and client-side domain modules

- [App shell](https://github.com/deepakkumarsray2026-dev/mini-erp/blob/main/frontend/src/App.tsx): spa shell · Top-level React application and router composition · `frontend/src/App.tsx`
- [Domain modules](https://github.com/deepakkumarsray2026-dev/mini-erp/tree/main/frontend/src/modules): feature modules · ERP route bundles for auth, workforce, payroll, AP, expenses, procurement, GL, admin, and AI dashboard · `frontend/src/modules`
- [API clients](https://github.com/deepakkumarsray2026-dev/mini-erp/tree/main/frontend/src/services): typed clients · Typed frontend service layer that calls backend endpoints · `frontend/src/services`
- [State store](https://github.com/deepakkumarsray2026-dev/mini-erp/tree/main/frontend/src/store): zustand slices · Shared client state for auth, UI, and notifications · `frontend/src/store`
- [UI kit](https://github.com/deepakkumarsray2026-dev/mini-erp/tree/main/frontend/src/components): shared components · Reusable layout, form, table, and chart components · `frontend/src/components`
- [Route guard](https://github.com/deepakkumarsray2026-dev/mini-erp/blob/main/frontend/src/components/common/ProtectedRoute.tsx): access control · Protected routes and client-side permission helpers · `frontend/src/components/common/ProtectedRoute.tsx`
- [AI dashboard](https://github.com/deepakkumarsray2026-dev/mini-erp/blob/main/frontend/src/modules/ai_dashboard/pages/AIDashboardPage.tsx): ui surface · Cross-cutting dashboard for model registry, batch insights, and prediction logs · `frontend/src/modules/ai_dashboard/pages/AIDashboardPage.tsx`

### Backend

FastAPI app, domain services, ML, agents, and async jobs

- [App entry](https://github.com/deepakkumarsray2026-dev/mini-erp/blob/main/backend/app/main.py): fastapi app · FastAPI composition, middleware, and startup wiring · `backend/app/main.py`
- [API routers](https://github.com/deepakkumarsray2026-dev/mini-erp/tree/main/backend/app/api/v1): rest endpoints · Versioned ERP, auth, admin, AI, and MLOps routes · `backend/app/api/v1`
- [Core services](https://github.com/deepakkumarsray2026-dev/mini-erp/tree/main/backend/app/core): platform core · Config, database, logging, middleware, security, and permissions · `backend/app/core`
- [Auth stack](https://github.com/deepakkumarsray2026-dev/mini-erp/blob/main/backend/app/services/auth_service.py): jwt + rbac · JWT authentication and RBAC enforcement across backend and frontend · `backend/app/services/auth_service.py`
- [ERP services](https://github.com/deepakkumarsray2026-dev/mini-erp/tree/main/backend/app/services): domain services · Business logic for workforce, payroll, AP, expenses, procurement, GL, and AI support · `backend/app/services`
- [ORM models](https://github.com/deepakkumarsray2026-dev/mini-erp/tree/main/backend/app/models): sqlalchemy models · Persistence models for ERP, auth, and MLOps domains · `backend/app/models`
- [Schemas](https://github.com/deepakkumarsray2026-dev/mini-erp/tree/main/backend/app/schemas): pydantic dto · Request/response contracts for API boundaries · `backend/app/schemas`
- [Migrations](https://github.com/deepakkumarsray2026-dev/mini-erp/tree/main/backend/alembic): alembic · Database migration history and schema evolution · `backend/alembic`
- [Seed data](https://github.com/deepakkumarsray2026-dev/mini-erp/blob/main/backend/app/data/seed_all.py): bootstrap data · Demo data and default RBAC population scripts · `backend/app/data/seed_all.py`
- [Celery app](https://github.com/deepakkumarsray2026-dev/mini-erp/blob/main/backend/app/celery_app.py): async runtime · Redis-backed task execution entrypoint · `backend/app/celery_app.py`
- [Task groups](https://github.com/deepakkumarsray2026-dev/mini-erp/tree/main/backend/app/tasks): background jobs · Agent, ML, notification, payroll, and report tasks · `backend/app/tasks`
- [ML pipelines](https://github.com/deepakkumarsray2026-dev/mini-erp/tree/main/backend/app/ml/pipelines): ml system · Feature engineering, training, inference, drift detection, and retraining · `backend/app/ml/pipelines`
- [Agents](https://github.com/deepakkumarsray2026-dev/mini-erp/tree/main/backend/app/agents): ai orchestration · Higher-level compliance, finance, invoice, onboarding, payroll, and planning workflows · `backend/app/agents`

### Platform

Database, queue, proxy, monitoring, and model ops

- [Compose stack](https://github.com/deepakkumarsray2026-dev/mini-erp/blob/main/docker-compose.prod.yml): deployment · Docker Compose deployment surfaces for app, database, queue, and MLflow · `docker-compose.prod.yml`
- [Edge proxy](https://github.com/deepakkumarsray2026-dev/mini-erp/blob/main/infrastructure/nginx/prod.conf): nginx · Development and production reverse proxy configuration · `infrastructure/nginx/prod.conf`
- [Postgres](https://github.com/deepakkumarsray2026-dev/mini-erp/blob/main/infrastructure/db/init.sql): system of record · Primary transactional database and schema namespaces · `infrastructure/db/init.sql`
- [Redis](https://github.com/deepakkumarsray2026-dev/mini-erp/blob/main/docker-compose.dev.yml): queue cache · Broker/cache layer for Celery and async work · `docker-compose.dev.yml`
- [MLflow](https://github.com/deepakkumarsray2026-dev/mini-erp/blob/main/docker-compose.mlflow.yml): model registry · Separate experiment and model registry environment · `docker-compose.mlflow.yml`
- [Monitoring](https://github.com/deepakkumarsray2026-dev/mini-erp/blob/main/infrastructure/monitoring/prometheus/prometheus.yml): metrics + dashboards · Prometheus and Grafana assets for runtime visibility · `infrastructure/monitoring/prometheus/prometheus.yml`

## Connections

- App shell → Domain modules: routes to · Top-level app composes domain route bundles
- App shell → UI kit: renders with · App and pages use shared layout and widgets
- Domain modules → API clients: calls · Feature pages invoke typed API clients
- Domain modules → Route guard: protects · Sensitive routes are wrapped with auth/permission checks
- API clients → API routers: HTTP API · Client services talk to versioned backend endpoints
- State store → Domain modules: feeds · Auth and UI state support module pages
- AI dashboard → API clients: consumes · AI dashboard uses MLOps and AI service clients
- App entry → API routers: mounts · Main FastAPI app includes versioned route modules
- App entry → Core services: configures · App bootstraps middleware, logging, and database plumbing
- API routers → ERP services: delegates to · Routers hand requests to service-layer use cases
- API routers → Auth stack: secures · Auth and permission checks gate protected APIs
- ERP services → ORM models: persists via · Service logic reads and writes ORM entities
- ERP services → Schemas: validates with · Services and endpoints exchange typed DTOs
- Auth stack → Core services: uses · Security helpers depend on core config and permissions
- Seed data → Postgres: loads · Bootstrap scripts populate the transactional database
- Migrations → Postgres: evolves · Alembic manages schema changes in Postgres
- Celery app → Redis: brokers via · Celery uses Redis for async job dispatch
- Task groups → Celery app: runs on · Task modules are executed by the Celery app
- Task groups → ML pipelines: orchestrates · Background jobs trigger training, retraining, and batch analysis
- Task groups → Agents: orchestrates · Async execution supports agent workflows
- ML pipelines → ORM models: stores metadata in · ML features and pipelines integrate with model/data records
- ML pipelines → MLflow: registers to · Trained models and experiments are tracked separately
- Agents → ERP services: uses · Agents sit above core ERP services and domain data
- Compose stack → Postgres: includes · Deployment stack provisions the database
- Compose stack → Redis: includes · Deployment stack provisions Redis
- Compose stack → Edge proxy: fronts with · Edge proxy is part of the full-stack deployment
- Compose stack → MLflow: includes · Separate compose setup supports model lifecycle services
- Monitoring → Compose stack: watches · Monitoring covers the deployed stack
