# islam4562/differential-simulator architecture

> Architecture diagram of the GitHub repository islam4562/differential-simulator, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/islam4562/differential-simulator
- Repository: https://github.com/islam4562/differential-simulator

## Overview

Differential Simulator is an interactive Python visualization of a car differential. The user presses arrow keys to change gears or steer; the animation updates simulated gear and wheel motion and redraws the differential alongside a tachometer, steering wheel, and gear indicator. The runtime is a single-file Matplotlib application, so its responsibilities share `code.py`. The README documents the controls and display capabilities; the excerpts show input state and rendering, but omit some wiring and simulation details.

Main entry points: [`code.py`](https://github.com/islam4562/differential-simulator/blob/main/code.py) (Animation update)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_controls["Input and state"]
  node_key_handlers["Key handlers<br/>[code.py]"]
  node_key_state["Key state<br/>[code.py]"]
  node_gear_state["Gear selection<br/>[code.py]"]
end

subgraph group_simulation["Vehicle simulation"]
  node_animation["Animation update<br/>[code.py]"]
  node_drivetrain["Differential motion<br/>[code.py]"]
  node_steering["Steering model<br/>[code.py]"]
end

subgraph group_display["Visualization"]
  node_canvas_setup["Canvas setup<br/>[code.py]"]
  node_differential_view["Differential view<br/>[code.py]"]
  node_tachometer["RPM display<br/>[code.py]"]
  node_steering_view["Steering display<br/>[code.py]"]
  node_gear_view["Gear display<br/>[code.py]"]
  node_labels["Component labels<br/>[code.py]"]
end

node_driver(("Driver"))

node_driver -->|"presses keys"| node_key_handlers
node_key_handlers -->|"updates"| node_key_state
node_key_handlers -->|"selects gear"| node_gear_state
node_key_state -->|"reads input"| node_animation
node_gear_state -->|"reads gear"| node_animation
node_animation -->|"updates motion"| node_drivetrain
node_animation -->|"updates steering"| node_steering
node_canvas_setup -->|"creates artists"| node_differential_view
node_canvas_setup -->|"creates artists"| node_tachometer
node_canvas_setup -->|"creates artists"| node_steering_view
node_canvas_setup -->|"creates artists"| node_gear_view
node_canvas_setup -->|"draws labels"| node_labels
node_animation -->|"updates display"| node_differential_view
node_animation -->|"updates needle"| node_tachometer
node_animation -->|"updates wheel"| node_steering_view
node_animation -->|"updates indicator"| node_gear_view

click node_key_handlers "https://github.com/islam4562/differential-simulator/blob/main/code.py"
click node_key_state "https://github.com/islam4562/differential-simulator/blob/main/code.py"
click node_gear_state "https://github.com/islam4562/differential-simulator/blob/main/code.py"
click node_animation "https://github.com/islam4562/differential-simulator/blob/main/code.py"
click node_drivetrain "https://github.com/islam4562/differential-simulator/blob/main/code.py"
click node_steering "https://github.com/islam4562/differential-simulator/blob/main/code.py"
click node_canvas_setup "https://github.com/islam4562/differential-simulator/blob/main/code.py"
click node_differential_view "https://github.com/islam4562/differential-simulator/blob/main/code.py"
click node_tachometer "https://github.com/islam4562/differential-simulator/blob/main/code.py"
click node_steering_view "https://github.com/islam4562/differential-simulator/blob/main/code.py"
click node_gear_view "https://github.com/islam4562/differential-simulator/blob/main/code.py"
click node_labels "https://github.com/islam4562/differential-simulator/blob/main/code.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_key_handlers,node_key_state,node_gear_state toneBlue
class node_animation,node_drivetrain,node_steering toneAmber
class node_canvas_setup,node_differential_view,node_tachometer,node_steering_view,node_gear_view,node_labels toneMint
class node_driver toneIndigo
```

## Components

### Input and state

- [Key handlers](https://github.com/islam4562/differential-simulator/blob/main/code.py): `code.py`
- [Key state](https://github.com/islam4562/differential-simulator/blob/main/code.py): `code.py`
- [Gear selection](https://github.com/islam4562/differential-simulator/blob/main/code.py): `code.py`

### Vehicle simulation

- [Animation update](https://github.com/islam4562/differential-simulator/blob/main/code.py): `code.py`
- [Differential motion](https://github.com/islam4562/differential-simulator/blob/main/code.py): `code.py`
- [Steering model](https://github.com/islam4562/differential-simulator/blob/main/code.py): `code.py`

### Visualization

- [Canvas setup](https://github.com/islam4562/differential-simulator/blob/main/code.py): `code.py`
- [Differential view](https://github.com/islam4562/differential-simulator/blob/main/code.py): `code.py`
- [RPM display](https://github.com/islam4562/differential-simulator/blob/main/code.py): `code.py`
- [Steering display](https://github.com/islam4562/differential-simulator/blob/main/code.py): `code.py`
- [Gear display](https://github.com/islam4562/differential-simulator/blob/main/code.py): `code.py`
- [Component labels](https://github.com/islam4562/differential-simulator/blob/main/code.py): `code.py`

### Other components

- **Driver**

## Connections

- Driver → Key handlers: presses keys
- Key handlers → Key state: updates
- Key handlers → Gear selection: selects gear
- Key state → Animation update: reads input
- Gear selection → Animation update: reads gear
- Animation update → Differential motion: updates motion
- Animation update → Steering model: updates steering
- Canvas setup → Differential view: creates artists
- Canvas setup → RPM display: creates artists
- Canvas setup → Steering display: creates artists
- Canvas setup → Gear display: creates artists
- Canvas setup → Component labels: draws labels
- Animation update → Differential view: updates display
- Animation update → RPM display: updates needle
- Animation update → Steering display: updates wheel
- Animation update → Gear display: updates indicator
