# samualtnorman/binmat architecture

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

- Interactive diagram: https://gitdiagram.com/samualtnorman/binmat
- Repository: https://github.com/samualtnorman/binmat

## Overview

Main Components to Include:

##### Core Simulator Components
- Game State Manager (makeState.ts)
- Move Processor (doMove.ts)
- Combat System (doCombat.ts)

##### Move Processing Subsystem
- Combat Moves (doMoveCombat.ts)
- Discard Moves (doMoveDiscard.ts)
- Pass Moves (doMovePass.ts)
- Play Moves (doMovePlay.ts, doMovePlayFaceUp.ts)

##### Parser Components
- A "Parser System" section containing:
- Move Parser (parseMove.ts)
- Binlog Parser (parseBinlog.ts, parseBinlogMove.ts)

##### Utility Components
- A "Utilities" section for:
- Card Validation (isCard.ts, isCardStringFace.ts, isCardStringSuit.ts)
- Argument Generation (generateArgs.ts)
- Move String Conversion (moveToString.ts)

##### Game Scripts Integration
- Integration with hackmud game via:
- binmat.ts
- binmat_lib.ts

##### Use a layered approach
- Top Layer: External Interface (hackmud game integration)
- Middle Layer: Core Simulator Components
- Bottom Layer: Utility Functions and Parsers

##### Connection Types

Specific Implementation Details:

##### Test integration
- A "Testing Framework" component connecting to all major systems
- Example brain testing system

##### State Management
- How game state flows through the system
- Role of StatusCode.ts and Role.ts in the state management

##### Build System
- A small section showing the build pipeline:
- TypeScript compilation
- Script packaging
- hackmud integration

Key Relationships to Highlight:

##### How the brain testing system interfaces with the simulator

Level of Detail:

- Keep main components visible at a glance
- Use expandable/collapsible sections for move processors
- Annotations for critical paths and important interactions

Remember to:
- Version compatibility (Node.js 18, 20, and above)
- Test integration points
- Brain testing interface
- Build and deployment paths

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph External["External Integration Layer"]
        GameScripts["Game Scripts"]
        BinmatScript["binmat.ts"]:::script
        BinmatLib["binmat_lib.ts"]:::script
    end

    subgraph Core["Core Simulator Layer"]
        SimEngine["Simulator Engine"]:::core
        StateManager["Game State Manager"]:::core
        MoveProcessor["Move Processor"]:::core
        CombatSystem["Combat System"]:::core
    end

    subgraph Moves["Move Processing Layer"]
        direction TB
        CombatMoves["Combat Moves"]:::move
        DiscardMoves["Discard Moves"]:::move
        DrawMoves["Draw Moves"]:::move
        PassMoves["Pass Moves"]:::move
        PlayMoves["Play Moves"]:::move
    end

    subgraph Parser["Parser Layer"]
        MoveParser["Move Parser"]:::parser
        BinlogParser["Binlog Parser"]:::parser
        BinlogMoveParser["Binlog Move Parser"]:::parser
    end

    subgraph State["State Management"]
        Roles["Role Definitions"]:::state
        StatusCodes["Status Codes"]:::state
        MoveTags["Move Tags"]:::state
    end

    subgraph Utils["Utility Layer"]
        CardValidation["Card Validation"]:::util
        ArgGen["Argument Generation"]:::util
        MoveString["Move String Conversion"]:::util
    end

    subgraph Testing["Testing Framework"]
        BrainTest["Brain Testing System"]:::test
        GameTests["Game Simulator Tests"]:::test
        MoveTests["Move Processing Tests"]:::test
    end

    %% Relationships
    GameScripts --> SimEngine
    SimEngine --> StateManager
    SimEngine --> MoveProcessor
    SimEngine --> CombatSystem
    
    MoveProcessor --> CombatMoves
    MoveProcessor --> DiscardMoves
    MoveProcessor --> DrawMoves
    MoveProcessor --> PassMoves
    MoveProcessor --> PlayMoves
    
    Parser --> SimEngine
    MoveParser --> MoveProcessor
    BinlogParser --> BinlogMoveParser
    BinlogMoveParser --> SimEngine
    
    State --> SimEngine
    Utils --> SimEngine
    Utils --> MoveProcessor
    
    Testing --> SimEngine
    Testing --> MoveProcessor
    Testing --> Parser

    %% Click Events
    click StateManager "https://github.com/samualtnorman/binmat/blob/main/src/makeState.ts"
    click MoveProcessor "https://github.com/samualtnorman/binmat/blob/main/src/doMove.ts"
    click CombatSystem "https://github.com/samualtnorman/binmat/blob/main/src/doCombat.ts"
    click CombatMoves "https://github.com/samualtnorman/binmat/blob/main/src/doMoveCombat.ts"
    click DiscardMoves "https://github.com/samualtnorman/binmat/blob/main/src/doMoveDiscard.ts"
    click DrawMoves "https://github.com/samualtnorman/binmat/blob/main/src/doMoveDraw.ts"
    click PassMoves "https://github.com/samualtnorman/binmat/blob/main/src/doMovePass.ts"
    click PlayMoves "https://github.com/samualtnorman/binmat/blob/main/src/doMovePlay.ts"
    click MoveParser "https://github.com/samualtnorman/binmat/blob/main/src/parseMove.ts"
    click BinlogParser "https://github.com/samualtnorman/binmat/blob/main/src/parseBinlog.ts"
    click BinlogMoveParser "https://github.com/samualtnorman/binmat/blob/main/src/parseBinlogMove.ts"
    click CardValidation "https://github.com/samualtnorman/binmat/blob/main/src/isCard.ts"
    click ArgGen "https://github.com/samualtnorman/binmat/blob/main/src/generateArgs.ts"
    click MoveString "https://github.com/samualtnorman/binmat/blob/main/src/moveToString.ts"
    click BinmatScript "https://github.com/samualtnorman/binmat/blob/main/game-scripts/binmat.ts"
    click BinmatLib "https://github.com/samualtnorman/binmat/blob/main/game-scripts/binmat_lib.ts"
    click Roles "https://github.com/samualtnorman/binmat/blob/main/src/Role.ts"
    click StatusCodes "https://github.com/samualtnorman/binmat/blob/main/src/StatusCode.ts"
    click MoveTags "https://github.com/samualtnorman/binmat/blob/main/src/MoveTag.ts"
    click BrainTest "https://github.com/samualtnorman/binmat/tree/main/examples/test-binmat-brain"
    click GameTests "https://github.com/samualtnorman/binmat/blob/main/test/simulateGame.test.js"
    click MoveTests "https://github.com/samualtnorman/binmat/blob/main/test/doMove.test.js"

    %% Styling
    classDef core fill:#a8d1f0,stroke:#333
    classDef move fill:#90EE90,stroke:#333
    classDef parser fill:#FFE5B4,stroke:#333
    classDef util fill:#E6E6FA,stroke:#333
    classDef state fill:#FFA07A,stroke:#333
    classDef test fill:#F0E68C,stroke:#333
    classDef script fill:#98FB98,stroke:#333
```
