# alialfredji/car-simulator architecture

> Architecture diagram of the GitHub repository alialfredji/car-simulator, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/alialfredji/car-simulator
- Repository: https://github.com/alialfredji/car-simulator

## Overview

##### Main Components
- User Interface / Input Handler: Represents the console-based CLI where users enter grid dimensions and driving commands.
- Simulation Engine: The core of the application responsible for processing the simulation. This includes:
- Manual Mode Simulator (src/simulator.js) that processes real-time user commands.
- Automated Mode Simulator (src/simulator-auto.js) that runs predefined maneuvers.
- Grid Manager and Collision Detector: The logic that maintains the grid (dynamically set dimensions) and checks for collisions (preventing crashes when moves would overlap or go out of bounds).
- Test Suite: Even though tests are not explicitly shown in the file tree, the README notes their presence, so include a component representing automated tests ensuring the simulator’s reliability.
- Build/Development Tools: Auxiliary components such as the ESLint configuration (.eslintrc.js), Makefile for build commands, and GitHub workflows (CI/CD Integration in the .github directory).

##### Relationships and Interactions
- The User Interface takes user input (grid dimensions and movement commands) and passes them to the Simulation Engine.
- The Simulation Engine (differentiated into manual and automated modes) relies on the Grid Manager to update positions and detect collisions.
- Collision Detection works by checking proposed moves against grid boundaries and existing positions.
- The Simulation Engine provides feedback back to the User Interface (e.g., alerts for potential collisions).
- The Test Suite runs separately to ensure that the simulation and collision detection logic works as intended.
- External configuration and CI/CD pipelines indirectly support the core components by ensuring code quality and continuous integration.

##### Architecturally Important Patterns and Principles
- Separation of Concerns: The project cleanly separates user interaction (input/output) from simulation logic.
- Modular Design: With distinct modules for manual and automated modes (separated files), it’s easier to extend or modify simulation behavior.
- Integration of Automated Testing: Emphasizing unit tests ensures that each component (mainly the simulation logic) remains robust.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interface Layer
    subgraph "User Interface"
        CLI["CLI Input Handler"]:::cli
    end

    %% Simulation Engine Layer
    subgraph "Simulation Engine"
        MANUAL["Manual Simulation Engine"]:::process
        AUTOMATED["Automated Simulation Engine"]:::process
        GRID["Grid Manager & Collision Detection"]:::process
    end

    %% Auxiliary Components
    subgraph "Auxiliary Components"
        TEST["Test Suite"]:::aux
        subgraph "Build & CI/CD Tools"
            ESLINT["ESLint Configuration"]:::aux
            MAKEFILE["Makefile"]:::aux
            CICD["CI/CD Integration"]:::aux
        end
    end

    %% Data Flow
    CLI -->|"userCommands"| MANUAL
    CLI -->|"userCommands"| AUTOMATED

    MANUAL -->|"processMove"| GRID
    AUTOMATED -->|"processManeuver"| GRID

    GRID -->|"statusUpdate"| MANUAL
    GRID -->|"statusUpdate"| AUTOMATED

    MANUAL -->|"feedback"| CLI
    AUTOMATED -->|"feedback"| CLI

    %% Testing loop to Simulation Engine (validating simulation components)
    TEST -- "validate" --> MANUAL
    TEST -- "validate" --> AUTOMATED
    TEST -- "validate" --> GRID

    %% Build & CI/CD Tools support loop (indirect support)
    ESLINT --- GRID
    MAKEFILE --- GRID
    CICD --- GRID

    %% Click Events
    click MANUAL "https://github.com/alialfredji/car-simulator/blob/master/src/simulator.js"
    click AUTOMATED "https://github.com/alialfredji/car-simulator/blob/master/src/simulator-auto.js"
    click ESLINT "https://github.com/alialfredji/car-simulator/blob/master/.eslintrc.js"
    click MAKEFILE "https://github.com/alialfredji/car-simulator/tree/master/Makefile"
    click CICD "https://github.com/alialfredji/car-simulator/blob/master/.github/workflows/project.yml"

    %% Styles
    classDef cli fill:#ffcc00,stroke:#333,stroke-width:2px,stroke-dasharray: 5 5;
    classDef process fill:#99ccff,stroke:#333,stroke-width:2px;
    classDef aux fill:#ccffcc,stroke:#333,stroke-width:2px;
```
