Skip to content

Architecture Overview

Acumen ERP follows a modern, microservices-inspired architecture with clear separation of concerns.

System Architecture

graph TB
    User[User Browser] -->|HTTPS| Frontend[React Frontend<br/>Port 3000]
    Frontend -->|REST API| FastAPI[FastAPI Backend<br/>Port 8001]
    Frontend -->|Auth/Admin| Django[Django Backend<br/>Port 8000]
    FastAPI -->|SQLAlchemy| DB[(PostgreSQL<br/>Database)]
    Django -->|Django ORM| DB
    FastAPI -->|Tasks| Celery[Celery Workers]
    Celery -->|Queue| Redis[(Redis)]

Key Components

Frontend Layer

  • Technology : React 18 with TypeScript
  • Port : 3000 (development)
  • Purpose : User interface with YAML-driven component generation
  • Key Features :
    • Material-UI design system
    • YAML-based page configuration
    • Dynamic form and table rendering
    • Real-time data updates

Business Logic Layer (FastAPI)

  • Technology : FastAPI with SQLAlchemy ORM
  • Port : 8001
  • Purpose : Core business logic and data operations
  • Key Features :
    • 2016+ RESTful API endpoints
    • Automatic API documentation (Swagger UI)
    • Async/await support
    • Database connection pooling
    • Three router modes (minimal, core, full)

Authentication Layer (Django)

  • Technology : Django 5.2 with DRF
  • Port : 8000
  • Purpose : User authentication, authorization, and admin
  • Key Features :
    • JWT token-based authentication
    • ABAC (Attribute-Based Access Control)
    • License management
    • Django admin interface

Database Layer

  • Primary : PostgreSQL 13+
  • Fallback : SQLite (development only)
  • Features :
    • 2000+ tables from legacy ERP
    • Multi-schema support
    • Connection pooling
    • SSL support

Background Tasks

  • Task Queue : Celery
  • Message Broker : Redis
  • Purpose : Asynchronous processing for reports, imports, exports

Directory Structure

project_root/
├── backend/
│   ├── api/                    # FastAPI application
│   │   ├── main.py             # Application entry point
│   │   ├── config.py           # Configuration
│   │   ├── router_registry.py # Route registration
│   │   ├── business/           # Business domain
│   │   ├── company/            # Company domain (8 entities)
│   │   ├── core/               # Core domain (685+ entities)
│   │   ├── finance/            # Finance domain (452+ entities)
│   │   ├── hr/                 # HR domain
│   │   ├── inventory/          # Inventory domain
│   │   ├── manufacturing/      # Manufacturing domain
│   │   ├── crm/                # CRM domain
│   │   └── project/            # Project domain
│   ├── django_app/             # Django application
│   │   ├── apps/
│   │   │   ├── authentication/ # User auth
│   │   │   ├── abac/           # Access control
│   │   │   └── license_manager/# Licensing
│   │   └── config/             # Django settings
│   └── shared/
│       └── database/           # Shared database utilities
├── frontend/
│   ├── public/
│   │   └── navigation/         # YAML configurations
│   └── src/
│       ├── components/         # React components
│       ├── context/            # React contexts
│       ├── services/           # API services
│       └── utils/              # Utility functions
├── api_builder/                # API code generator
└── ui_builder/                 # UI analysis tool

Data Flow

Read Operation (GET)

1. User clicks "View Companies" in UI
2. Frontend loads /navigation/pages/companies.yaml
3. YamlPageRenderer renders DataTable component
4. Frontend: GET /api/company/company/
5. FastAPI routes to company.Company.routes.read_company_list()
6. CRUD layer queries PostgreSQL via SQLAlchemy
7. Response: [{CompanyID: 1, CompanyCD: "MAIN", ...}, ...]
8. DataTable renders rows with data

Write Operation (POST)

1. User fills "New Company" form
2. Frontend validates with React Hook Form
3. Frontend: POST /api/company/company/ with JSON payload
4. FastAPI validates with Pydantic schema (CompanyCreate)
5. CRUD layer creates SQLAlchemy model instance
6. Database INSERT executed
7. Response: Created company object
8. Frontend updates UI and shows success message

Authentication Flow

1. User enters credentials on login page
2. Frontend: POST /api/auth/login (Django)
3. Django validates username/password
4. Django generates JWT token
5. Response: {user, token, modules, pinned_items}
6. Frontend stores token in localStorage
7. Frontend sets Authorization header: "Bearer {token}"
8. All subsequent API calls include token
9. FastAPI/Django verify token on protected routes

