# naniorion/rugby-controller architecture

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

- Interactive diagram: https://gitdiagram.com/naniorion/rugby-controller
- Repository: https://github.com/naniorion/rugby-controller

## Overview

1. **What this repo is**
   - A **local desktop app** for controlling a rugby broadcast in OBS.
   - It is built as an **Electron shell** with a **React + TypeScript renderer** and a live **browser-source overlay** for OBS.
   - There is **no remote backend** in the architecture; the app is centered on local state and local file import/export.

2. **Top-level runtime boundary**
   - The **Electron main process** (`electron/main.ts`) owns desktop concerns: app startup, window creation, and serving the local UI.
   - The **renderer** is the React app under `src/`, which provides both the operator dashboard and the graphics overlay.
   - `electron/preload.ts` is the bridge boundary for safe IPC exposure, and `electron/timer.ts` suggests timer logic that may live outside the UI layer.

3. **Primary UI split: control plane vs broadcast plane**
   - `src/pages/Dashboard.tsx` is the **operator control panel**: where the user edits match data, scores, timer, cards, lineups, labels, and presentation assets.
   - `src/pages/Overlay.tsx` is the **broadcast output**: the visual layer rendered in OBS via Browser Source.
   - This split is important for diagrams: one side is **input/control**, the other is **presentation/output**.

4. **Central state model**
   - `src/context/MatchContext.tsx` is the main application state hub.
   - It likely holds the full match model: teams, score, timer state, cards, substitutions, lineups, presentation data, logs, and overlay visibility/animations.
   - Most components appear to be thin UI controls that read/write through this context rather than managing their own isolated state.

5. **Match operations and live scoring**
   - The core match workflow is driven by score and event actions: **try, conversion, penalty, drop**, and automated score calculation.
   - `src/components/ActionLog.tsx` records the chronological event feed that feeds both the dashboard and overlay summary views.
   - `src/components/SubstitutionControl.tsx` and card-related logic support live match events and time-based consequences.

6. **Timekeeping and discipline**
   - The app includes a **match clock** with first/second half control, pause/stop, and manual adjustment.
   - Yellow card and red-card variants are supported, including a **20-minute red** with a separate countdown and differentiated notification behavior.
   - This suggests a timer subsystem that is time-sensitive and likely coupled to the central match state rather than treated as a standalone widget.

7. **Team, lineup, and roster management**
   - `src/components/LineupEditor.tsx`, `PlayerSelectorModal.tsx`, and `LabelManager.tsx` support preparing the match roster and on-screen labels.
   - The roster flow includes **bulk import/paste from Excel or notes**, manual editing, and real-time substitutions.
   - These features feed both the dashboard controls and overlay lineup/statistics presentation.

8. **Presentation assets and graphics**
   - The app manages **team names, initials, colors, logos**, plus extra broadcast assets such as sponsor images, league logos, posters, referees, stadium info, and commentators.
   - `src/components/LabelManager.tsx` indicates reusable lower-third style or informational graphics.
   - `src/pages/Overlay.css` and `src/index.css` imply the overlay is heavily styled as a broadcast graphic rather than a generic app page.

9. **Overlay rendering contract**
   - The overlay is meant to be loaded by OBS from a local URL such as `http://localhost:3000/#/overlay`.
   - The overlay consumes the same live match state as the dashboard and renders score, timer, lineup views, stats comparisons, match presentation, and animated transitions.
   - In architecture terms, OBS is an **external consumer** of the app’s render output, not a collaborator with business logic.

10. **Persistence and portability**
   - The app supports **export/import of full match configuration as JSON** for reuse across matches.
   - Assets such as logos and posters are likely kept as local file references or embedded data managed from the dashboard.
   - This makes the app stateful locally, but portable through user-generated config files rather than a database.

11. **Socket/synchronization layer**
   - `src/hooks/useSocket.ts` suggests a communication hook, likely used to propagate live updates across the dashboard/overlay boundary or to coordinate real-time updates.
   - Even if the app is mostly single-process, this hook indicates a dedicated synchronization abstraction rather than ad hoc prop drilling.
   - For a diagram, treat it as the live-update transport between control state and broadcast rendering.

