System Architecture
The Inventory Management System is a full-stack web application built with a modern, maintainable architecture that separates concerns and follows industry best practices.Technology Stack
Backend
- Framework: Flask (Python)
- ORM: SQLAlchemy
- Database: SQLite (development)
- API Style: RESTful JSON API
- Authentication: JWT tokens
- Middleware: CORS, Exception Handling, Logging
Frontend
- Framework: React 19.2
- Build Tool: Vite 7
- Styling: Tailwind CSS 4.2
- Architecture: Hexagonal Architecture (Ports & Adapters)
- State Management: Custom hooks with application layer
High-Level Architecture
Directory Structure
Backend Structure
Frontend Structure
Key Architectural Decisions
1. Modular Design
The system is organized into bounded contexts (modules) that align with business domains:- Product: Core inventory tracking
- Stakeholder: Customer and supplier management
- User: Authentication and authorization
- Audit: Activity logging
- Report: Business intelligence
2. Hexagonal Architecture (Ports & Adapters)
Both backend and frontend follow the Hexagonal Architecture pattern (see Hexagonal Design for details):- Domain: Business logic and entities (framework-agnostic)
- Ports: Interfaces defining contracts
- Adapters: Concrete implementations (Flask controllers, SQLAlchemy repositories, React components)
3. Separation of Concerns
Backend Layers:- Controllers (Adapters): Handle HTTP requests, validate input, return responses
- Domain Services: Implement business logic
- Repositories (Adapters): Manage data persistence
- Models: Define database schema and relationships
- UI Layer: React components and pages
- Application Layer: Use cases and custom hooks
- Domain Layer: Business models and validation
- Adapters: API communication
- Ports: Interface contracts
4. RESTful API Design
The backend exposes RESTful endpoints organized by module:5. Authentication & Authorization
- JWT-based authentication: Stateless token authentication
- Role-based access control: Three roles (Admin, Gestor, Consultor)
- Middleware protection:
@require_roledecorator on endpoints - Password reset: Token-based email flow
backend/CommonLayer/middleware/auth_middleware.py:1
6. Audit Trail
All domain entities inherit fromAuditableEntity which provides:
created_at,created_by: Track entity creationupdated_at,updated_by: Track modifications- Automatic timestamp management via SQLAlchemy hooks
backend/CommonLayer/domain/autitable_entity.py:1
7. Database Schema
SQLAlchemy ORM with declarative base mapping:- Automatic migrations: Not implemented (manual schema evolution)
- Relationships: One-to-many, many-to-one with cascade operations
- Indexes: Strategic indexing on foreign keys and lookup fields
Data Flow Example
Creating a New Product
Frontend Flow:Cross-Cutting Concerns
Logging
- Centralized logger:
CommonLayer.logging.logger - Request/response logging middleware
- Error logging with stack traces
Exception Handling
- Global exception handler catches all unhandled errors
- Returns consistent JSON error responses
- Logs errors with context
backend/CommonLayer/middleware/exception_handler.py:1
CORS Configuration
Scalability Considerations
Current Architecture
- Monolithic: Single Flask application
- SQLite: File-based database
- Synchronous: Blocking I/O operations
Future Enhancements
- Database: Migrate to PostgreSQL or MySQL for production
- Caching: Add Redis for session management and query caching
- Async: Migrate to async Flask or FastAPI
- Microservices: Split modules into independent services
- Message Queue: Add RabbitMQ/Kafka for async operations
- API Gateway: Add rate limiting and load balancing
Security Features
- Password Hashing: Werkzeug security helpers
- JWT Tokens: Secure, stateless authentication
- Role-based Access: Fine-grained endpoint protection
- Input Validation: Request data validation
- SQL Injection Protection: SQLAlchemy parameterized queries
- CORS: Controlled cross-origin access
Development Workflow
-
Backend Development:
-
Frontend Development:
-
Testing:
Related Documentation
- Hexagonal Design - Deep dive into Ports & Adapters pattern
- Database Schema - Complete database structure
- API Reference - Full API documentation