Design Principles

1. YAML-Driven UI

Instead of writing React components for every page, we use YAML configuration files to declaratively define: - Page layout and structure - Data tables with columns and actions - Forms with fields and validation - Navigation and breadcrumbs

Benefits : - Rapid development of new pages - Consistent UI patterns - Non-developers can configure pages - Easy A/B testing and customization

2. Code Generation

Both API and UI code can be auto-generated: - API Builder : Scans database tables → generates models, schemas, CRUD, routes - UI Builder : Analyzes web pages → generates YAML configs

Benefits : - Consistent code patterns - Reduced manual coding - Automatic documentation - Easy onboarding of legacy systems

3. Router Modes

FastAPI supports three startup modes for performance optimization:

Mode Entities Loaded Use Case
minimal Essential only Fast development, testing
core Core, Finance, Company Standard development
full All 2016+ entities Production (if needed)

Set via environment variable: ROUTER_MODE=core

4. Domain-Driven Design

Business entities are organized into domains: - Company : Organizations, branches, companies - Finance : Accounts, transactions, GL, AR, AP - HR : Employees, payroll, benefits - Inventory : Items, warehouses, stock - CRM : Customers, leads, opportunities - Manufacturing : BOMs, work orders, production - Project : Projects, tasks, time tracking

Each domain has its own router, making it easy to: - Scale independently - Deploy as microservices (future) - Assign ownership to teams

5. Separation of Concerns

Layer Responsibility Technology
Presentation UI rendering, user input React + YAML
Business Logic Data processing, validation FastAPI + Pydantic
Data Access Database operations SQLAlchemy ORM
Authentication User identity, permissions Django + JWT
Background Async tasks, scheduling Celery + Redis

Technology Stack

Frontend

  • React 18.2 - UI library
  • TypeScript 4.9 - Type safety
  • Material-UI 7.1 - Component library
  • React Hook Form 7.56 - Form management
  • Axios 1.9 - HTTP client
  • React Router 6 - Routing

Backend (FastAPI)

  • FastAPI 0.109 - Web framework
  • SQLAlchemy 2.0 - ORM
  • Pydantic 2.6 - Data validation
  • Uvicorn 0.27 - ASGI server
  • python-jose 3.3 - JWT handling

Backend (Django)

  • Django 5.2 - Web framework
  • Django REST Framework 3.15 - API toolkit
  • JWT Authentication - Token auth

Database

  • PostgreSQL 13+ - Primary database
  • SQLite - Development fallback

Task Queue

  • Celery 5.3 - Task queue
  • Redis 5.0 - Message broker

Performance Considerations

Database

  • Connection pooling (5 connections, 10 overflow)
  • Pool pre-ping (validate connections before use)
  • Connection recycling (30 minutes)
  • SSL support for production

API

  • Async/await support in FastAPI
  • Route-level caching (future)
  • Response compression
  • Pagination (default 100 items)

Frontend

  • Code splitting with React.lazy()
  • Lazy loading of YAML configs
  • Memoization of expensive computations
  • Virtual scrolling for large tables

Security Architecture

Authentication

  • JWT tokens with expiration
  • HTTP-only cookies option
  • Token refresh mechanism
  • Automatic logout on expiry

Authorization

  • Role-based access control (RBAC)
  • Attribute-based access control (ABAC)
  • Route-level permissions
  • Field-level permissions
  • Action-level permissions (view, create, update, delete)

Data Protection

  • SQL injection prevention (ORM parameterization)
  • XSS prevention (React escaping)
  • CORS configuration
  • HTTPS enforcement (production)
  • Database SSL connections

Scalability

Horizontal Scaling

  • Frontend : Static files on CDN
  • FastAPI : Multiple uvicorn workers behind load balancer
  • Django : Multiple gunicorn workers
  • Celery : Multiple worker processes
  • Database : Read replicas, connection pooling

Vertical Scaling

  • Increase worker processes
  • Increase database connections
  • Add more RAM for caching
  • Optimize database indexes

Monitoring and Observability

Logs

  • FastAPI: Uvicorn access logs
  • Django: Django logging framework
  • Celery: Task execution logs
  • Nginx: Access and error logs

Health Checks

  • FastAPI: GET /health endpoint
  • Database: Connection pool status
  • Redis: Ping check

Metrics (Future)

  • Request latency
  • Error rates
  • Active connections
  • Queue depth

Next Steps