# lewis500/bus architecture

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

- Interactive diagram: https://gitdiagram.com/lewis500/bus
- Repository: https://github.com/lewis500/bus

## Overview

#### Purpose and entry points
This is a browser-based CoffeeScript simulation/visualization of bus movement and bus bunching (“bottleneck sim”). The HTML entry point is `index.html`; application bootstrap is `app/app.coffee`; the primary controller is `app/mainCtrl.coffee`. A prebuilt browser bundle exists at `dist/bundle.js`.

#### Application composition
The app is organized as an Angular-style component/directive system:
- Root/main presentation component: `app/components/main/mainDer.coffee`
- Map and vehicle visualization components: `app/components/map/mapDer.coffee`, `app/components/map/busDer.coffee`
- Shared behavioral bindings and interaction directives: `app/directives/behavior.coffee`, `app/directives/shifter.coffee`, `app/directives/slider.coffee`

Components own rendered regions; directives encapsulate reusable SVG/DOM behavior and controls.

#### Simulation domain model
The core simulation entities are:
- Buses: `app/models/bus.coffee`
- Bus stops: `app/models/bus_stop.coffee`
- Passengers/demand: `app/models/pax.coffee`

These models define the domain boundary between simulation state and visualization. Bus movement, stop interactions, and passenger accumulation/boarding behavior are expected to be represented through these entities rather than directly in rendering code.

#### Data, settings, and control flow
Runtime state and simulation inputs are centralized behind services:
- `app/services/data.coffee`
- `app/services/settings.coffee`

`mainCtrl.coffee` coordinates the application, consuming settings/data and exposing state to the main component tree. The likely control path is bootstrap → controller/service initialization → model/state updates → map/main component rendering. `app/helpers.coffee` provides shared support logic across these layers.

#### SVG map and chart rendering boundary
The map is a dedicated visualization subsystem:
- `app/components/map/mapDer.coffee`
- `app/components/map/busDer.coffee`
- `app/directives/stopDer.coffee`

Bus and stop models are transformed into SVG/DOM representations here. Chart-like primitives are separated into directives:
- `app/directives/dot.coffee`
- `app/directives/line.coffee`
- `app/directives/xAxis.coffee`
- `app/directives/yAxis.coffee`

This separation allows simulation state to drive both route/map views and time-series or quantitative displays.

#### Interaction and parameter adjustment
User-adjustable simulation behavior is handled through reusable directives:
- `app/directives/slider.coffee`
- `app/directives/shifter.coffee`
- `app/directives/behavior.coffee`
- `app/directives/datum.coffee`

These form the UI-to-settings/state boundary: controls should update service-backed configuration or selected data, while renderers consume resulting state.

#### Build and runtime assets
The project targets the browser, with CoffeeScript source compiled/bundled through `gulpfile.js` and dependencies declared in `package.json`. Styling is primarily LESS/CSS:
- `styles/main.less`
- `styles/slider.css`
- `styles/flex.css`

No backend, database, or external service integration is indicated by the repository tree. Font assets are bundled locally under `styles/font/`.

