# dragon-hatcher/type-system-chess architecture

> Architecture diagram of the GitHub repository dragon-hatcher/type-system-chess, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dragon-hatcher/type-system-chess
- Repository: https://github.com/dragon-hatcher/type-system-chess

## Overview

Key Components to Include:

##### Dual Implementation Structure
- Create two main parallel branches showing Rust and TypeScript implementations

##### Core Components (for each implementation)

Rust Implementation:
a. Board Representation (/rust/src/board_rep/)
- Board state management
- Piece representation
- Square/position handling

b. Move Generation (/rust/src/move_gen/)
- Piece-specific move generators
- Attack calculation
- Castling logic
- Check detection

c. Game State (/rust/src/state/)
- Game outcome handling
- State management

TypeScript Implementation:
- More condensed structure with core files:
- Handling (position.ts)
- Move generation (movegen.ts)
- Game state management (game-state.ts)
- FEN parsing (Fen.ts)

##### Interaction Flows
- How move generation depends on board representation
- State transitions
- Validation flows

##### Component Representation
- Use rectangles for modules
- Use hexagons for type system components
- Use diamonds for decision points

##### Additional Notes
- Recursion limits in Rust implementation
- Different complexity levels (5000 vs 900 lines)
- Parallel nature of implementations

Key Aspects to Emphasize:

##### Type System Integration
- How the chess logic is embedded in the type systems
- Where type-level computation occurs

##### Feature Implementation
- Chess rules implementation
- Move validation
- Special moves (castling, en passant, promotion)

Remember to include a note about the unique nature of this project as a type system implementation, distinguishing it from traditional chess engine architectures.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Legend
        L1[Module]
        L2[/Type System Component/]
        L3{Decision Point}
        L4[(Performance Critical)]
        style L1 fill:#f9f,stroke:#333
        style L2 fill:#bbf,stroke:#333
        style L3 fill:#ff9,stroke:#333
        style L4 fill:#f96,stroke:#333
    end

    subgraph Rust["Rust Implementation"]
        RBR["Board Representation"]:::rust
        click RBR "https://github.com/Dragon-Hatcher/type-system-chess/tree/main/rust/src/board_rep/"
        
        subgraph BoardComponents["Board Components"]
            BSM["Board State Management"]:::rust
            click BSM "https://github.com/Dragon-Hatcher/type-system-chess/tree/main/rust/src/board_rep/board/"
            PR["Piece Representation"]:::rust
            click PR "https://github.com/Dragon-Hatcher/type-system-chess/blob/main/rust/src/board_rep/piece.rs"
            SPH["Square/Position Handling"]:::rust
            click SPH "https://github.com/Dragon-Hatcher/type-system-chess/tree/main/rust/src/board_rep/square/"
            CM["Color Management"]:::rust
            click CM "https://github.com/Dragon-Hatcher/type-system-chess/blob/main/rust/src/board_rep/color.rs"
        end

        subgraph MoveGen["Move Generation"]
            MG["Move Generator"]:::rust
            click MG "https://github.com/Dragon-Hatcher/type-system-chess/tree/main/rust/src/move_gen/"
            
            subgraph PieceMoves["Piece-Specific Moves"]
                B["Bishop Moves"]:::rust
                click B "https://github.com/Dragon-Hatcher/type-system-chess/blob/main/rust/src/move_gen/bishop.rs"
                K["King Moves"]:::rust
                click K "https://github.com/Dragon-Hatcher/type-system-chess/blob/main/rust/src/move_gen/king.rs"
                N["Knight Moves"]:::rust
                click N "https://github.com/Dragon-Hatcher/type-system-chess/blob/main/rust/src/move_gen/knight.rs"
                P["Pawn Moves"]:::rust
                click P "https://github.com/Dragon-Hatcher/type-system-chess/blob/main/rust/src/move_gen/pawn.rs"
                Q["Queen Moves"]:::rust
                click Q "https://github.com/Dragon-Hatcher/type-system-chess/blob/main/rust/src/move_gen/queen.rs"
                R["Rook Moves"]:::rust
                click R "https://github.com/Dragon-Hatcher/type-system-chess/blob/main/rust/src/move_gen/rook.rs"
            end

            CL["Castling Logic"]:::rust
            click CL "https://github.com/Dragon-Hatcher/type-system-chess/blob/main/rust/src/move_gen/castle.rs"
            CD["Check Detection"]:::rust
            click CD "https://github.com/Dragon-Hatcher/type-system-chess/blob/main/rust/src/move_gen/check.rs"
            AC["Attack Calculation"]:::rust
            click AC "https://github.com/Dragon-Hatcher/type-system-chess/blob/main/rust/src/move_gen/attacked.rs"
        end

        GS["Game State"]:::rust
        click GS "https://github.com/Dragon-Hatcher/type-system-chess/tree/main/rust/src/state/"
        GO["Game Outcome"]:::rust
        click GO "https://github.com/Dragon-Hatcher/type-system-chess/blob/main/rust/src/state/outcome.rs"
        
        RUI["Rust UI"]:::rust
        click RUI "https://github.com/Dragon-Hatcher/type-system-chess/blob/main/rust/src/ui.rs"
        
        RT["Rust Tests"]:::rust
        click RT "https://github.com/Dragon-Hatcher/type-system-chess/tree/main/rust/src/test/"
    end

    subgraph TypeScript["TypeScript Implementation"]
        PH["Position Handler"]:::typescript
        click PH "https://github.com/Dragon-Hatcher/type-system-chess/blob/main/ts/src/position.ts"
        TMG["Move Generator"]:::typescript
        click TMG "https://github.com/Dragon-Hatcher/type-system-chess/blob/main/ts/src/movegen.ts"
        GSM["Game State Manager"]:::typescript
        click GSM "https://github.com/Dragon-Hatcher/type-system-chess/blob/main/ts/src/game-state.ts"
        FP["FEN Parser"]:::typescript
        click FP "https://github.com/Dragon-Hatcher/type-system-chess/blob/main/ts/src/Fen.ts"
        TUI["TypeScript UI"]:::typescript
        click TUI "https://github.com/Dragon-Hatcher/type-system-chess/blob/main/ts/src/ui.ts"
        TT["TypeScript Tests"]:::typescript
        click TT "https://github.com/Dragon-Hatcher/type-system-chess/tree/main/ts/src/test/"
    end

    %% Relationships
    RBR --> BSM
    RBR --> PR
    RBR --> SPH
    RBR --> CM
    
    MG --> B & K & N & P & Q & R
    MG --> CL
    MG --> CD
    MG --> AC
    
    GS --> GO
    
    %% TypeScript relationships
    PH --> TMG
    TMG --> GSM
    FP --> GSM
    
    %% Cross-implementation validation
    RBR -.-> PH
    MG -.-> TMG
    GS -.-> GSM

    classDef rust fill:#FFA07A,stroke:#333
    classDef typescript fill:#87CEEB,stroke:#333
    classDef performance fill:#FF6347,stroke:#333
    classDef critical fill:#FFD700,stroke:#333
```
