# dn0903/marginalia-the-hero-s-journey architecture

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

- Interactive diagram: https://gitdiagram.com/dn0903/marginalia-the-hero-s-journey
- Repository: https://github.com/dn0903/marginalia-the-hero-s-journey

## Overview

1. **Project type and runtime**
   - This is a Unity 2D combat-simulation project (“Hero’s Library”), not a general web app.
   - The runtime is built around Unity scenes, ScriptableObject content, and a deterministic combat loop.
   - Notable supporting tech: Unity Input System, URP 2D, DOTween, TextMesh Pro.

2. **Core product idea**
   - The system is designed to **predict combat outcomes before committing them**.
   - The same effect compiler is used for both preview/prediction and runtime execution, so parity can be checked instead of assumed.
   - The main architectural promise is determinism: same inputs, same seed/state versions, same result.

3. **Primary control plane**
   - `CombatManager`, `BattleReferee`, and `TimeLineEngine` form the core combat orchestration layer.
   - `CombatManager` owns battle state and turn flow.
   - `BattleReferee` and battle-condition systems decide when a battle can continue or end.
   - `EventManager` is the main broadcast mechanism for authoritative state changes.

4. **Oracle subsystem: predict-then-execute**
   - The Oracle subsystem is the most distinctive part of the repo.
   - `BattleOracle` bridges prediction and execution, using:
     - `OracleSimulationEngine` for deterministic simulation,
     - `ActionPackageBuilder` / `ActionPackage` for compiled action payloads,
     - `EffectsPipeline` for effect resolution,
     - `SimulationWriteGuard` to prevent prediction-side mutation.
   - This is the central boundary between “forecasting” and “committing” gameplay.

5. **Parity, caching, and drift detection**
   - `OracleRealityVault` stores stamped predictions keyed by actor/skill/target plus versioned state.
   - `OracleParityProbe` and `DriftReportBuffer` enforce runtime equality between predicted and executed results.
   - `CriticalParityException` is the hard-stop boundary for invalid divergence.
   - The `.dbg` files and oracle test harnesses indicate active work on parity failures and drift reproduction.

6. **State authority and versioning**
   - `StateAuthority` is the authoritative commit layer for gameplay state.
   - It maintains commit buffers, sinks, and events, and advances versions only from committed gameplay changes.
   - `ResourceSnapshot` and `ResourceTransactionScope` support transaction-like state handling.
   - This state/version model is part of the determinism anchor used by the Oracle seed logic.

7. **Rules as a policy engine**
   - The rules system is a separate policy layer rather than scattered `if` statements.
   - `RuleRegistry`, `RuleMask256`, `RuleBit`, `ObjectTag`, and generated `BakedRuleMap` provide fast rule checks.
   - Individual rules like `Rule_MatchRole`, `Rule_OwnerALive`, and `Rule_BattleOngoing` are the concrete gates used by combat logic.
   - Editor tooling (`RuleBakeProcessor`) suggests rules are compiled/baked into lookup structures.

8. **Content/effect model**
   - Combat behavior is data-driven through ScriptableObjects under `Assets/Resources/CombatData`.
   - The main content categories are:
     - skills,
     - effects,
     - status effects,
     - passives,
     - unit stats.
   - Runtime effect types are implemented in `Assets/Scripts/Data/Effects`, while authored assets live in `Resources` so they can be loaded by the simulation and Oracle.

9. **Status effects and capability masking**
   - Status effects are treated as a subsystem, not just a visual debuff layer.
   - `StatusInjector`, `EffectChannel`, `EffectSlot`, and `StatusEffectParams` manage how effects are applied and updated.
   - There is also a capabilities layer (`UnitCapabilities`, `UnitCapabilityRegistry`) that appears to gate what units can do when effects are active.
   - This is where policy, stats, and runtime simulation intersect.

10. **Timeline and turn forecasting**
   - The timeline subsystem (`TurnData`, `VirtualEntityData`, `TurnPredictor`, `RoundBarrier`) handles turn order and future turn projection.
   - `TimeLineEngine` likely uses these data structures to maintain deterministic sequencing.
   - This subsystem feeds both gameplay UI and Oracle preview logic.

