Software Architecture - COS301-SE-2025/Swift-Signals GitHub Wiki

๐Ÿšฆ Architectural Requirements Specification

๐Ÿ—๏ธ System Overview

Swift Signals is a comprehensive traffic optimization system designed to analyze traffic patterns, simulate intersection performance, and optimize traffic light timing using machine learning algorithms. The system employs a microservices architecture to ensure scalability, maintainability, and independent deployment of core components including user management, traffic simulation, AI optimization, real-time control, metrics collection, and a web-based frontend interface.


โญ Quality Requirements

๐Ÿš€ Performance

The system must deliver high-performance capabilities to handle real-time traffic data processing and simulation workloads. Response times for web interface interactions should not exceed 2 seconds under normal load conditions. The simulation service must be capable of processing complex intersection scenarios with hundreds of vehicles within acceptable timeframes. Machine learning inference for traffic optimization should complete within 30 seconds for single intersection analysis. The system must support concurrent users and simultaneous simulation runs without degradation in performance.

๐Ÿ“ˆ Scalability

Swift Signals is designed to scale horizontally across multiple dimensions. The microservices architecture enables individual services to scale independently based on demand. The system must support scaling from single intersection analysis to city-wide traffic network optimization. Database systems should handle growing volumes of time-series traffic data and simulation results. The AI service must accommodate training and inference workloads that increase with system adoption. Container orchestration through Kubernetes ensures efficient resource utilization and automatic scaling capabilities.

๐Ÿ›ก๏ธ Reliability and Availability

The system requires high availability with a target uptime of 99.5% to support continuous traffic monitoring and optimization. Critical services like the control service and metrics collection must implement redundancy and failover mechanisms. Data persistence layers must include backup and recovery procedures to prevent loss of historical traffic data and trained models. The API gateway should implement circuit breaker patterns to handle service failures gracefully. Health monitoring and alerting systems must provide proactive notification of system issues.

๐Ÿ”’ Security

Security is paramount given the system's potential integration with municipal traffic infrastructure. Authentication and authorization mechanisms must protect against unauthorized access to traffic control functions. API endpoints require rate limiting and input validation to prevent abuse. Sensitive configuration data and model parameters must be encrypted at rest and in transit. The system should implement audit logging for all configuration changes and control actions. Network security policies must isolate internal services from external access points.

๐Ÿ”ง Maintainability

The codebase must support long-term maintenance and evolution through clear separation of concerns and comprehensive documentation. Each microservice should follow established coding standards and include unit and integration tests. Configuration management through YAML files enables environment-specific deployments without code changes. Service interfaces should be well-defined with comprehensive API documentation to facilitate integration and troubleshooting. API versioning strategies ensure backward compatibility during system updates.

๐Ÿ”Œ Extensibility

The architecture must accommodate future enhancements and integration with external traffic management systems. New intersection types and traffic patterns should be addable without requiring changes to core simulation logic. The AI service should support multiple machine learning algorithms and model types. Plugin architectures enable third-party integrations for traffic data sources and optimization algorithms. The metrics service should accommodate new performance indicators and reporting requirements.

๐Ÿ‘ฅ Usability

The web interface must provide an intuitive experience for traffic engineers and system administrators. Visualization components should clearly present complex traffic data and simulation results. Configuration workflows should guide users through intersection setup and optimization processes. Real-time dashboards must display system status and traffic conditions effectively. Help documentation and user guides should support users of varying technical expertise levels.

๐Ÿค Interoperability

The system must integrate with existing traffic management infrastructure and data sources. Standard protocols and data formats ensure compatibility with third-party traffic monitoring systems. REST APIs enable integration with municipal traffic control centers. Export capabilities allow sharing of optimization results with external planning tools. The system should support common traffic data formats and simulation standards.


๐Ÿ›๏ธ Architectural Patterns

๐Ÿ”ท Microservices Architecture

Swift Signals employs a microservices architecture to achieve modularity, scalability, and independent deployment capabilities. Each core function is implemented as a separate service with its own data store and deployment lifecycle.

๐ŸŽฏ Services:

  • ๐Ÿšช API Gateway: Central entry point providing request routing, authentication, and rate limiting
  • ๐Ÿ‘ค User Service: Handles authentication and user management, with JWT-based login/signup functionality
  • ๐ŸŽฎ Simulation Service: Traffic simulation engine with SUMO integration for intersection modeling
  • ๐Ÿค– Optimization Service: Applies machine learning or heuristic algorithms to generate optimized traffic signal strategies
  • ๐ŸŽ›๏ธ Control Service: Acts as a coordinator between the Simulation Service and the AI Service, ensuring smooth data flow and trigger sequencing
  • ๐Ÿ“Š Metrics Service: Collects and serves statistics about simulation runs and AI performance
  • ๐Ÿ’ป Frontend Service: React-based and Vite web interface for system interaction and visualization

