Architecture Documentation¶
Welcome to the Acumen ERP architecture documentation. This section provides in-depth technical details about how the system is designed and organized.
Architecture Overview¶
Acumen ERP is built using a modern, modular architecture with clear separation between presentation, business logic, and data layers.
graph TB
subgraph "Client Layer"
Browser[Web Browser]
end
subgraph "Presentation Layer"
React[React Frontend<br/>TypeScript + Material-UI]
YAML[YAML Configs<br/>Navigation & Pages]
end
subgraph "Business Logic Layer"
FastAPI[FastAPI Backend<br/>2016+ Endpoints]
Router[Router Registry<br/>3 Modes]
end
subgraph "Authentication Layer"
Django[Django Backend<br/>Auth + Admin]
JWT[JWT Tokens]
ABAC[ABAC System]
end
subgraph "Data Layer"
SQLAlchemy[SQLAlchemy ORM]
DjangoORM[Django ORM]
DB[(PostgreSQL)]
end
subgraph "Background Layer"
Celery[Celery Workers]
Redis[(Redis Queue)]
end
Browser -->|HTTPS| React
React -.->|Loads| YAML
React -->|REST API| FastAPI
React -->|Auth API| Django
FastAPI --> Router
Router --> SQLAlchemy
Django --> JWT
Django --> ABAC
Django --> DjangoORM
SQLAlchemy --> DB
DjangoORM --> DB
FastAPI -.->|Async Tasks| Celery
Celery -.->|Queue| Redis
Architecture Principles¶
1. Separation of Concerns¶
Each layer has a single, well-defined responsibility: - Frontend : User interface and interaction - FastAPI : Business logic and data operations - Django : Authentication and authorization - Database : Data persistence - Background : Asynchronous processing
2. YAML-Driven Development¶
UI components are generated from YAML configuration files, enabling: - Rapid development without writing React code - Consistent UI patterns across the application - Easy customization by non-developers - Configuration-as-code approach
3. Code Generation¶
Automated code generation for APIs and UI: - API Builder : Generates models, schemas, CRUD, routes from database - UI Builder : Generates YAML configs from existing web pages - Reduces boilerplate and ensures consistency
4. Modular Domain Design¶
Business logic is organized into domains: - Company, Finance, HR, Inventory, CRM, Manufacturing, Project - Each domain is self-contained with its own models, routes, and logic - Enables independent development and potential microservices migration
5. Performance Optimization¶
Multiple strategies for optimal performance: - Router modes : Minimal, core, or full loading - Database pooling : Connection reuse and management - Lazy loading : Frontend components and data - Caching : Future Redis caching layer
Key Components¶
Frontend Architecture¶
- React 18 with TypeScript
- Material-UI component library
- YAML-driven page rendering
- Context-based state management
- Axios for API communication
Backend Architecture¶
- FastAPI for business logic
- Django for authentication
- SQLAlchemy ORM for data access
- Pydantic for validation
- Celery for background tasks
Database Architecture¶
- PostgreSQL primary database
- 2000+ tables from legacy ERP
- Connection pooling
- Multi-schema support
- Migration management
YAML-Driven UI¶
- Navigation configuration
- Page definitions
- Table configurations
- Form schemas
- Action definitions
System Statistics¶
| Metric | Value |
|---|---|
| Total API Endpoints | 2016+ |
| Business Domains | 9 |
| Database Tables | 2000+ |
| Frontend Components | 100+ reusable |
| YAML Config Files | Navigation + Pages |
| Supported Operations | CRUD + Custom |
Technology Stack¶
Frontend¶
- Framework : React 18.2
- Language : TypeScript 4.9
- UI Library : Material-UI 7.1
- Forms : React Hook Form 7.56
- HTTP : Axios 1.9
- Routing : React Router 6
- State : React Context API
Backend¶
- API Framework : FastAPI 0.109
- Auth Framework : Django 5.2
- ORM : SQLAlchemy 2.0
- Validation : Pydantic 2.6
- Server : Uvicorn 0.27
- Task Queue : Celery 5.3
Database¶
- Primary DB : PostgreSQL 13+
- Dev Fallback : SQLite
- Cache/Queue : Redis 5.0
Request Flow Examples¶
Reading Data (GET Request)¶
sequenceDiagram
participant U as User
participant R as React
participant Y as YAML Loader
participant F as FastAPI
participant D as Database
U->>R: Click "View Companies"
R->>Y: Load companies.yaml
Y-->>R: Page config
R->>R: Render DataTable
R->>F: GET /api/company/company/
F->>D: SELECT * FROM Company
D-->>F: Result set
F-->>R: JSON response
R->>R: Populate table
R-->>U: Display companies
Creating Data (POST Request)¶
sequenceDiagram
participant U as User
participant R as React
participant F as FastAPI
participant P as Pydantic
participant D as Database
U->>R: Fill form + Submit
R->>R: Validate with React Hook Form
R->>F: POST /api/company/company/
F->>P: Validate CompanyCreate schema
P-->>F: Validation result
F->>D: INSERT INTO Company
D-->>F: New record
F-->>R: JSON response
R->>R: Update UI
R-->>U: Success message
Authentication Flow¶
sequenceDiagram
participant U as User
participant R as React
participant D as Django
participant DB as Database
U->>R: Enter credentials
R->>D: POST /api/auth/login
D->>DB: Verify user
DB-->>D: User record
D->>D: Generate JWT token
D-->>R: {user, token, modules}
R->>R: Store in localStorage
R->>R: Set Authorization header
R-->>U: Redirect to dashboard
Note over R,D: Subsequent API calls
R->>D: GET /api/... (with Bearer token)
D->>D: Verify JWT
D-->>R: Protected resource
Architecture Patterns¶
Repository Pattern¶
Data access is abstracted through CRUD functions:
# crud.py
def get_company(db: Session, company_id: int):
return db.query(Company).filter(Company.CompanyID == company_id).first()
Dependency Injection¶
FastAPI uses dependency injection for database sessions:
@router.get("/")
def read_companies(db: Session = Depends(get_db)):
return crud.get_company_list(db)
Schema Validation¶
Pydantic ensures data integrity:
class CompanyCreate(BaseModel):
CompanyCD: str
CompanyName: str
BaseCuryID: str
Context-Based State¶
React Context for global state management:
const { user, isAuthenticated } = useAuth();
const { navigation } = useNavigation();
Scalability Considerations¶
Horizontal Scaling¶
- Frontend : Static files on CDN
- FastAPI : Multiple workers behind load balancer
- Django : Multiple instances
- Celery : Worker pool scaling
- Database : Read replicas
Vertical Scaling¶
- Increase worker processes
- Increase connection pool size
- Add more RAM for caching
- Optimize database indexes
Caching Strategy (Future)¶
- Redis caching for frequently accessed data
- Browser caching for static assets
- Database query caching
- API response caching
Security Architecture¶
Authentication¶
- JWT token-based authentication
- Token expiration (24 hours default)
- Secure password hashing (bcrypt)
- HTTPS enforcement
Authorization¶
- Role-based access control (RBAC)
- Attribute-based access control (ABAC)
- Route-level permissions
- Field-level permissions
- Action-level permissions
Data Protection¶
- SQL injection prevention (ORM)
- XSS prevention (React escaping)
- CORS configuration
- Input validation (Pydantic)
- Output sanitization
Monitoring and Logging¶
Application Logs¶
- FastAPI: Uvicorn access logs
- Django: Django logging framework
- Celery: Task execution logs
- Frontend: Browser console (dev), error tracking (prod)
Performance Monitoring¶
- Database query performance
- API response times
- Frontend render performance
- Background task duration
Health Checks¶
/healthendpoint on FastAPI- Database connection status
- Redis availability check
Documentation Sections¶
Explore each component in detail:
- System Overview - Complete system architecture
- Frontend Architecture - React and TypeScript
- Backend Architecture - FastAPI and Django
- Database Architecture - PostgreSQL and ORM
- YAML-Driven UI - Configuration system