# zachbeta/2025_03_29_oneshot architecture

> Architecture diagram of the GitHub repository zachbeta/2025_03_29_oneshot, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/zachbeta/2025_03_29_oneshot
- Repository: https://github.com/zachbeta/2025_03_29_oneshot

## Overview

##### Project Type and Purpose
- SLOP_RUNNER is a terminal-based card game where the player acts as a “runner” hacking corporate systems.
- It focuses on turn-based gameplay, ASCII art rendering, resource management, and combat mechanics reminiscent of card games like Magic: The Gathering.

##### Analyzing the File Structure
- Top-level Files & Directories:
- Configuration and metadata files (e.g., package.json, tsconfig.json, jest.config.js, .gitignore).
- A saves directory containing JSON files, suggesting state persistence.
- The README, licensing, and documentation (intro.md, spec.md, todo.md) for overall project context.
- The src Directory is subdivided into:
- models: Contains core domain objects such as Card, GameState, LogEntry, UserAction, and associated tests. These represent the data model for the game.
- systems: Implements the game’s internal processing logic (ActionProcessor, CombatResolver, CorpAI, GameLoop, GameStateManager, InputHandler, PhaseManager, ProgramMechanics, SaveSystem, TurnManager, and ICEMechanics). These modules form the heart of the game engine.
- ui: Manages the rendering and user interaction components (CardRenderer, EventLogRenderer, GameBoardRenderer, HelpSystem, InteractiveGameBoard, TerminalUtils). This is the ASCII/terminal interface layer.
- utils: Provides additional helper functionality (e.g., CardFactory).
- types: Contains type definitions (e.g., terminal-kit typings), ensuring proper TypeScript support.
- A dedicated tests folder (and tests spread across directories) underlines a focus on modularity and testing.

a. Main Components to Identify:
- User Interface (UI Layer): Drawn from the ui directory handling rendering of cards, event logs, game boards, and helper systems.
- Game Engine / Core Systems: The systems directory, which includes the Game Loop, Turn Manager, Phase Manager, Input Handler, Action Processor, Combat Resolver, CorpAI, ICEMechanics, and Save System.
- Domain/Data Models: The models directory that defines Cards, GameState, LogEntry, and UserAction.
- Utility Functions: The utils (and smaller types definitions) that support the creation and management of cards, among others.
- Persistence: The saves directory represents the mechanism for state saving and retrieval.

b. Relationships/Interactions:
- The UI layer receives user input (keyboard events) and displays game states using ASCII art; it interacts primarily with the input components and rendering systems.
- The Input Handler (a system) collects and routes user actions to the Action Processor and Game State Manager.
- The Game Loop orchestrates the game phases (managed by Phase Manager and Turn Manager) and coordinates with Combat Resolver, CorpAI, and various Mechanics (ICEMechanics, ProgramMechanics) to process game logic.
- Domain models (Cards, GameState, etc.) are used across these systems to maintain state and facilitate gameplay.
- The Save System persists game state to the saves directory, enabling game session continuity.

c. Architectural Patterns/Design Principles:
- Separation of Concerns: Clear modular division between domain models, systems (logic), and UI.
- Component-Based Design: Systems encapsulate specific game functionalities (e.g., processing actions, resolving combat, handling game input).
- Test-Driven Development: Extensive tests are provided for nearly every module (as seen by *.test.ts files).

d. Relevant Technologies and Frameworks:
- Node.js and TypeScript provide the development platform.
- Terminal libraries (like terminal-kit, as indicated by type definitions) are used to manage CLI interactions.
- Testing is done using Jest, as seen in jest.config.js and the naming convention of test files.