High-Level Diagram

Architecture Diagram

---
icons:
    - name: carbon
      url: https://unpkg.com/@iconify-json/carbon/icons.json
---
architecture-beta

    group userGroup(server)[User Service]
    group simGroup(server)[Simulation Service]
    group aiGroup(server)[Optimisation Service]
    group metGroup(server)[Metrics Service]

    service fe     (disk) [Frontend]
    service api    (internet) [API Gateway]
    service user   (internet) [User Auth] in userGroup
    service userDB (database) [UserDB] in userGroup
    service sim    (internet) [Simulation] in simGroup
    service simDB  (database) [SimDB] in simGroup
    service opt    (internet) [Optimisation] in aiGroup
    service con    (internet) [Controller]
    service met    (internet) [Metrics] in metGroup
    service metDB  (database) [StatsDB] in metGroup
    junction jL
    junction jLL
    junction jR

    fe: B -- T : api
    api: L -- R : jL
    jLL: R -- L : jL
    api: R -- L : jR
    api: B -- T : sim
    sim: B -- T : simDB
    jL: B -- T : user
    user: B -- T : userDB
    jR: B -- T : con
    jLL : B -- T : met
    met : B -- T : metDB
    sim: R -- L : con
    con: R -- L : opt

Sequence Diagram of Optimisation Request

sequenceDiagram
    actor User
    participant FE as Frontend
    participant API as API Gateway
    participant CTRL as Controller Service
    participant SIM as Simulation Service
    participant AI as AI Optimization Service
    User ->> FE: Click "Optimise"
    FE ->> API: POST /optimise
    API ->> CTRL: Forward request
    CTRL ->> SIM: GET /simulation/:id
    SIM -->> CTRL: Return simulation data
    CTRL ->> AI: Send data for optimization
    AI ->> AI: Run optimization algorithm
    AI -->> CTRL: Return optimized data
    CTRL ->> SIM: POST /simulation/:id/update
    CTRL ->> API: Notify optimization done
    API -->> FE: Optimization complete
    FE ->> API: GET /simulation/:id
    API ->> SIM: Forward data request
    SIM -->> API: Return updated simulation
    API -->> FE: Return simulation data

๐Ÿšช API Gateway Pattern

The API Gateway serves as the single entry point for all client requests, providing essential cross-cutting concerns including request routing, authentication, rate limiting, and HTTP-to-gRPC translation. This pattern simplifies client interactions by presenting a unified REST interface while allowing internal services to communicate efficiently via gRPC. The gateway implements load balancing for downstream services and provides centralized logging and monitoring capabilities.

๐Ÿ—„๏ธ Database Per Service Pattern

Each microservice maintains its own database to ensure loose coupling and independent scaling. The User Service utilizes MongoDB for flexible user profile storage, while the Metrics Service employs PostgreSQL for time-series data. This pattern prevents database-level coupling between services and allows for technology choices optimized for specific data access patterns.

โšก Event-Driven Architecture

Services communicate through asynchronous events using gRPC streaming capabilities to reduce coupling and improve system resilience. The simulation service publishes events when simulations complete, triggering downstream processing in the AI and metrics services via efficient binary Protocol Buffer messages. This pattern enables loose coupling between services while maintaining high-performance communication channels and supports eventual consistency across the system.

๐Ÿ“– CQRS (Command Query Responsibility Segregation)

The metrics service implements CQRS to separate read and write operations for optimal performance. Historical traffic data writes are optimized for ingestion speed, while query operations are optimized for complex analytics and reporting. This separation allows for independent scaling of read and write workloads.


๐ŸŽจ Design Patterns

๐Ÿญ Factory Pattern

The AI service employs the Factory pattern to create appropriate machine learning models based on intersection types and optimization requirements. This pattern enables runtime selection of algorithms and supports extensibility for new optimization approaches.

๐Ÿ‘๏ธ Observer Pattern

The control service implements the Observer pattern to notify interested parties when traffic light configurations change. This enables real-time updates to the frontend interface and logging of configuration changes for audit purposes.

๐ŸŽฏ Strategy Pattern

