# terry395/sg-election-simulator architecture

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

- Interactive diagram: https://gitdiagram.com/terry395/sg-election-simulator
- Repository: https://github.com/terry395/sg-election-simulator

## Overview

GE2030 Simulator is an interactive Singapore election-boundary, contest, forecast and election-night simulator, with a separate National Planner for population and land-use decisions through 2050. The main election workflow runs from map editing through contests and swings to forecast and simulated results; past-election comparison, reports and coalition building extend that workflow. The planner has its own population, plan-building, simulation and reporting stages. Edges are limited to calls visible in excerpts or capabilities and relationships documented in the README; unsampled implementation details are not assumed.

Main entry points: [`src/App.tsx`](https://github.com/terry395/sg-election-simulator/blob/main/src/App.tsx) (Election app), [`src/planner/PlannerApp.tsx`](https://github.com/terry395/sg-election-simulator/blob/main/src/planner/PlannerApp.tsx) (Planner workspace), [`src/state/derived.tsx`](https://github.com/terry395/sg-election-simulator/blob/main/src/state/derived.tsx) (Live projection), [`src/panels/DrawPanel.tsx`](https://github.com/terry395/sg-election-simulator/blob/main/src/panels/DrawPanel.tsx) (Boundary drawing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_election_ui["Election Workspace"]
  node_election_app["Election app<br/>[App.tsx]"]
  node_map["Map workspace<br/>[MapView.tsx]"]
  node_draw["Boundary drawing<br/>[DrawPanel.tsx]"]
  node_contest["Contest setup<br/>[ContestPanel.tsx]"]
  node_forecast["Forecast controls<br/>[ForecastPanel.tsx]"]
  node_night["Election night<br/>[NightPanel.tsx]"]
end

subgraph group_election_engine["Election Models"]
  node_election_data["Election data loader<br/>[loadData.ts]"]
  node_election_state["Election state<br/>[store.ts]"]
  node_derived["Live projection<br/>[derived.tsx]"]
  node_stats["Boundary statistics<br/>[stats.ts]"]
  node_swing["Vote and seat model<br/>[swing.ts]"]
  node_redistrict["Automatic redistricting<br/>[index.ts]"]
  node_montecarlo["Forecast simulation<br/>[montecarlo.ts]"]
end

subgraph group_election_insights["Election Insights"]
  node_comparison["Past election comparison<br/>[ComparePanels.tsx]"]
  node_election_report["Election report<br/>[ElectionReport.tsx]"]
  node_ebrc["Mock EBRC report<br/>[EbrcReport.tsx]"]
  node_coalition["Coalition builder"]
  node_news["Mock news article<br/>[NewsArticle.tsx]"]
end

subgraph group_planner_ui["National Planner"]
  node_planner_app["Planner workspace<br/>[PlannerApp.tsx]"]
  node_planner_map["Land-use map<br/>[PlannerMap.tsx]"]
  node_planner_build["Plan editing<br/>[BuildPanel.tsx]"]
  node_planner_report["Planner report<br/>[PlannerReport.tsx]"]
end

subgraph group_planner_engine["Planner Models"]
  node_population["Population projection<br/>[population.ts]"]
  node_planner_state["Planner state<br/>[planner.ts]"]
  node_planner_simulation["Plan simulation<br/>[simulate.ts]"]
  node_autoplan["Automatic planning<br/>[autoplan.ts]"]
end

node_user(("Political enthusiast"))

node_user -->|"opens simulator"| node_election_app
node_election_app -->|"loads data"| node_election_data
node_election_app -->|"renders map"| node_map
node_election_app -->|"renders panel"| node_draw
node_election_app -->|"renders panel"| node_contest
node_election_app -->|"renders panel"| node_forecast
node_election_app -->|"renders panel"| node_night
node_draw -->|"auto-draws boundaries"| node_redistrict
node_draw -->|"generates report"| node_ebrc
node_election_state -->|"builds boundary context"| node_stats
node_derived -->|"computes statistics"| node_stats
node_derived -->|"runs election model"| node_swing
node_contest -->|"sets contest inputs"| node_derived
node_forecast -->|"sets swing inputs"| node_derived
node_forecast -->|"runs simulations"| node_montecarlo
node_night -->|"shows final report"| node_election_report
node_night -->|"offers coalition builder"| node_coalition
node_election_report -->|"opens mock article"| node_news
node_comparison -->|"compares past elections"| node_user
node_user -->|"opens planner"| node_planner_app
node_planner_app -->|"renders map"| node_planner_map
node_planner_app -->|"uses projection"| node_population
node_planner_build -->|"edits plan"| node_planner_state
node_planner_state -->|"simulates plan"| node_planner_simulation
node_planner_build -->|"runs auto-plan"| node_autoplan
node_planner_app -->|"shows report"| node_planner_report

click node_election_app "https://github.com/terry395/sg-election-simulator/blob/main/src/App.tsx"
click node_election_data "https://github.com/terry395/sg-election-simulator/blob/main/src/data/loadData.ts"
click node_map "https://github.com/terry395/sg-election-simulator/blob/main/src/map/MapView.tsx"
click node_draw "https://github.com/terry395/sg-election-simulator/blob/main/src/panels/DrawPanel.tsx"
click node_contest "https://github.com/terry395/sg-election-simulator/blob/main/src/panels/ContestPanel.tsx"
click node_forecast "https://github.com/terry395/sg-election-simulator/blob/main/src/panels/ForecastPanel.tsx"
click node_night "https://github.com/terry395/sg-election-simulator/blob/main/src/panels/NightPanel.tsx"
click node_election_state "https://github.com/terry395/sg-election-simulator/blob/main/src/state/store.ts"
click node_derived "https://github.com/terry395/sg-election-simulator/blob/main/src/state/derived.tsx"
click node_stats "https://github.com/terry395/sg-election-simulator/blob/main/src/model/stats.ts"
click node_swing "https://github.com/terry395/sg-election-simulator/blob/main/src/model/swing.ts"
click node_redistrict "https://github.com/terry395/sg-election-simulator/blob/main/src/model/redistrict/index.ts"
click node_montecarlo "https://github.com/terry395/sg-election-simulator/blob/main/src/model/montecarlo.ts"
click node_comparison "https://github.com/terry395/sg-election-simulator/blob/main/src/panels/ComparePanels.tsx"
click node_election_report "https://github.com/terry395/sg-election-simulator/blob/main/src/components/ElectionReport.tsx"
click node_ebrc "https://github.com/terry395/sg-election-simulator/blob/main/src/components/EbrcReport.tsx"
click node_coalition "https://github.com/terry395/sg-election-simulator/blob/main/src/components/CoalitionBuilder.tsx"
click node_news "https://github.com/terry395/sg-election-simulator/blob/main/src/components/NewsArticle.tsx"
click node_planner_app "https://github.com/terry395/sg-election-simulator/blob/main/src/planner/PlannerApp.tsx"
click node_population "https://github.com/terry395/sg-election-simulator/blob/main/src/planner/model/population.ts"
click node_planner_map "https://github.com/terry395/sg-election-simulator/blob/main/src/planner/map/PlannerMap.tsx"
click node_planner_build "https://github.com/terry395/sg-election-simulator/blob/main/src/planner/panels/BuildPanel.tsx"
click node_planner_state "https://github.com/terry395/sg-election-simulator/blob/main/src/planner/state/planner.ts"
click node_planner_simulation "https://github.com/terry395/sg-election-simulator/blob/main/src/planner/model/simulate.ts"
click node_autoplan "https://github.com/terry395/sg-election-simulator/blob/main/src/planner/model/autoplan.ts"
click node_planner_report "https://github.com/terry395/sg-election-simulator/blob/main/src/planner/report/PlannerReport.tsx"

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_election_app,node_map,node_draw,node_contest,node_forecast,node_night toneBlue
class node_election_data,node_election_state,node_derived,node_stats,node_swing,node_redistrict,node_montecarlo toneAmber
class node_comparison,node_election_report,node_ebrc,node_coalition,node_news toneMint
class node_planner_app,node_planner_map,node_planner_build,node_planner_report toneRose
class node_population,node_planner_state,node_planner_simulation,node_autoplan,node_user toneIndigo
```

## Components

### Election Workspace

- [Election app](https://github.com/terry395/sg-election-simulator/blob/main/src/App.tsx): `src/App.tsx`
- [Map workspace](https://github.com/terry395/sg-election-simulator/blob/main/src/map/MapView.tsx): `src/map/MapView.tsx`
- [Boundary drawing](https://github.com/terry395/sg-election-simulator/blob/main/src/panels/DrawPanel.tsx): `src/panels/DrawPanel.tsx`
- [Contest setup](https://github.com/terry395/sg-election-simulator/blob/main/src/panels/ContestPanel.tsx): `src/panels/ContestPanel.tsx`
- [Forecast controls](https://github.com/terry395/sg-election-simulator/blob/main/src/panels/ForecastPanel.tsx): `src/panels/ForecastPanel.tsx`
- [Election night](https://github.com/terry395/sg-election-simulator/blob/main/src/panels/NightPanel.tsx): `src/panels/NightPanel.tsx`

### Election Models

- [Election data loader](https://github.com/terry395/sg-election-simulator/blob/main/src/data/loadData.ts): `src/data/loadData.ts`
- [Election state](https://github.com/terry395/sg-election-simulator/blob/main/src/state/store.ts): `src/state/store.ts`
- [Live projection](https://github.com/terry395/sg-election-simulator/blob/main/src/state/derived.tsx): `src/state/derived.tsx`
- [Boundary statistics](https://github.com/terry395/sg-election-simulator/blob/main/src/model/stats.ts): `src/model/stats.ts`
- [Vote and seat model](https://github.com/terry395/sg-election-simulator/blob/main/src/model/swing.ts): `src/model/swing.ts`
- [Automatic redistricting](https://github.com/terry395/sg-election-simulator/blob/main/src/model/redistrict/index.ts): `src/model/redistrict/index.ts`
- [Forecast simulation](https://github.com/terry395/sg-election-simulator/blob/main/src/model/montecarlo.ts): `src/model/montecarlo.ts`

### Election Insights

- [Past election comparison](https://github.com/terry395/sg-election-simulator/blob/main/src/panels/ComparePanels.tsx): `src/panels/ComparePanels.tsx`
- [Election report](https://github.com/terry395/sg-election-simulator/blob/main/src/components/ElectionReport.tsx): `src/components/ElectionReport.tsx`
- [Mock EBRC report](https://github.com/terry395/sg-election-simulator/blob/main/src/components/EbrcReport.tsx): `src/components/EbrcReport.tsx`
- [Coalition builder](https://github.com/terry395/sg-election-simulator/blob/main/src/components/CoalitionBuilder.tsx): `src/components/CoalitionBuilder.tsx`
- [Mock news article](https://github.com/terry395/sg-election-simulator/blob/main/src/components/NewsArticle.tsx): `src/components/NewsArticle.tsx`

### National Planner

- [Planner workspace](https://github.com/terry395/sg-election-simulator/blob/main/src/planner/PlannerApp.tsx): `src/planner/PlannerApp.tsx`
- [Land-use map](https://github.com/terry395/sg-election-simulator/blob/main/src/planner/map/PlannerMap.tsx): `src/planner/map/PlannerMap.tsx`
- [Plan editing](https://github.com/terry395/sg-election-simulator/blob/main/src/planner/panels/BuildPanel.tsx): `src/planner/panels/BuildPanel.tsx`
- [Planner report](https://github.com/terry395/sg-election-simulator/blob/main/src/planner/report/PlannerReport.tsx): `src/planner/report/PlannerReport.tsx`

### Planner Models

- [Population projection](https://github.com/terry395/sg-election-simulator/blob/main/src/planner/model/population.ts): `src/planner/model/population.ts`
- [Planner state](https://github.com/terry395/sg-election-simulator/blob/main/src/planner/state/planner.ts): `src/planner/state/planner.ts`
- [Plan simulation](https://github.com/terry395/sg-election-simulator/blob/main/src/planner/model/simulate.ts): `src/planner/model/simulate.ts`
- [Automatic planning](https://github.com/terry395/sg-election-simulator/blob/main/src/planner/model/autoplan.ts): `src/planner/model/autoplan.ts`

### Other components

- **Political enthusiast**

## Connections

- Political enthusiast → Election app: opens simulator (evidence: `README.md`)
- Election app → Election data loader: loads data (evidence: `src/App.tsx`)
- Election app → Map workspace: renders map (evidence: `src/App.tsx`)
- Election app → Boundary drawing: renders panel (evidence: `src/App.tsx`)
- Election app → Contest setup: renders panel (evidence: `src/App.tsx`)
- Election app → Forecast controls: renders panel (evidence: `src/App.tsx`)
- Election app → Election night: renders panel (evidence: `src/App.tsx`)
- Boundary drawing → Automatic redistricting: auto-draws boundaries (evidence: `README.md`)
- Boundary drawing → Mock EBRC report: generates report (evidence: `README.md`)
- Election state → Boundary statistics: builds boundary context (evidence: `src/state/store.ts`)
- Live projection → Boundary statistics: computes statistics (evidence: `src/state/derived.tsx`)
- Live projection → Vote and seat model: runs election model (evidence: `src/state/derived.tsx`)
- Contest setup → Live projection: sets contest inputs (evidence: `README.md`)
- Forecast controls → Live projection: sets swing inputs (evidence: `README.md`)
- Forecast controls → Forecast simulation: runs simulations (evidence: `README.md`)
- Election night → Election report: shows final report (evidence: `src/panels/NightPanel.tsx`)
- Election night → Coalition builder: offers coalition builder (evidence: `src/panels/NightPanel.tsx`)
- Election report → Mock news article: opens mock article (evidence: `src/components/ElectionReport.tsx`)
- Past election comparison → Political enthusiast: compares past elections (evidence: `README.md`)
- Political enthusiast → Planner workspace: opens planner (evidence: `README.md`)
- Planner workspace → Land-use map: renders map (evidence: `src/planner/PlannerApp.tsx`)
- Planner workspace → Population projection: uses projection (evidence: `src/planner/PlannerApp.tsx`)
- Plan editing → Planner state: edits plan (evidence: `README.md`)
- Planner state → Plan simulation: simulates plan (evidence: `src/planner/state/planner.ts`)
- Plan editing → Automatic planning: runs auto-plan
- Planner workspace → Planner report: shows report (evidence: `src/planner/PlannerApp.tsx`)
