Architectural Pattern
SimulationBank follows Hexagonal Architecture (also known as Ports and Adapters) combined with Domain-Driven Design (DDD) principles. This architecture ensures:- Clean separation of concerns
- Testability and maintainability
- Technology independence at the core
- Clear dependency flow from outside-in
System Architecture
Layer Responsibilities
Domain Layer (Core)
The innermost layer contains:- Entities:
Customer,Teller,DiscreteEventSimulation - Value Objects:
SimulationConfig,Priority,TransactionType - Domain Events:
SimulationEventwith event types - Ports: Interfaces like
CustomerGenerator,MetricsRepository
The domain layer has zero dependencies on external frameworks. It contains pure business logic.
Application Layer
Orchestrates domain logic through use cases:run_simulation.py- Execute simulationgenerate_customer.py- Create customer instancesrecord_customer_served.py- Track metricsget_simulation_report.py- Generate reports
Infrastructure Layer
Provides concrete implementations:- HTTP Adapters: Flask blueprints and controllers
- Generators:
ConfigurableGenerator(Poisson distribution) - Persistence:
InMemoryMetricsRepository - Frontend: React components and state management
Bounded Contexts
The system is organized into bounded contexts:Simulation
Core simulation engine, event processing, and lifecycle management
Customer
Customer generation, attributes, and state transitions
Teller
Teller resources, service operations, and utilization
Queue
Priority queue implementation and ordering logic
Metrics
Metrics collection, aggregation, and reporting
Shared
Shared kernel with common utilities and types
Dependency Rule
Dependencies flow inward only:- Domain layer depends on nothing
- Application layer depends only on domain
- Infrastructure layer depends on both application and domain
Technology Stack
Backend
- Language: Python 3.x
- Web Framework: Flask
- CORS: flask-cors
- Event Queue: Python heapq (min-heap)
- Random Generation: NumPy (exponential distribution)
Frontend
- Language: JavaScript (ES6+)
- Framework: React 19.x
- Build Tool: Vite 7.x
- State Management: React hooks (useState, useEffect)
- HTTP Client: Fetch API
Directory Structure
Design Principles
Separation of Concerns
Each module has a single, well-defined responsibility:- Simulation manages time and event processing
- Customer handles arrival and service logic
- Teller manages resource allocation
- Queue implements priority ordering
- Metrics tracks performance indicators
Dependency Inversion
The domain defines interfaces (ports), and infrastructure provides implementations (adapters):Immutability
Value objects are immutable:Communication Patterns
Frontend ↔ Backend
- Protocol: HTTP/REST
- Format: JSON
- CORS: Enabled for local development
Event Flow
- Frontend sends configuration via POST
/api/simulation/start - Backend creates
DiscreteEventSimulationinstance - Simulation processes events in chronological order
- Frontend polls GET
/api/simulation/statefor updates - Metrics accumulate in
MetricsRepository - Frontend fetches GET
/api/metrics/reportfor analysis
Next Steps
Domain Model
Explore entities, value objects, and domain events
Simulation Engine
Deep dive into the discrete event simulation implementation
Frontend Architecture
Learn about React components and visualization
API Design
Understand the REST API structure