11. **Entity boundaries**
   - Units are split into player, enemy, and shared combat-unit abstractions.
   - Shared unit concerns live under `Entities/CombatUnit`:
     - stats,
     - combat behavior,
     - passives,
     - timeline,
     - visuals.
   - Enemy-specific logic includes `EnemyBrain`, `EnemySkillConfig`, and `UnitBreak`, while `PlayerUnit` is separate.
   - This suggests a deliberate boundary between generic combat identity and side-specific AI/control.

12. **UI and feedback layer**
   - UI is lightweight and driven by combat state rather than owning gameplay logic.
   - `CombatUI`, `HPBarUI`, `MPBarUI`, `TurnBarUI`, and damage popup prefabs provide feedback from authoritative state changes.
   - Visual effects are supported by prefabs and DOTween, but the UI is downstream of combat authority.

13. **Editor and build-time support**
   - The repo includes editor scripts for inspection and generation:
     - `CombatObjectEditor`,
     - `PassiveEffectEditor`,
     - `StatModifierStatusEffectEditor`,
     - `OracleSystemActivation`,
     - `MarginaliaCleanSweep`,
     - `RuleBakeProcessor`.
   - This indicates the architecture depends on tooling to keep data, rules, and generated artifacts consistent.

14. **Testing, audits, and documentation as architecture artifacts**
   - There is extensive documentation for Oracle parity, rules, state versioning, skill architecture, and sequential effect execution.
   - Tests such as `OracleDeterminismTester` and `OracleParityTestHarness` target the determinism contract directly.
   - The `.kiro`, `.dbg`, and report files show that architecture decisions are tracked as first-class project assets, not just code.

15. **Main data flow to diagram**
   - Player input or AI intent enters via managers/controllers.
   - Combat actions are packaged and sent through the Oracle pipeline.
   - The Oracle simulates effects against versioned state, validates parity, and emits a commitable result.
   - `StateAuthority` commits the result, `EventManager` broadcasts it, timeline/state subsystems update, and UI/visuals react.
   - Rules and capabilities gate whether contributions are allowed at each step.

16. **Useful diagram boundaries**
   - Treat these as the major boxes:
     - **Authoring/content**: ScriptableObjects, Resources, editor bake tools.
     - **Combat orchestration**: CombatManager, BattleReferee, timeline, conditions.
     - **Oracle prediction**: BattleOracle, simulation engine, write guard, parity vault.
     - **State authority**: StateAuthority, snapshots, transactions, versioning.
     - **Policy/rules**: RuleRegistry and baked rule maps.
     - **Unit/effect systems**: units, effects, status effects, passives, capabilities.
     - **Presentation**: UI, popups, DOTween-driven feedback.