##### Putting It All Together
- Present the central “Game Engine” containing the Game Loop, which orchestrates other systems like Turn Manager and Phase Manager.
- Domain models (Cards, GameState, LogEntry) to the Game Engine to show data structures that drive gameplay.
- Save System’s interaction with the Game Engine, highlighting persistence.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interface Layer
    subgraph "User Interface"
        UI["Terminal UI"]:::ui
    end

    %% Game Engine / Core Systems
    subgraph "Game Engine"
        IH["Input Handler"]:::engine
        AP["Action Processor"]:::engine
        GSM["Game State Manager"]:::engine
        GL["Game Loop"]:::engine
        TM["Turn Manager"]:::engine
        PM["Phase Manager"]:::engine
        CR["Combat Resolver"]:::engine
        CA["Corp AI"]:::engine
        ICE["ICEMechanics"]:::engine
        PMec["ProgramMechanics"]:::engine
        SS["Save System"]:::engine
    end

    %% Domain / Data Models
    subgraph "Domain Models"
        CM["Card"]:::models
        GSMd["GameState"]:::models
        LE["LogEntry"]:::models
        UA["User Action"]:::models
        TD["Type Definitions"]:::models
    end

    %% Persistence (Save Files)
    subgraph "Persistence"
        SF1["Save File 1"]:::persistence
        SF2["Save File 2"]:::persistence
        SF3["Save File 3"]:::persistence
    end

    %% Utility Functions
    subgraph "Utility Functions"
        CF["Card Factory"]:::utils
    end

    %% Connections
    UI -->|"input"| IH
    IH -->|"processAction"| AP
    IH -->|"updateState"| GSM
    AP -->|"triggerLoop"| GL
    GL -->|"manageTurn"| TM
    GL -->|"managePhase"| PM
    GL -->|"resolveCombat"| CR
    GL -->|"executeCorpAI"| CA
    GL -->|"applyICEMechanics"| ICE
    GL -->|"applyProgramMechanics"| PMec
    GL -->|"state_update"| GSMd
    GL -->|"render_update"| UI
    GL -->|"saveState"| SS
    SS --> SF1
    SS --> SF2
    SS --> SF3
    CF -->|"createCard"| CM

    %% Click Events
    click UI "https://github.com/zachbeta/2025_03_29_oneshot/tree/main/src/ui"
    click IH "https://github.com/zachbeta/2025_03_29_oneshot/blob/main/src/systems/InputHandler.ts"
    click AP "https://github.com/zachbeta/2025_03_29_oneshot/blob/main/src/systems/ActionProcessor.ts"
    click GSM "https://github.com/zachbeta/2025_03_29_oneshot/blob/main/src/systems/GameStateManager.ts"
    click GL "https://github.com/zachbeta/2025_03_29_oneshot/blob/main/src/systems/GameLoop.ts"
    click TM "https://github.com/zachbeta/2025_03_29_oneshot/blob/main/src/systems/TurnManager.ts"
    click PM "https://github.com/zachbeta/2025_03_29_oneshot/blob/main/src/systems/PhaseManager.ts"
    click CR "https://github.com/zachbeta/2025_03_29_oneshot/blob/main/src/systems/CombatResolver.ts"
    click CA "https://github.com/zachbeta/2025_03_29_oneshot/blob/main/src/systems/CorpAI.ts"
    click ICE "https://github.com/zachbeta/2025_03_29_oneshot/blob/main/src/systems/ICEMechanics.ts"
    click PMec "https://github.com/zachbeta/2025_03_29_oneshot/blob/main/src/systems/ProgramMechanics.ts"
    click SS "https://github.com/zachbeta/2025_03_29_oneshot/blob/main/src/systems/SaveSystem.ts"
    click CM "https://github.com/zachbeta/2025_03_29_oneshot/blob/main/src/models/Card.ts"
    click GSMd "https://github.com/zachbeta/2025_03_29_oneshot/blob/main/src/models/GameState.ts"
    click LE "https://github.com/zachbeta/2025_03_29_oneshot/blob/main/src/models/LogEntry.ts"
    click UA "https://github.com/zachbeta/2025_03_29_oneshot/blob/main/src/models/UserAction.ts"
    click TD "https://github.com/zachbeta/2025_03_29_oneshot/blob/main/src/models/types.ts"
    click CF "https://github.com/zachbeta/2025_03_29_oneshot/blob/main/src/utils/CardFactory.ts"
    click SF1 "https://github.com/zachbeta/2025_03_29_oneshot/blob/main/saves/save_2025-03-29T18-06-24-514Z.json"
    click SF2 "https://github.com/zachbeta/2025_03_29_oneshot/blob/main/saves/save_2025-03-29T18-09-53-572Z.json"
    click SF3 "https://github.com/zachbeta/2025_03_29_oneshot/blob/main/saves/save_2025-03-29T18-10-28-087Z.json"

    %% Styles
    classDef ui fill:#aqua,stroke:#333,stroke-width:2px;
    classDef engine fill:#cfc,stroke:#333,stroke-width:2px;
    classDef models fill:#fffae6,stroke:#333,stroke-width:2px;
    classDef utils fill:#f4f4f4,stroke:#333,stroke-width:2px;
    classDef persistence fill:#ffc0cb,stroke:#333,stroke-width:2px;
```
