# leoyuku/rcas architecture

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

- Interactive diagram: https://gitdiagram.com/leoyuku/rcas
- Repository: https://github.com/leoyuku/rcas

## Overview

1. **Repository shape**
   This is a TypeScript monorepo for RCAS, an automated playout/control system. The active runtime lives in `packages/backend`, `packages/frontend`, and `packages/core-lib`. There is also a large `gcloudignore/reference/sofie-core` tree, which is a vendored reference copy of Sofie Core used as architectural inspiration and source material, not the primary application runtime.

2. **Shared contract layer**
   `packages/core-lib` is the only intentional shared dependency between backend and frontend. It defines the canonical data models for rundowns, parts, pieces, timelines, and socket/event contracts. This enforces the repo’s boundary: backend and frontend do not depend on each other directly, only on shared contracts.

3. **Backend top-level composition**
   `packages/backend` is the system brain. Its `src/index.ts` boots one of two execution styles: a monolith entrypoint or a microservice entrypoint. The backend also has adapters for local in-memory execution and gRPC, which suggests the same domain code can run either in-process or across process boundaries.

4. **Backend shared infrastructure**
   `packages/backend/src/shared` centralizes cross-cutting concerns: configuration loading, structured logging, startup checks, shared event bus, and startup health validation. This keeps runtime environment handling out of the domain layers.

5. **MOS/NCS connectivity boundary**
   `modules/1_mos_connection` is the protocol ingress layer. It handles MOS socket connections, XML/message parsing, and profile-specific MOS behavior, especially the supported profiles 0, 2, and 4. Its job is to accept newsroom/NCS updates and normalize them into the system’s internal ingest representation.

6. **Ingest transformation**
   `modules/2_ingest` is the translation layer from MOS running orders into the internal rundown model. The main file, `mos-to-rundown.ts`, is a pure conversion boundary between editorial input and the domain engine. This is where inbound MOS structure becomes RCAS/IRundown data.

7. **Domain engine and state machine**
   `modules/3_domain_engine` is the core of the architecture. It contains:
   - a **store** for rundown state, socket serving, JSON persistence, and MOS caching
   - an **engine** for rundown lifecycle, state loop, PartInstance management, timeline building, resolver/diff logic, and runtime crash recovery  
   This is the layer that implements the repo’s “single source of truth” concept: models plus time produce desired system state.

8. **Timeline and diff pipeline**
   The engine is explicitly state-driven. Rundown/part data is turned into timeline objects, then resolved into a desired device state, then diffed against the last sent state to generate device commands. That makes the architecture predictive and reconstructable: current model + current time should be enough to rebuild the correct output state.

9. **Playout control layer**
   `modules/4_playout_controllers` adapts abstract playout intent into device-specific commands. Today the concrete implementation is for Blackmagic Tricaster, via a client/driver pair that sends commands over WebSocket and retries with backoff. The abstraction also includes device config, execution strategy resolution, runtime overrides, and a pluggable device interface for future drivers.

10. **Frontend role**
   `packages/frontend` is a React/Vite UI with Zustand state management. It presents rundown and playout control views such as preview/on-air/next, source cards, timing panels, and configuration screens. The frontend consumes backend contracts from `core-lib` and is primarily an operator console, not a source of business truth.

11. **External integration points**
   The important external systems are MOS/NCS on the ingest side and Tricaster on the playout side. The repo also contains hooks for gRPC-based backend deployment, implying the system can be split into services later without rewriting the domain model.

12. **Persistence and recovery**
   The backend persists rundown JSON, runtime snapshots, and config history under `packages/backend/config-history`. Crash recovery is part of the architecture, not an afterthought: runtime state is designed to be rebuilt from persisted rundown data plus current time. That is a key diagram boundary between ephemeral runtime state and durable state.

13. **Support tooling**
   `tools/quick-mos` and `tools/quick-mos-patch` are validation and conversion utilities for MOS samples and diffs. They are not part of the runtime path, but they matter because they validate the MOS translation layer and help test protocol compatibility.

14. **Operational identity**
   The repo is not a generic CRUD app. It is a deterministic, time-driven control system with a strict pipeline: protocol ingest → model translation → timeline/state resolution → device diff/dispatch → operator UI feedback. Any architecture diagram should emphasize those one-way data flows and the clear separation between editorial data, runtime state, and physical device control.