Main entry points: [`Assets/Scripts/Systems/Oracle/CoreOracle/BattleOracle.cs`](https://github.com/dn0903/marginalia-the-hero-s-journey/blob/main/Assets/Scripts/Systems/Oracle/CoreOracle/BattleOracle.cs) (Battle oracle), [`Assets/Scripts/Systems/State/StateAuthority.cs`](https://github.com/dn0903/marginalia-the-hero-s-journey/blob/main/Assets/Scripts/Systems/State/StateAuthority.cs) (State authority), [`Assets/Scripts/Systems/Rules/RuleRegistry.cs`](https://github.com/dn0903/marginalia-the-hero-s-journey/blob/main/Assets/Scripts/Systems/Rules/RuleRegistry.cs) (Rule registry), [`Assets/Scripts/Core/CombatManager.cs`](https://github.com/dn0903/marginalia-the-hero-s-journey/blob/main/Assets/Scripts/Core/CombatManager.cs) (Combat manager)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_authoring["Authoring & content"]
  node_node_content["Combat data<br/>ScriptableObject assets"]
  node_node_editor_tools["Editor tools<br/>bake/inspect"]
  node_node_rules_assets["Rule assets<br/>rule content"]
end

subgraph group_group_orchestration["Combat orchestration"]
  node_node_combat_manager["Combat manager<br/>battle controller<br/>[CombatManager.cs]"]
  node_node_battle_referee["Battle referee<br/>battle arbiter<br/>[BattleReferee.cs]"]
  node_node_timeline_engine["Timeline engine<br/>turn sequencer<br/>[TimeLineEngine.cs]"]
  node_node_event_manager["Event manager<br/>state broadcaster<br/>[EventManager.cs]"]
end

subgraph group_group_oracle["Oracle prediction"]
  node_node_battle_oracle["Battle oracle<br/>predict/execute bridge<br/>[BattleOracle.cs]"]
  node_node_oracle_sim["Sim engine<br/>deterministic sim"]
  node_node_action_builder["Action package<br/>payload compiler"]
  node_node_effects_pipeline["Effects pipeline<br/>resolution pipeline<br/>[EffectsPipeline.cs]"]
  node_node_write_guard["Write guard<br/>mutation guard"]
  node_node_parity_vault[("Reality vault<br/>prediction cache")]
  node_node_parity_probe["Parity probe<br/>drift checker"]
end

subgraph group_group_state["State authority"]
  node_node_state_authority["State authority<br/>commit layer<br/>[StateAuthority.cs]"]
  node_node_snapshot_tx["Snapshot tx<br/>resource transaction"]
end

subgraph group_group_policy["Rules & policy"]
  node_node_rule_registry["Rule registry<br/>policy engine<br/>[RuleRegistry.cs]"]
  node_node_rule_map["Baked map<br/>generated lookup<br/>[BakedRuleMap.cs]"]
end

subgraph group_group_units["Units & effects"]
  node_node_combat_unit["Combat unit<br/>shared entity<br/>[CombatUnit.cs]"]
  node_node_enemy_unit["Enemy unit<br/>enemy control<br/>[EnemyUnit.cs]"]
  node_node_player_unit["Player unit<br/>player control<br/>[PlayerUnit.cs]"]
  node_node_effect_system["Effect system<br/>runtime effects"]
  node_node_status_channel["Status channel<br/>status masking"]
  node_node_capabilities["Capabilities<br/>ability policy"]
end

subgraph group_group_presentation["Presentation"]
  node_node_combat_ui["Combat UI<br/>feedback layer<br/>[CombatUI.cs]"]
  node_node_damage_popup["Damage popup<br/>visual feedback<br/>[DamagePopup.prefab]"]
end

node_node_content -->|"baked by"| node_node_editor_tools
node_node_rules_assets -->|"loaded by"| node_node_rule_registry
node_node_editor_tools -->|"generates"| node_node_rule_map
node_node_combat_manager -->|"consults"| node_node_battle_referee
node_node_combat_manager -->|"drives"| node_node_timeline_engine
node_node_combat_manager -->|"submits actions"| node_node_battle_oracle
node_node_battle_oracle -->|"compiles"| node_node_action_builder
node_node_action_builder -->|"feeds"| node_node_effects_pipeline
node_node_battle_oracle -->|"simulates"| node_node_oracle_sim
node_node_oracle_sim -->|"protected by"| node_node_write_guard
node_node_battle_oracle -->|"caches"| node_node_parity_vault
node_node_battle_oracle -->|"verifies"| node_node_parity_probe
node_node_parity_probe -->|"compares against"| node_node_state_authority
node_node_state_authority -->|"uses"| node_node_snapshot_tx
node_node_state_authority -->|"publishes"| node_node_event_manager
node_node_rule_registry -->|"gates commits"| node_node_state_authority
node_node_rule_registry -->|"constrains"| node_node_capabilities
node_node_combat_unit -->|"applies"| node_node_effect_system
node_node_enemy_unit -->|"bounded by"| node_node_rule_registry
node_node_player_unit -->|"inputs to"| node_node_combat_manager
node_node_status_channel -->|"masks"| node_node_capabilities
node_node_status_channel -->|"routes"| node_node_effect_system
node_node_combat_ui -->|"subscribes to"| node_node_event_manager
node_node_damage_popup -->|"reacts to"| node_node_event_manager
node_node_timeline_engine -->|"checks"| node_node_rule_registry
node_node_effects_pipeline -->|"commits via"| node_node_state_authority

click node_node_content "https://github.com/dn0903/marginalia-the-hero-s-journey/tree/main/Assets/Resources/CombatData"
click node_node_editor_tools "https://github.com/dn0903/marginalia-the-hero-s-journey/tree/main/Assets/Editor"
click node_node_rules_assets "https://github.com/dn0903/marginalia-the-hero-s-journey/tree/main/Assets/Resources/Rules"
click node_node_combat_manager "https://github.com/dn0903/marginalia-the-hero-s-journey/blob/main/Assets/Scripts/Core/CombatManager.cs"
click node_node_battle_referee "https://github.com/dn0903/marginalia-the-hero-s-journey/blob/main/Assets/Scripts/Core/BattleReferee.cs"
click node_node_timeline_engine "https://github.com/dn0903/marginalia-the-hero-s-journey/blob/main/Assets/Scripts/Core/TimeLineEngine.cs"
click node_node_event_manager "https://github.com/dn0903/marginalia-the-hero-s-journey/blob/main/Assets/Scripts/Manager/EventManager.cs"
click node_node_battle_oracle "https://github.com/dn0903/marginalia-the-hero-s-journey/blob/main/Assets/Scripts/Systems/Oracle/CoreOracle/BattleOracle.cs"
click node_node_oracle_sim "https://github.com/dn0903/marginalia-the-hero-s-journey/blob/main/Assets/Scripts/Systems/Oracle/CoreOracle/OracleSimulationEngine.cs"
click node_node_action_builder "https://github.com/dn0903/marginalia-the-hero-s-journey/blob/main/Assets/Scripts/Systems/Oracle/Pipeline/ActionPackageBuilder.cs"
click node_node_effects_pipeline "https://github.com/dn0903/marginalia-the-hero-s-journey/blob/main/Assets/Scripts/Systems/Oracle/Pipeline/EffectsPipeline.cs"
click node_node_write_guard "https://github.com/dn0903/marginalia-the-hero-s-journey/blob/main/Assets/Scripts/Systems/Oracle/CoreOracle/SimulationWriteGuard.cs"
click node_node_parity_vault "https://github.com/dn0903/marginalia-the-hero-s-journey/blob/main/Assets/Scripts/Systems/Oracle/Infrastructure/OracleRealityVault.cs"
click node_node_parity_probe "https://github.com/dn0903/marginalia-the-hero-s-journey/blob/main/Assets/Scripts/Systems/Oracle/Infrastructure/OracleParityProbe.cs"
click node_node_state_authority "https://github.com/dn0903/marginalia-the-hero-s-journey/blob/main/Assets/Scripts/Systems/State/StateAuthority.cs"
click node_node_snapshot_tx "https://github.com/dn0903/marginalia-the-hero-s-journey/blob/main/Assets/Scripts/Systems/State/ResourceSnapshot.cs"
click node_node_rule_registry "https://github.com/dn0903/marginalia-the-hero-s-journey/blob/main/Assets/Scripts/Systems/Rules/RuleRegistry.cs"
click node_node_rule_map "https://github.com/dn0903/marginalia-the-hero-s-journey/blob/main/Assets/Scripts/Systems/Rules/Generated/BakedRuleMap.cs"
click node_node_combat_unit "https://github.com/dn0903/marginalia-the-hero-s-journey/blob/main/Assets/Scripts/Entities/CombatUnit/CombatUnit.cs"
click node_node_enemy_unit "https://github.com/dn0903/marginalia-the-hero-s-journey/blob/main/Assets/Scripts/Entities/EnemyUnit/EnemyUnit.cs"
click node_node_player_unit "https://github.com/dn0903/marginalia-the-hero-s-journey/blob/main/Assets/Scripts/Entities/PlayerUnit.cs"
click node_node_effect_system "https://github.com/dn0903/marginalia-the-hero-s-journey/tree/main/Assets/Scripts/Data/Effects"
click node_node_status_channel "https://github.com/dn0903/marginalia-the-hero-s-journey/tree/main/Assets/Scripts/Systems/StatusEffects/EffectChannel"
click node_node_capabilities "https://github.com/dn0903/marginalia-the-hero-s-journey/blob/main/Assets/Scripts/Systems/Capabilities/UnitCapabilities.cs"
click node_node_combat_ui "https://github.com/dn0903/marginalia-the-hero-s-journey/blob/main/Assets/Scripts/UI/CombatUI.cs"
click node_node_damage_popup "https://github.com/dn0903/marginalia-the-hero-s-journey/blob/main/Assets/Prefabs/DamagePopup.prefab"

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_node_content,node_node_editor_tools,node_node_rules_assets,node_node_combat_ui,node_node_damage_popup toneBlue
class node_node_combat_manager,node_node_battle_referee,node_node_timeline_engine,node_node_event_manager toneAmber
class node_node_battle_oracle,node_node_oracle_sim,node_node_action_builder,node_node_effects_pipeline,node_node_write_guard,node_node_parity_vault,node_node_parity_probe toneMint
class node_node_state_authority,node_node_snapshot_tx toneRose
class node_node_rule_registry,node_node_rule_map toneIndigo
class node_node_combat_unit,node_node_enemy_unit,node_node_player_unit,node_node_effect_system,node_node_status_channel,node_node_capabilities toneTeal
```

## Components

### Authoring & content

ScriptableObject combat data, baked rules, and editor tooling that shape runtime behavior.

- [Combat data](https://github.com/dn0903/marginalia-the-hero-s-journey/tree/main/Assets/Resources/CombatData): ScriptableObject assets · Authored skills, effects, statuses, passives, unit stats, and win-condition assets under Resources. · `Assets/Resources/CombatData`
- [Editor tools](https://github.com/dn0903/marginalia-the-hero-s-journey/tree/main/Assets/Editor): bake/inspect · Editor scripts that validate, bake, and keep combat content and rules aligned. · `Assets/Editor`
- [Rule assets](https://github.com/dn0903/marginalia-the-hero-s-journey/tree/main/Assets/Resources/Rules): rule content · Authorable rule definitions used as policy inputs and baked into runtime lookups. · `Assets/Resources/Rules`

### Combat orchestration

Authoritative combat flow, turn control, battle conditions, and event broadcasting.

- [Combat manager](https://github.com/dn0903/marginalia-the-hero-s-journey/blob/main/Assets/Scripts/Core/CombatManager.cs): battle controller · Owns battle state, turn flow, and high-level combat coordination. · `Assets/Scripts/Core/CombatManager.cs`
- [Battle referee](https://github.com/dn0903/marginalia-the-hero-s-journey/blob/main/Assets/Scripts/Core/BattleReferee.cs): battle arbiter · Evaluates battle continuation and end conditions with the condition systems. · `Assets/Scripts/Core/BattleReferee.cs`
- [Timeline engine](https://github.com/dn0903/marginalia-the-hero-s-journey/blob/main/Assets/Scripts/Core/TimeLineEngine.cs): turn sequencer · Maintains deterministic turn ordering and forecasting across combat rounds. · `Assets/Scripts/Core/TimeLineEngine.cs`
- [Event manager](https://github.com/dn0903/marginalia-the-hero-s-journey/blob/main/Assets/Scripts/Manager/EventManager.cs): state broadcaster · Broadcasts authoritative combat state changes to downstream systems. · `Assets/Scripts/Manager/EventManager.cs`

### Oracle prediction

Deterministic simulation, action packaging, parity checking, and drift handling.

- [Battle oracle](https://github.com/dn0903/marginalia-the-hero-s-journey/blob/main/Assets/Scripts/Systems/Oracle/CoreOracle/BattleOracle.cs): predict/execute bridge · Coordinates prediction versus execution and connects simulation results back to runtime. · `Assets/Scripts/Systems/Oracle/CoreOracle/BattleOracle.cs`
- [Sim engine](https://github.com/dn0903/marginalia-the-hero-s-journey/blob/main/Assets/Scripts/Systems/Oracle/CoreOracle/OracleSimulationEngine.cs): deterministic sim · Runs the oracle simulation over versioned combat state. · `Assets/Scripts/Systems/Oracle/CoreOracle/OracleSimulationEngine.cs`
- [Action package](https://github.com/dn0903/marginalia-the-hero-s-journey/blob/main/Assets/Scripts/Systems/Oracle/Pipeline/ActionPackageBuilder.cs): payload compiler · Builds compiled action payloads that feed the same pipeline in preview and runtime. · `Assets/Scripts/Systems/Oracle/Pipeline/ActionPackageBuilder.cs`
- [Effects pipeline](https://github.com/dn0903/marginalia-the-hero-s-journey/blob/main/Assets/Scripts/Systems/Oracle/Pipeline/EffectsPipeline.cs): resolution pipeline · Resolves effect execution for both prediction and committed gameplay. · `Assets/Scripts/Systems/Oracle/Pipeline/EffectsPipeline.cs`
- [Write guard](https://github.com/dn0903/marginalia-the-hero-s-journey/blob/main/Assets/Scripts/Systems/Oracle/CoreOracle/SimulationWriteGuard.cs): mutation guard · Prevents prediction-side writes from mutating authoritative state. · `Assets/Scripts/Systems/Oracle/CoreOracle/SimulationWriteGuard.cs`
- [Reality vault](https://github.com/dn0903/marginalia-the-hero-s-journey/blob/main/Assets/Scripts/Systems/Oracle/Infrastructure/OracleRealityVault.cs): prediction cache · Stores stamped predictions keyed by actors, skills, targets, and state versions. · `Assets/Scripts/Systems/Oracle/Infrastructure/OracleRealityVault.cs`
- [Parity probe](https://github.com/dn0903/marginalia-the-hero-s-journey/blob/main/Assets/Scripts/Systems/Oracle/Infrastructure/OracleParityProbe.cs): drift checker · Compares predicted and executed outcomes and reports divergence. · `Assets/Scripts/Systems/Oracle/Infrastructure/OracleParityProbe.cs`

### State authority

Committed gameplay state, versioning, snapshots, and transactional resource handling.

- [State authority](https://github.com/dn0903/marginalia-the-hero-s-journey/blob/main/Assets/Scripts/Systems/State/StateAuthority.cs): commit layer · Authoritatively commits gameplay changes and advances state versions. · `Assets/Scripts/Systems/State/StateAuthority.cs`
- [Snapshot tx](https://github.com/dn0903/marginalia-the-hero-s-journey/blob/main/Assets/Scripts/Systems/State/ResourceSnapshot.cs): resource transaction · Supports snapshotting and transaction-like handling of battle resources. · `Assets/Scripts/Systems/State/ResourceSnapshot.cs`

### Rules & policy

Fast rule gates and generated lookup maps used by combat and effect systems.

- [Rule registry](https://github.com/dn0903/marginalia-the-hero-s-journey/blob/main/Assets/Scripts/Systems/Rules/RuleRegistry.cs): policy engine · Central rule evaluation layer for combat gates and fast checks. · `Assets/Scripts/Systems/Rules/RuleRegistry.cs`
- [Baked map](https://github.com/dn0903/marginalia-the-hero-s-journey/blob/main/Assets/Scripts/Systems/Rules/Generated/BakedRuleMap.cs): generated lookup · Generated rule mask lookup used for runtime-efficient policy checks. · `Assets/Scripts/Systems/Rules/Generated/BakedRuleMap.cs`

### Units & effects

Combat entities, skills, effects, status handling, passives, and capability masking.

- [Combat unit](https://github.com/dn0903/marginalia-the-hero-s-journey/blob/main/Assets/Scripts/Entities/CombatUnit/CombatUnit.cs): shared entity · Shared unit abstraction covering core combat identity and behavior. · `Assets/Scripts/Entities/CombatUnit/CombatUnit.cs`
- [Enemy unit](https://github.com/dn0903/marginalia-the-hero-s-journey/blob/main/Assets/Scripts/Entities/EnemyUnit/EnemyUnit.cs): enemy control · Enemy-specific brain, skill config, and break behavior. · `Assets/Scripts/Entities/EnemyUnit/EnemyUnit.cs`
- [Player unit](https://github.com/dn0903/marginalia-the-hero-s-journey/blob/main/Assets/Scripts/Entities/PlayerUnit.cs): player control · Player-facing combat entity boundary. · `Assets/Scripts/Entities/PlayerUnit.cs`
- [Effect system](https://github.com/dn0903/marginalia-the-hero-s-journey/tree/main/Assets/Scripts/Data/Effects): runtime effects · Implements damage, healing, break, stat buffs, status injection, and timeline shifts. · `Assets/Scripts/Data/Effects`
- [Status channel](https://github.com/dn0903/marginalia-the-hero-s-journey/tree/main/Assets/Scripts/Systems/StatusEffects/EffectChannel): status masking · Applies and updates status effects and capability masks across combat state. · `Assets/Scripts/Systems/StatusEffects/EffectChannel`
- [Capabilities](https://github.com/dn0903/marginalia-the-hero-s-journey/blob/main/Assets/Scripts/Systems/Capabilities/UnitCapabilities.cs): ability policy · Determines what units can do when status and battle policy change. · `Assets/Scripts/Systems/Capabilities/UnitCapabilities.cs`

### Presentation

UI, popups, and scene-facing feedback downstream of authoritative state.

- [Combat UI](https://github.com/dn0903/marginalia-the-hero-s-journey/blob/main/Assets/Scripts/UI/CombatUI.cs): feedback layer · Surfaces HP, MP, turn order, and combat state feedback to the player. · `Assets/Scripts/UI/CombatUI.cs`
- [Damage popup](https://github.com/dn0903/marginalia-the-hero-s-journey/blob/main/Assets/Prefabs/DamagePopup.prefab): visual feedback · Floating damage and combat popups driven by authoritative events. · `Assets/Prefabs/DamagePopup.prefab`

## Connections

- Combat data → Editor tools: baked by · Authoring content is validated and baked into runtime-friendly artifacts.
- Rule assets → Rule registry: loaded by · Rules assets feed the runtime registry and generated lookup layer.
- Editor tools → Baked map: generates · Editor tooling produces baked rule maps for fast runtime checks.
- Combat manager → Battle referee: consults · Combat flow is constrained by battle continuation and end-condition checks.
- Combat manager → Timeline engine: drives · The manager advances deterministic turn flow through the timeline engine.
- Combat manager → Battle oracle: submits actions · Intent is routed through oracle prediction before committing.
- Battle oracle → Action package: compiles · Oracle packages actor intent into action payloads.
- Action package → Effects pipeline: feeds · Compiled actions enter the shared effects resolution pipeline.
- Battle oracle → Sim engine: simulates · The oracle executes deterministic simulations over versioned state.
- Sim engine → Write guard: protected by · Simulation writes are blocked from mutating authoritative state.
- Battle oracle → Reality vault: caches · Predicted outcomes are stored for later comparison and reuse.
- Battle oracle → Parity probe: verifies · Predicted results are checked against committed runtime results.
- Parity probe → State authority: compares against · Parity checking is anchored to committed state transitions.
- State authority → Snapshot tx: uses · Commit authority relies on snapshots and transactional resource scopes.
- State authority → Event manager: publishes · Committed changes are broadcast to listeners and UI.
- Rule registry → State authority: gates commits · Policy checks decide whether gameplay changes may be applied.
- Rule registry → Capabilities: constrains · Rules and capabilities combine to gate unit actions.
- Combat unit → Effect system: applies · Shared units are modified through the runtime effect system.
- Enemy unit → Rule registry: bounded by · Enemy behavior is constrained by the same policy layer.
- Player unit → Combat manager: inputs to · Player intent enters combat orchestration through controllers.
- Status channel → Capabilities: masks · Status effects alter capability availability through masking.
- Status channel → Effect system: routes · Status application and updates are part of the effect boundary.
- Combat UI → Event manager: subscribes to · UI is updated from authoritative combat events.
- Damage popup → Event manager: reacts to · Visual feedback is spawned from combat state broadcasts.
- Timeline engine → Rule registry: checks · Timeline projection is constrained by battle policy.
- Effects pipeline → State authority: commits via · Resolved effect outcomes are committed through state authority.