12. **Tooling and packaging**
   - The project uses **Vite** for the renderer build and **TypeScript** throughout.
   - `package.json`, `vite.config.ts`, and `tsconfig.json` define the web build toolchain, while Electron packages it as a desktop application.
   - `docs/` and `public/` are supporting static assets; they are not part of the core runtime path.

13. **Overall data flow**
   - User actions in the **Dashboard** update the **MatchContext**.
   - The context drives timer changes, score updates, lineup edits, and event logging.
   - The **Overlay** reads that shared state and renders broadcast graphics.
   - OBS consumes the overlay through the browser source URL, while JSON import/export lets the operator persist and reload the match setup.

Main entry points: [`src/context/MatchContext.tsx`](https://github.com/naniorion/rugby-controller/blob/master/src/context/MatchContext.tsx) (Match state), [`src/pages/Overlay.tsx`](https://github.com/naniorion/rugby-controller/blob/master/src/pages/Overlay.tsx) (Overlay), [`src/App.tsx`](https://github.com/naniorion/rugby-controller/blob/master/src/App.tsx) (App shell), [`src/pages/Dashboard.tsx`](https://github.com/naniorion/rugby-controller/blob/master/src/pages/Dashboard.tsx) (Dashboard)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_g_electron["Electron runtime"]
  node_electron_main["Main process<br/>electron host<br/>[main.ts]"]
  node_electron_preload["Preload bridge<br/>ipc bridge<br/>[preload.ts]"]
  node_electron_timer(("Timer runtime<br/>native timer<br/>[timer.ts]"))
end

subgraph group_g_renderer["Renderer app"]
  node_app_shell["App shell<br/>React shell<br/>[App.tsx]"]
  node_renderer_boot["Renderer entry<br/>bootstrap<br/>[main.tsx]"]
  node_match_context[("Match state<br/>state hub<br/>[MatchContext.tsx]")]
  node_socket_hook(("Sync hook<br/>live sync<br/>[useSocket.ts]"))
  node_dashboard_page["Dashboard<br/>control panel<br/>[Dashboard.tsx]"]
  node_overlay_page["Overlay<br/>broadcast output<br/>[Overlay.tsx]"]
  node_action_log["Action log<br/>event feed<br/>[ActionLog.tsx]"]
  node_lineup_editor["Lineup editor<br/>roster editor<br/>[LineupEditor.tsx]"]
  node_substitution_control["Substitutions<br/>match action"]
  node_label_manager["Label manager<br/>graphics editor<br/>[LabelManager.tsx]"]
  node_player_selector["Player picker<br/>modal editor"]
  node_overlay_style["Overlay CSS<br/>styling<br/>[Overlay.css]"]
  node_global_style["Global CSS<br/>styling<br/>[index.css]"]
end

subgraph group_g_assets["Static assets"]
  node_public_assets["Public assets<br/>static resources"]
  node_docs_site["Docs site<br/>documentation<br/>[index.html]"]
end

subgraph group_g_tooling["Tooling"]
  node_package_json["Package config<br/>project manifest<br/>[package.json]"]
  node_vite_config["Vite config<br/>build config<br/>[vite.config.ts]"]
  node_tsconfig["TS config<br/>compiler config<br/>[tsconfig.json]"]
end

node_electron_main -->|"exposes IPC"| node_electron_preload
node_electron_main -->|"hosts UI"| node_renderer_boot
node_renderer_boot -->|"mounts"| node_app_shell
node_app_shell -->|"routes to"| node_dashboard_page
node_app_shell -->|"routes to"| node_overlay_page
node_dashboard_page -->|"reads/writes"| node_match_context
node_overlay_page -->|"reads"| node_match_context
node_match_context -->|"feeds"| node_action_log
node_match_context -->|"drives"| node_lineup_editor
node_match_context -->|"drives"| node_substitution_control
node_match_context -->|"drives"| node_label_manager
node_lineup_editor -->|"opens"| node_player_selector
node_electron_timer -->|"updates clock"| node_match_context
node_socket_hook -->|"syncs"| node_match_context
node_socket_hook -->|"broadcasts"| node_overlay_page
node_overlay_page -->|"uses"| node_overlay_style
node_dashboard_page -->|"uses"| node_global_style
node_public_assets -->|"supplies assets"| node_overlay_page
node_docs_site -.->|"supported by"| node_package_json
node_vite_config -->|"builds"| node_renderer_boot
node_tsconfig -.->|"types"| node_app_shell
node_package_json -->|"packages"| node_electron_main

click node_electron_main "https://github.com/naniorion/rugby-controller/blob/master/electron/main.ts"
click node_electron_preload "https://github.com/naniorion/rugby-controller/blob/master/electron/preload.ts"
click node_electron_timer "https://github.com/naniorion/rugby-controller/blob/master/electron/timer.ts"
click node_app_shell "https://github.com/naniorion/rugby-controller/blob/master/src/App.tsx"
click node_renderer_boot "https://github.com/naniorion/rugby-controller/blob/master/src/main.tsx"
click node_match_context "https://github.com/naniorion/rugby-controller/blob/master/src/context/MatchContext.tsx"
click node_socket_hook "https://github.com/naniorion/rugby-controller/blob/master/src/hooks/useSocket.ts"
click node_dashboard_page "https://github.com/naniorion/rugby-controller/blob/master/src/pages/Dashboard.tsx"
click node_overlay_page "https://github.com/naniorion/rugby-controller/blob/master/src/pages/Overlay.tsx"
click node_action_log "https://github.com/naniorion/rugby-controller/blob/master/src/components/ActionLog.tsx"
click node_lineup_editor "https://github.com/naniorion/rugby-controller/blob/master/src/components/LineupEditor.tsx"
click node_substitution_control "https://github.com/naniorion/rugby-controller/blob/master/src/components/SubstitutionControl.tsx"
click node_label_manager "https://github.com/naniorion/rugby-controller/blob/master/src/components/LabelManager.tsx"
click node_player_selector "https://github.com/naniorion/rugby-controller/blob/master/src/components/PlayerSelectorModal.tsx"
click node_overlay_style "https://github.com/naniorion/rugby-controller/blob/master/src/pages/Overlay.css"
click node_global_style "https://github.com/naniorion/rugby-controller/blob/master/src/index.css"
click node_public_assets "https://github.com/naniorion/rugby-controller/tree/master/public/icons"
click node_docs_site "https://github.com/naniorion/rugby-controller/blob/master/docs/index.html"
click node_package_json "https://github.com/naniorion/rugby-controller/blob/master/package.json"
click node_vite_config "https://github.com/naniorion/rugby-controller/blob/master/vite.config.ts"
click node_tsconfig "https://github.com/naniorion/rugby-controller/blob/master/tsconfig.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_electron_main,node_electron_preload,node_electron_timer toneBlue
class node_app_shell,node_renderer_boot,node_match_context,node_socket_hook,node_dashboard_page,node_overlay_page,node_action_log,node_lineup_editor,node_substitution_control,node_label_manager,node_player_selector,node_overlay_style,node_global_style toneAmber
class node_public_assets,node_docs_site toneMint
class node_package_json,node_vite_config,node_tsconfig toneRose
```

## Components

### Electron runtime

Desktop process boundary and IPC bridge

- [Main process](https://github.com/naniorion/rugby-controller/blob/master/electron/main.ts): electron host · Starts the desktop app, creates windows, and serves the local UI · `electron/main.ts`
- [Preload bridge](https://github.com/naniorion/rugby-controller/blob/master/electron/preload.ts): ipc bridge · Safe IPC surface between main and renderer · `electron/preload.ts`
- [Timer runtime](https://github.com/naniorion/rugby-controller/blob/master/electron/timer.ts): native timer · Timer logic that may run outside the React UI layer · `electron/timer.ts`

### Renderer app

React application that powers control and overlay views

- [App shell](https://github.com/naniorion/rugby-controller/blob/master/src/App.tsx): React shell · Top-level renderer composition and route wiring · `src/App.tsx`
- [Renderer entry](https://github.com/naniorion/rugby-controller/blob/master/src/main.tsx): bootstrap · Bootstraps the React renderer into the page · `src/main.tsx`
- [Match state](https://github.com/naniorion/rugby-controller/blob/master/src/context/MatchContext.tsx): state hub · Central match model for score, timer, cards, lineups, assets, and overlay state · `src/context/MatchContext.tsx`
- [Sync hook](https://github.com/naniorion/rugby-controller/blob/master/src/hooks/useSocket.ts): live sync · Abstraction for propagating live updates across the app · `src/hooks/useSocket.ts`
- [Dashboard](https://github.com/naniorion/rugby-controller/blob/master/src/pages/Dashboard.tsx): control panel · Operator workspace for editing match data and live actions · `src/pages/Dashboard.tsx`
- [Overlay](https://github.com/naniorion/rugby-controller/blob/master/src/pages/Overlay.tsx): broadcast output · Browser-source graphics rendered in OBS · `src/pages/Overlay.tsx`
- [Action log](https://github.com/naniorion/rugby-controller/blob/master/src/components/ActionLog.tsx): event feed · Chronological record of match events and operator actions · `src/components/ActionLog.tsx`
- [Lineup editor](https://github.com/naniorion/rugby-controller/blob/master/src/components/LineupEditor.tsx): roster editor · Edits team lineups and player availability · `src/components/LineupEditor.tsx`
- [Substitutions](https://github.com/naniorion/rugby-controller/blob/master/src/components/SubstitutionControl.tsx): match action · Controls live substitutions and related match events · `src/components/SubstitutionControl.tsx`
- [Label manager](https://github.com/naniorion/rugby-controller/blob/master/src/components/LabelManager.tsx): graphics editor · Maintains reusable broadcast labels and lower-third style assets · `src/components/LabelManager.tsx`
- [Player picker](https://github.com/naniorion/rugby-controller/blob/master/src/components/PlayerSelectorModal.tsx): modal editor · Selects and assigns players into roster and lineup workflows · `src/components/PlayerSelectorModal.tsx`
- [Overlay CSS](https://github.com/naniorion/rugby-controller/blob/master/src/pages/Overlay.css): styling · Broadcast-specific overlay styling · `src/pages/Overlay.css`
- [Global CSS](https://github.com/naniorion/rugby-controller/blob/master/src/index.css): styling · Shared application styling · `src/index.css`

### Static assets

Local files and public resources used by the app

- [Public assets](https://github.com/naniorion/rugby-controller/tree/master/public/icons): static resources · Packaged local assets such as icons and other public files · `public/icons`
- [Docs site](https://github.com/naniorion/rugby-controller/blob/master/docs/index.html): documentation · Static documentation and published pages · `docs/index.html`

### Tooling

Build and packaging configuration

- [Package config](https://github.com/naniorion/rugby-controller/blob/master/package.json): project manifest · Dependencies, scripts, and app packaging metadata · `package.json`
- [Vite config](https://github.com/naniorion/rugby-controller/blob/master/vite.config.ts): build config · Renderer build configuration · `vite.config.ts`
- [TS config](https://github.com/naniorion/rugby-controller/blob/master/tsconfig.json): compiler config · TypeScript compilation settings · `tsconfig.json`

## Connections

- Main process → Preload bridge: exposes IPC · Main process publishes a safe bridge to the renderer
- Main process → Renderer entry: hosts UI · Desktop shell serves the renderer application
- Renderer entry → App shell: mounts · Renderer entry mounts the React shell
- App shell → Dashboard: routes to · Operator control view
- App shell → Overlay: routes to · Broadcast output view
- Dashboard → Match state: reads/writes · Dashboard edits the central match model
- Overlay → Match state: reads · Overlay renders from shared live state
- Match state → Action log: feeds · State changes are recorded as match events
- Match state → Lineup editor: drives · Roster and lineup data are synchronized from context
- Match state → Substitutions: drives · Live substitution state and actions flow through context
- Match state → Label manager: drives · Broadcast labels and presentation assets come from shared state
- Lineup editor → Player picker: opens · Lineup editing uses player selection
- Timer runtime → Match state: updates clock · Timer runtime feeds match time and discipline state
- Sync hook → Match state: syncs · Dedicated live-update abstraction keeps state coordinated
- Sync hook → Overlay: broadcasts · Live updates reach the overlay rendering path
- Overlay → Overlay CSS: uses · Overlay-specific visual styling
- Dashboard → Global CSS: uses · Shared styling for the control UI
- Public assets → Overlay: supplies assets · Local graphics and icons used in the app
- Docs site → Package config: supported by · Documentation and static site are part of the project package
- Vite config → Renderer entry: builds · Vite bundles the renderer application
- TS config → App shell: types · TypeScript config governs the app codebase
- Package config → Main process: packages · Desktop app distribution and scripts center on Electron