Main entry points: [`app/services/data.coffee`](https://github.com/lewis500/bus/blob/master/app/services/data.coffee) (Data service), [`app/mainCtrl.coffee`](https://github.com/lewis500/bus/blob/master/app/mainCtrl.coffee) (Main controller), [`app/components/map/mapDer.coffee`](https://github.com/lewis500/bus/blob/master/app/components/map/mapDer.coffee) (Map component), [`app/components/main/mainDer.coffee`](https://github.com/lewis500/bus/blob/master/app/components/main/mainDer.coffee) (Main component)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_browser["Browser runtime"]
  node_html["HTML entry<br/>browser entry<br/>[index.html]"]
  node_bundle["Browser bundle<br/>compiled JavaScript<br/>[bundle.js]"]
end

subgraph group_core["Application core"]
  node_bootstrap["App bootstrap<br/>CoffeeScript entry<br/>[app.coffee]"]
  node_controller["Main controller<br/>application controller<br/>[mainCtrl.coffee]"]
  node_data["Data service<br/>runtime state service<br/>[data.coffee]"]
  node_settings["Settings service<br/>simulation configuration<br/>[settings.coffee]"]
  node_helpers["Shared helpers<br/>support logic<br/>[helpers.coffee]"]
end

subgraph group_domain["Simulation domain"]
  node_bus["Bus model<br/>simulation entity<br/>[bus.coffee]"]
  node_stop["Bus stop model<br/>simulation entity<br/>[bus_stop.coffee]"]
  node_passengers["Passenger model<br/>demand entity<br/>[pax.coffee]"]
end

subgraph group_visuals["Visualization and controls"]
  node_main["Main component<br/>root presentation component<br/>[mainDer.coffee]"]
  node_map["Map component<br/>SVG map renderer<br/>[mapDer.coffee]"]
  node_busview["Bus view<br/>vehicle renderer<br/>[busDer.coffee]"]
  node_stopview["Stop directive<br/>stop renderer<br/>[stopDer.coffee]"]
  node_charts["Chart directives<br/>quantitative SVG primitives<br/>[line.coffee]"]
  node_controls["Interaction directives<br/>parameter controls<br/>[slider.coffee]"]
end

subgraph group_build["Build assets"]
  node_build{{"Gulp build<br/>asset pipeline<br/>[gulpfile.js]"}}
  node_styles["Stylesheets<br/>LESS/CSS assets<br/>[main.less]"]
  node_package["Package manifest<br/>dependency manifest<br/>[package.json]"]
end

node_html -->|"loads"| node_bundle
node_bundle -.->|"contains compiled app"| node_bootstrap
node_bootstrap -->|"initializes"| node_controller
node_controller -->|"consumes"| node_data
node_controller -->|"consumes"| node_settings
node_controller -->|"uses"| node_helpers
node_data -->|"holds simulation state"| node_bus
node_data -->|"holds route stops"| node_stop
node_data -->|"holds demand state"| node_passengers
node_settings -->|"configures simulation"| node_data
node_controller -->|"provides state"| node_main
node_main -->|"composes"| node_map
node_map -->|"renders vehicles"| node_busview
node_map -->|"renders stops"| node_stopview
node_data -->|"drives map state"| node_map
node_data -->|"drives chart data"| node_charts
node_main -->|"hosts controls"| node_controls
node_controls -->|"updates parameters"| node_settings
node_build -->|"produces"| node_bundle
node_package -->|"declares tooling"| node_build
node_styles -->|"styles interface"| node_html

click node_html "https://github.com/lewis500/bus/blob/master/index.html"
click node_bundle "https://github.com/lewis500/bus/blob/master/dist/bundle.js"
click node_bootstrap "https://github.com/lewis500/bus/blob/master/app/app.coffee"
click node_controller "https://github.com/lewis500/bus/blob/master/app/mainCtrl.coffee"
click node_data "https://github.com/lewis500/bus/blob/master/app/services/data.coffee"
click node_settings "https://github.com/lewis500/bus/blob/master/app/services/settings.coffee"
click node_helpers "https://github.com/lewis500/bus/blob/master/app/helpers.coffee"
click node_bus "https://github.com/lewis500/bus/blob/master/app/models/bus.coffee"
click node_stop "https://github.com/lewis500/bus/blob/master/app/models/bus_stop.coffee"
click node_passengers "https://github.com/lewis500/bus/blob/master/app/models/pax.coffee"
click node_main "https://github.com/lewis500/bus/blob/master/app/components/main/mainDer.coffee"
click node_map "https://github.com/lewis500/bus/blob/master/app/components/map/mapDer.coffee"
click node_busview "https://github.com/lewis500/bus/blob/master/app/components/map/busDer.coffee"
click node_stopview "https://github.com/lewis500/bus/blob/master/app/directives/stopDer.coffee"
click node_charts "https://github.com/lewis500/bus/blob/master/app/directives/line.coffee"
click node_controls "https://github.com/lewis500/bus/blob/master/app/directives/slider.coffee"
click node_build "https://github.com/lewis500/bus/blob/master/gulpfile.js"
click node_styles "https://github.com/lewis500/bus/blob/master/styles/main.less"
click node_package "https://github.com/lewis500/bus/blob/master/package.json"

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_html,node_bundle toneBlue
class node_bootstrap,node_controller,node_data,node_settings,node_helpers toneAmber
class node_bus,node_stop,node_passengers toneMint
class node_main,node_map,node_busview,node_stopview,node_charts,node_controls toneRose
class node_build,node_styles,node_package toneIndigo
```

## Components

### Browser runtime

- [HTML entry](https://github.com/lewis500/bus/blob/master/index.html): browser entry · `index.html`
- [Browser bundle](https://github.com/lewis500/bus/blob/master/dist/bundle.js): compiled JavaScript · `dist/bundle.js`

### Application core

- [App bootstrap](https://github.com/lewis500/bus/blob/master/app/app.coffee): CoffeeScript entry · `app/app.coffee`
- [Main controller](https://github.com/lewis500/bus/blob/master/app/mainCtrl.coffee): application controller · Coordinates state and exposes it to the component tree. · `app/mainCtrl.coffee`
- [Data service](https://github.com/lewis500/bus/blob/master/app/services/data.coffee): runtime state service · `app/services/data.coffee`
- [Settings service](https://github.com/lewis500/bus/blob/master/app/services/settings.coffee): simulation configuration · `app/services/settings.coffee`
- [Shared helpers](https://github.com/lewis500/bus/blob/master/app/helpers.coffee): support logic · `app/helpers.coffee`

### Simulation domain

- [Bus model](https://github.com/lewis500/bus/blob/master/app/models/bus.coffee): simulation entity · `app/models/bus.coffee`
- [Bus stop model](https://github.com/lewis500/bus/blob/master/app/models/bus_stop.coffee): simulation entity · `app/models/bus_stop.coffee`
- [Passenger model](https://github.com/lewis500/bus/blob/master/app/models/pax.coffee): demand entity · Represents passenger accumulation and boarding demand. · `app/models/pax.coffee`

### Visualization and controls

- [Main component](https://github.com/lewis500/bus/blob/master/app/components/main/mainDer.coffee): root presentation component · `app/components/main/mainDer.coffee`
- [Map component](https://github.com/lewis500/bus/blob/master/app/components/map/mapDer.coffee): SVG map renderer · `app/components/map/mapDer.coffee`
- [Bus view](https://github.com/lewis500/bus/blob/master/app/components/map/busDer.coffee): vehicle renderer · `app/components/map/busDer.coffee`
- [Stop directive](https://github.com/lewis500/bus/blob/master/app/directives/stopDer.coffee): stop renderer · `app/directives/stopDer.coffee`
- [Chart directives](https://github.com/lewis500/bus/blob/master/app/directives/line.coffee): quantitative SVG primitives · Dots, lines, and axes render state-driven charts. · `app/directives/line.coffee`
- [Interaction directives](https://github.com/lewis500/bus/blob/master/app/directives/slider.coffee): parameter controls · Sliders, shifters, behavior, and datum bindings update configuration or selection. · `app/directives/slider.coffee`

### Build assets

- [Gulp build](https://github.com/lewis500/bus/blob/master/gulpfile.js): asset pipeline · Compiles and bundles CoffeeScript for the browser. · `gulpfile.js`
- [Stylesheets](https://github.com/lewis500/bus/blob/master/styles/main.less): LESS/CSS assets · `styles/main.less`
- [Package manifest](https://github.com/lewis500/bus/blob/master/package.json): dependency manifest · `package.json`

## Connections

- HTML entry → Browser bundle: loads
- Browser bundle → App bootstrap: contains compiled app
- App bootstrap → Main controller: initializes
- Main controller → Data service: consumes
- Main controller → Settings service: consumes
- Main controller → Shared helpers: uses
- Data service → Bus model: holds simulation state
- Data service → Bus stop model: holds route stops
- Data service → Passenger model: holds demand state
- Settings service → Data service: configures simulation
- Main controller → Main component: provides state
- Main component → Map component: composes
- Map component → Bus view: renders vehicles
- Map component → Stop directive: renders stops
- Data service → Map component: drives map state
- Data service → Chart directives: drives chart data
- Main component → Interaction directives: hosts controls
- Interaction directives → Settings service: updates parameters
- Gulp build → Browser bundle: produces
- Package manifest → Gulp build: declares tooling
- Stylesheets → HTML entry: styles interface