Traffic simulation scenarios use the Strategy pattern to support different intersection types and traffic patterns. This pattern allows the simulation service to handle various intersection configurations through pluggable strategy implementations.

โšก Command Pattern

Configuration changes to traffic light timing are implemented using the Command pattern, providing undo capabilities and audit trails. This pattern enables queuing of configuration changes and rollback functionality for testing scenarios.

๐ŸŽฏ Singleton Pattern

Shared resources like database connection pools and configuration managers are implemented as singletons to ensure efficient resource utilization and consistent configuration across service instances.

๐ŸŽ€ Decorator Pattern

The API gateway uses the Decorator pattern to add cross-cutting concerns like authentication, logging, and rate limiting to request processing pipelines. This pattern enables flexible composition of middleware components.

โšก Circuit Breaker Pattern

Inter-service gRPC communication implements the Circuit Breaker pattern to handle failures gracefully and prevent cascade failures. This pattern improves system resilience by failing fast when downstream services are unavailable and provides automatic retry mechanisms with exponential backoff for transient failures.


โ›“๏ธ Constraints

๐Ÿ’ป Technology Constraints

  • ๐Ÿ”“ Open Source Software Only: All system components must use open-source technologies and libraries to comply with project constraints
  • ๐Ÿ“ฆ Containerization: All services must be containerized using Docker for consistent deployment across environments
  • โ˜ธ๏ธ Kubernetes Orchestration: Production deployments must use Kubernetes for container orchestration and service management
  • โšก gRPC Communication: Inter-service communication must use gRPC protocols with Protocol Buffer serialization for high-performance, type-safe communication between microservices

๐Ÿ—๏ธ Infrastructure Constraints

  • โ˜๏ธ Cloud-Native Design: The system must be designed for cloud deployment with Southern Cross Solutions providing infrastructure resources
  • ๐Ÿ“Š Container Resource Limits: Each service must operate within defined CPU and memory constraints to ensure efficient resource utilization
  • ๐Ÿ” Network Security: Internal service communication must be secured through service mesh or VPN technologies
  • ๐Ÿ’พ Storage Limitations: Database storage must be planned for cost-effectiveness while meeting performance requirements

๐Ÿ‘จโ€๐Ÿ’ป Development Constraints

  • ๐Ÿš€ Independent Deployment: Each microservice must be independently deployable without affecting other services
  • ๐Ÿงช Automated Testing: All services must include comprehensive unit and integration tests with minimum 80% code coverage
  • ๐Ÿ”„ CI/CD Pipeline: Automated build, test, and deployment pipelines must be implemented using GitHub Actions
  • โš™๏ธ Configuration Management: Environment-specific configurations must be externalized and managed through YAML files

๐Ÿ”ง Operational Constraints

  • ๐Ÿ“ˆ Monitoring and Logging: All services must implement structured logging and expose health check endpoints
  • ๐Ÿ—‚๏ธ Data Retention: Historical traffic data must be retained according to specified policies while managing storage costs
  • ๐Ÿ’พ Backup and Recovery: Critical data must be backed up with defined recovery time objectives
  • ๐Ÿ›ก๏ธ Security Compliance: System must implement security best practices including secret management and access controls

โšก Performance Constraints

  • โฑ๏ธ Response Time: Web interface interactions must complete within 2 seconds under normal load
  • ๐ŸŽฎ Simulation Performance: Traffic simulations must complete within acceptable timeframes based on intersection complexity
  • ๐Ÿ‘ฅ Concurrent Users: System must support multiple concurrent users without performance degradation
  • ๐Ÿ“Š Data Processing: Time-series data ingestion must keep pace with real-time traffic monitoring requirements

๐Ÿ”— Integration Constraints

  • ๐ŸŒ Third-Party APIs: Integration with external traffic data sources must handle rate limits and API versioning
  • ๐Ÿš— SUMO Compatibility: Simulation service must maintain compatibility with SUMO traffic simulation software
  • ๐Ÿ“‹ Standard Protocols: External integrations must use industry-standard protocols and data formats
  • ๐Ÿ”„ Backward Compatibility: API changes must maintain backward compatibility for existing integrations

๐ŸŽฏ Conclusion

The Swift Signals architectural requirements specification defines a robust, scalable, and maintainable system for traffic optimization. The microservices architecture provides the flexibility needed for independent development and deployment while addressing critical quality attributes including performance, security, and extensibility. The combination of established architectural and design patterns ensures a solid foundation for the system's evolution and long-term success in optimizing traffic flow and reducing congestion costs. ๐Ÿšฆโœจ