Main entry points: [`packages/backend/src/index.ts`](https://github.com/leoyuku/rcas/blob/main/packages/backend/src/index.ts) (Backend entry), [`packages/frontend/src`](https://github.com/leoyuku/rcas/tree/main/packages/frontend/src) (Frontend app), [`packages/backend/src/modules/1_mos_connection/helper/mosModel`](https://github.com/leoyuku/rcas/tree/main/packages/backend/src/modules/1_mos_connection/helper/mosModel) (MOS parser), [`packages/backend/src/modules/2_ingest/mos-to-rundown.ts`](https://github.com/leoyuku/rcas/blob/main/packages/backend/src/modules/2_ingest/mos-to-rundown.ts) (Ingest translate)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Active runtime"]
  node_backend_entry["Backend entry<br/>bootstraps runtime<br/>[index.ts]"]
  node_backend_shared["Shared infra<br/>config/logging"]
  node_backend_adapter["Service adapters<br/>in-memory/grpc"]
  node_mos_connector["MOS ingress<br/>socket protocol"]
  node_mos_parser["MOS parser<br/>xml/message parsing"]
  node_ingest_translate["Ingest translate<br/>mos→rundown<br/>[mos-to-rundown.ts]"]
  node_domain_store[("Domain store<br/>state/persistence")]
  node_domain_engine["Engine core<br/>lifecycle/state machine"]
  node_timeline_pipeline["Timeline flow<br/>build/resolve/diff"]
  node_playout_controller["Playout ctrl<br/>device adaptation"]
  node_tricaster_driver["Tricaster driver<br/>ws device client"]
  node_core_contracts["Core lib<br/>shared contracts"]
  node_frontend_app["Frontend app<br/>react operator UI"]
  node_frontend_store["UI state<br/>zustand store<br/>[useRCASStore.ts]"]
  node_frontend_views["UI panels<br/>rundown/playout views"]
end

subgraph group_reference["Vendored reference"]
  node_sofie_ref["Sofie Core<br/>vendored reference<br/>[sofie-core]"]
end

subgraph group_tools["Support tools"]
  node_quick_mos["Quick MOS<br/>validation utility"]
  node_quick_mos_patch["MOS patch<br/>conversion utility"]
end

node_backend_entry -->|"uses"| node_backend_shared
node_backend_entry -->|"selects"| node_backend_adapter
node_backend_entry -->|"boots"| node_mos_connector
node_mos_connector -->|"parses"| node_mos_parser
node_mos_parser -->|"feeds"| node_ingest_translate
node_ingest_translate -->|"loads"| node_domain_store
node_domain_store -->|"serves"| node_domain_engine
node_domain_engine -->|"builds"| node_timeline_pipeline
node_timeline_pipeline -->|"diffs to"| node_playout_controller
node_playout_controller -->|"implements"| node_tricaster_driver
node_backend_shared -->|"shares"| node_core_contracts
node_frontend_app -->|"consumes"| node_core_contracts
node_frontend_app -->|"manages"| node_frontend_store
node_frontend_app -->|"renders"| node_frontend_views
node_frontend_views -->|"reads"| node_frontend_store
node_backend_entry -.->|"inspired by"| node_sofie_ref
node_mos_parser -.->|"validated by"| node_quick_mos
node_ingest_translate -.->|"validated by"| node_quick_mos_patch
node_playout_controller -.->|"inspired by"| node_sofie_ref

click node_backend_entry "https://github.com/leoyuku/rcas/blob/main/packages/backend/src/index.ts"
click node_backend_shared "https://github.com/leoyuku/rcas/tree/main/packages/backend/src/shared"
click node_backend_adapter "https://github.com/leoyuku/rcas/tree/main/packages/backend/src/adapters"
click node_mos_connector "https://github.com/leoyuku/rcas/tree/main/packages/backend/src/modules/1_mos_connection"
click node_mos_parser "https://github.com/leoyuku/rcas/tree/main/packages/backend/src/modules/1_mos_connection/helper/mosModel"
click node_ingest_translate "https://github.com/leoyuku/rcas/blob/main/packages/backend/src/modules/2_ingest/mos-to-rundown.ts"
click node_domain_store "https://github.com/leoyuku/rcas/tree/main/packages/backend/src/modules/3_domain_engine/store"
click node_domain_engine "https://github.com/leoyuku/rcas/tree/main/packages/backend/src/modules/3_domain_engine/engine"
click node_timeline_pipeline "https://github.com/leoyuku/rcas/blob/main/packages/backend/src/modules/3_domain_engine/engine/timeline-builder.ts"
click node_playout_controller "https://github.com/leoyuku/rcas/blob/main/packages/backend/src/modules/4_playout_controllers/playout-controller.ts"
click node_tricaster_driver "https://github.com/leoyuku/rcas/tree/main/packages/backend/src/modules/4_playout_controllers/tricaster"
click node_core_contracts "https://github.com/leoyuku/rcas/tree/main/packages/core-lib/src"
click node_frontend_app "https://github.com/leoyuku/rcas/tree/main/packages/frontend/src"
click node_frontend_store "https://github.com/leoyuku/rcas/blob/main/packages/frontend/src/store/useRCASStore.ts"
click node_frontend_views "https://github.com/leoyuku/rcas/tree/main/packages/frontend/src/components"
click node_sofie_ref "https://github.com/leoyuku/rcas/blob/main/.gcloudignore/reference/sofie-core"
click node_quick_mos "https://github.com/leoyuku/rcas/tree/main/tools/quick-mos"
click node_quick_mos_patch "https://github.com/leoyuku/rcas/tree/main/tools/quick-mos-patch"

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_backend_entry,node_backend_shared,node_backend_adapter,node_mos_connector,node_mos_parser,node_ingest_translate,node_domain_store,node_domain_engine,node_timeline_pipeline,node_playout_controller,node_tricaster_driver,node_core_contracts,node_frontend_app,node_frontend_store,node_frontend_views toneBlue
class node_sofie_ref toneAmber
class node_quick_mos,node_quick_mos_patch toneMint
```

## Components

### Active runtime

Primary RCAS application packages that make up the live system.

- [Backend entry](https://github.com/leoyuku/rcas/blob/main/packages/backend/src/index.ts): bootstraps runtime · Starts monolith or microservice execution styles and wires backend composition. · `packages/backend/src/index.ts`
- [Shared infra](https://github.com/leoyuku/rcas/tree/main/packages/backend/src/shared): config/logging · Cross-cutting backend services for config, logging, startup checks, and event bus. · `packages/backend/src/shared`
- [Service adapters](https://github.com/leoyuku/rcas/tree/main/packages/backend/src/adapters): in-memory/grpc · Execution adapters that let backend domain logic run in-process or across process boundaries. · `packages/backend/src/adapters`
- [MOS ingress](https://github.com/leoyuku/rcas/tree/main/packages/backend/src/modules/1_mos_connection): socket protocol · Accepts MOS/NCS socket traffic and normalizes external newsroom updates. · `packages/backend/src/modules/1_mos_connection`
- [MOS parser](https://github.com/leoyuku/rcas/tree/main/packages/backend/src/modules/1_mos_connection/helper/mosModel): xml/message parsing · Parses MOS sockets, XML payloads, and profile-specific message behavior. · `packages/backend/src/modules/1_mos_connection/helper/mosModel`
- [Ingest translate](https://github.com/leoyuku/rcas/blob/main/packages/backend/src/modules/2_ingest/mos-to-rundown.ts): mos→rundown · Pure boundary that converts MOS running orders into the internal rundown model. · `packages/backend/src/modules/2_ingest/mos-to-rundown.ts`
- [Domain store](https://github.com/leoyuku/rcas/tree/main/packages/backend/src/modules/3_domain_engine/store): state/persistence · Holds rundown state, JSON persistence, socket serving, and MOS caching. · `packages/backend/src/modules/3_domain_engine/store`
- [Engine core](https://github.com/leoyuku/rcas/tree/main/packages/backend/src/modules/3_domain_engine/engine): lifecycle/state machine · Runs rundown lifecycle, state loop, PartInstance management, and crash recovery. · `packages/backend/src/modules/3_domain_engine/engine`
- [Timeline flow](https://github.com/leoyuku/rcas/blob/main/packages/backend/src/modules/3_domain_engine/engine/timeline-builder.ts): build/resolve/diff · Turns model state into timelines, resolves desired device state, and diffs against last sent state. · `packages/backend/src/modules/3_domain_engine/engine/timeline-builder.ts`
- [Playout ctrl](https://github.com/leoyuku/rcas/blob/main/packages/backend/src/modules/4_playout_controllers/playout-controller.ts): device adaptation · Converts abstract playout intent into device-specific commands and execution strategy. · `packages/backend/src/modules/4_playout_controllers/playout-controller.ts`
- [Tricaster driver](https://github.com/leoyuku/rcas/tree/main/packages/backend/src/modules/4_playout_controllers/tricaster): ws device client · Concrete Blackmagic Tricaster integration using WebSocket commands and retry logic. · `packages/backend/src/modules/4_playout_controllers/tricaster`
- [Core lib](https://github.com/leoyuku/rcas/tree/main/packages/core-lib/src): shared contracts · Canonical models and socket/event contracts shared by backend and frontend. · `packages/core-lib/src`
- [Frontend app](https://github.com/leoyuku/rcas/tree/main/packages/frontend/src): react operator UI · Operator console for rundown and playout views using backend-shared contracts. · `packages/frontend/src`
- [UI state](https://github.com/leoyuku/rcas/blob/main/packages/frontend/src/store/useRCASStore.ts): zustand store · Client-side state management for rundown and playout interface behavior. · `packages/frontend/src/store/useRCASStore.ts`
- [UI panels](https://github.com/leoyuku/rcas/tree/main/packages/frontend/src/components): rundown/playout views · Major operator-facing components such as rundown rows, source cards, timing, and control panels. · `packages/frontend/src/components`

### Vendored reference

Sofie Core copy kept as architectural reference, not the main runtime.

- [Sofie Core](https://github.com/leoyuku/rcas/blob/main/.gcloudignore/reference/sofie-core): vendored reference · Large reference copy of Sofie Core used for architectural inspiration and comparison. · `.gcloudignore/reference/sofie-core`

### Support tools

Utility programs for protocol validation and MOS patching.

- [Quick MOS](https://github.com/leoyuku/rcas/tree/main/tools/quick-mos): validation utility · Sample conversion and diff tooling for MOS compatibility validation. · `tools/quick-mos`
- [MOS patch](https://github.com/leoyuku/rcas/tree/main/tools/quick-mos-patch): conversion utility · Patch-oriented MOS conversion helper for sample inputs and diffs. · `tools/quick-mos-patch`

## Connections

- Backend entry → Shared infra: uses · Backend startup relies on shared config, logging, and health checks.
- Backend entry → Service adapters: selects · Entrypoint chooses in-memory or gRPC-oriented execution style.
- Backend entry → MOS ingress: boots · Backend can start the MOS ingress boundary as part of runtime composition.
- MOS ingress → MOS parser: parses · Socket traffic is normalized through MOS message and XML parsing.
- MOS parser → Ingest translate: feeds · Parsed MOS data is translated into internal rundown structures.
- Ingest translate → Domain store: loads · Translated rundown data is stored and cached for the domain engine.
- Domain store → Engine core: serves · The engine consumes persisted and live rundown state from the store.
- Engine core → Timeline flow: builds · Lifecycle state is transformed into timelines and desired device state.
- Timeline flow → Playout ctrl: diffs to · Resolved state is diffed into device-facing control actions.
- Playout ctrl → Tricaster driver: implements · Tricaster is the concrete device driver behind the playout abstraction.
- Shared infra → Core lib: shares · Shared backend services rely on canonical domain and event contracts.
- Frontend app → Core lib: consumes · Frontend uses the shared models and socket/event contracts.
- Frontend app → UI state: manages · UI state is coordinated through the client store.
- Frontend app → UI panels: renders · Operator screens are composed from the main UI panels.
- UI panels → UI state: reads · Panels subscribe to the client store for rundown and playout state.
- Backend entry → Sofie Core: inspired by · Vendored Sofie Core provides reference architecture and patterns.
- MOS parser → Quick MOS: validated by · MOS sample tooling helps validate parser and translation compatibility.
- Ingest translate → MOS patch: validated by · Patch tooling exercises MOS-to-rundown conversion behavior.
- Playout ctrl → Sofie Core: inspired by · Playout controller design is informed by the reference Sofie Core tree.
