# rogermt/pub-restaurant-simulation architecture

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

- Interactive diagram: https://gitdiagram.com/rogermt/pub-restaurant-simulation
- Repository: https://github.com/rogermt/pub-restaurant-simulation

## Overview

##### Project Type and Purpose
- This is a discrete-event simulation project for modeling a fast-food restaurant scenario in a UK pub.
- The simulation leverages the SimPy library and centers on modeling customer arrivals, order processing, food preparation, and delivery events.
- The overall goal is to optimize restaurant performance by minimizing wait times and maximizing customer throughput.

##### File Structure
- Top-Level Files:
- main.py acts as the entry point to the simulation.
- config.py in the src directory provides simulation parameters.
- Modules like customer.py, driver.py, and restaurant_stub.py represent various simulation entities.
- Additional Files:
- The tests directory ensures code reliability.
- Configuration files (.flake8, mypy.ini, pytest.ini, pyproject.toml, etc.) and scripts (setup.py, requirements.txt) indicate a well-organized Python project.
- Architectural Clues:
- The modular structure under src suggests clear separation between simulation engine, configuration, and domain-specific entities.
- There is no separation into a typical frontend/backend but rather a focus on simulation processes.

##### README for Additional Insights
- The README confirms that the project is implemented using SimPy, emphasizing the simulation aspect.
- It mentions discrete events including customer arrivals, order placement, food preparation, and delivery.
- The command-line interface implies that the simulation is started via the CLI and runs as a standalone process.

a. Main Components to Include:
- Simulation Environment: Representing the SimPy engine that governs the event scheduling and execution.
- Configuration Module: (src/config.py) which holds simulation parameters. This feeds into the initialization of the simulation.
- Customer Process: (src/customer.py) modeling customer arrivals and their interactions.
- Restaurant Process (or Stub): (src/restaurant_stub.py) handling order reception and food preparation.
- Driver Process: (src/driver.py) managing order deliveries.
- Command-Line Interface: The role of main.py, which initializes the simulation engine by coordinating the above modules.

b. Determining Relationships and Interactions:
- main.py initializes the simulation and loads configuration (from config.py) to set parameters (arrival rates, preparation times, etc.).
- The Simulation Environment (SimPy engine) is at the core, scheduling discrete events for each entity.
- Customer processes are triggered based on arrival events and pass control to the restaurant process when placing orders.
- The restaurant process (restaurant_stub.py) simulates order processing and interacts with both the customer and driver processes.
- The driver process (driver.py) picks up completed orders and facilitates order delivery, completing the cycle.

c. Architectural Patterns and Design Principles:
- Discrete-event simulation pattern using SimPy.
- Modules are designed for separation of concerns, with each simulation entity in its own file/module.
- The simulation follows an event-driven architecture where processes interact within the simulation environment.
- This modular design enables easy customization, testing, and extension of individual components.

d. Mention Relevant Technologies, Frameworks, or Libraries:
- Primary framework: SimPy (discrete-event simulation)
- Python’s standard library for CLI-based execution.
- Testing frameworks (pytest) ensuring simulation accuracy.
- Configuration management using a dedicated config module.

##### Elements
- Clear labels for each component (Main Simulation Engine, Config, Customer, Restaurant, Driver).
- Optionally, note that the test suite exists separately to validate these interactions.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["Main Simulation Engine (main.py)"]:::engine
    B["Configuration Module (src/config.py)"]:::config
    C["Simulation Environment (SimPy Engine)"]:::engine
    subgraph "Simulation Entities"
        D["Customer Process (src/customer.py)"]:::process
        E["Restaurant Process (src/restaurant_stub.py)"]:::process
        F["Driver Process (src/driver.py)"]:::process
    end
    G["Testing Suite (tests/)"]:::test

    A -->|"loads"| B
    B -->|"injectsConfig"| C
    C -->|"schedulesCustomer"| D
    D -->|"placesOrder"| E
    E -->|"notifiesReady"| F
    F -->|"deliversOrder"| C

    click A "https://github.com/rogermt/pub-restaurant-simulation/blob/main/main.py"
    click B "https://github.com/rogermt/pub-restaurant-simulation/blob/main/src/config.py"
    click D "https://github.com/rogermt/pub-restaurant-simulation/blob/main/src/customer.py"
    click E "https://github.com/rogermt/pub-restaurant-simulation/blob/main/src/restaurant_stub.py"
    click F "https://github.com/rogermt/pub-restaurant-simulation/blob/main/src/driver.py"
    click G "https://github.com/rogermt/pub-restaurant-simulation/tree/main/tests/"

    classDef engine fill:#ffcc00,stroke:#000,stroke-width:2px;
    classDef config fill:#add8e6,stroke:#000,stroke-width:2px;
    classDef process fill:#90ee90,stroke:#000,stroke-width:2px;
    classDef test fill:#ff9999,stroke:#000,stroke-width:2px;
```
