How deepakkumarsray2026-dev/mini-erp works
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 Compose stack · modules Domain modules · v1 API routers · services ERP services
Components 26
Frontend
React/Vite SPA and client-side domain modules
- App shell · Top-level React application and router composition
frontend/src/App.tsx - Domain modules · ERP route bundles for auth, workforce, payroll, AP, expenses, procurement, GL, admin, and AI dashboard
frontend/src/modules - API clients · Typed frontend service layer that calls backend endpoints
frontend/src/services - State store · Shared client state for auth, UI, and notifications
frontend/src/store - UI kit · Reusable layout, form, table, and chart components
frontend/src/components - Route guard · Protected routes and client-side permission helpers
frontend/src/components/common/ProtectedRoute.tsx - AI dashboard · 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 · FastAPI composition, middleware, and startup wiring
backend/app/main.py - API routers · Versioned ERP, auth, admin, AI, and MLOps routes
backend/app/api/v1 - Core services · Config, database, logging, middleware, security, and permissions
backend/app/core - Auth stack · JWT authentication and RBAC enforcement across backend and frontend
backend/app/services/auth_service.py - ERP services · Business logic for workforce, payroll, AP, expenses, procurement, GL, and AI support
backend/app/services - ORM models · Persistence models for ERP, auth, and MLOps domains
backend/app/models - Schemas · Request/response contracts for API boundaries
backend/app/schemas - Migrations · Database migration history and schema evolution
backend/alembic - Seed data · Demo data and default RBAC population scripts
backend/app/data/seed_all.py - Celery app · Redis-backed task execution entrypoint
backend/app/celery_app.py - Task groups · Agent, ML, notification, payroll, and report tasks
backend/app/tasks - ML pipelines · Feature engineering, training, inference, drift detection, and retraining
backend/app/ml/pipelines - Agents · Higher-level compliance, finance, invoice, onboarding, payroll, and planning workflows
backend/app/agents
Platform
Database, queue, proxy, monitoring, and model ops
- Compose stack · Docker Compose deployment surfaces for app, database, queue, and MLflow
docker-compose.prod.yml - Edge proxy · Development and production reverse proxy configuration
infrastructure/nginx/prod.conf - Postgres · Primary transactional database and schema namespaces
infrastructure/db/init.sql - Redis · Broker/cache layer for Celery and async work
docker-compose.dev.yml - MLflow · Separate experiment and model registry environment
docker-compose.mlflow.yml - Monitoring · Prometheus and Grafana assets for runtime visibility
infrastructure/monitoring/prometheus/prometheus.yml
Connections 28
- 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