# suppliedorange/obcb-contraptions architecture

> Architecture diagram of the GitHub repository suppliedorange/obcb-contraptions, 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/suppliedorange/obcb-contraptions
- Repository: https://github.com/suppliedorange/obcb-contraptions

## Overview

##### High-Level System Components

The system should be divided into these main components:

a) Core Infrastructure
- Checkbox Interface Layer
- WebSocket Communication System
- Image Processing Engine

b) Application Modules
- Static Image Renderer
- Animation Engine
- Game Engines (Pong, Tic-tac-toe)
- Retro Game Emulator
- Digital Clock

c) Utility Services
- Image Dithering Service
- Large-scale Rendering Service
- Python-based Data Processing

**[Frontend Layer]**

- WebSocket Client
- Checkbox Matrix Interface

**[Core Processing Layer]**

- Image Processing
- Dithering Engine
- Bitmap Converter

- Game Engines
- Pong Engine
- Tic-tac-toe Engine
- RetroBot Emulator
- Game Cores (MGBA, QuickNES, SNES9x)

- Animation System

**[Backend Services]**

- Python Data Processors
- Page Data Collator
- MongoDB Interface

- WebSocket Server

##### Key Relationships to Highlight

- Data flow between WebSocket client and server
- Image processing pipeline
- Game state management flow
- Emulator core interactions

##### Technical Details

Annotations for:
- WebSocket protocols used
- Image processing parameters (threshold values)
- Pixel calculation formulas
- Memory requirements for large-scale operations

##### Implementation Notes

- The modular nature of the applications
- The shared checkbox interface layer
- The separation between real-time games and static renders
- The scalability considerations for large renders

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Frontend
        WC[WebSocket Client]:::comm
        CM[Checkbox Matrix Interface]:::ui
        WC --> CM
    end

    subgraph Core
        IP[Image Processing]:::image
        DE[Dithering Engine]:::image
        BC[Bitmap Converter]:::image
        IP --> DE
        IP --> BC

        subgraph GameEngines
            PE[Pong Engine]:::game
            TT[Tic-tac-toe Engine]:::game
            RE[RetroBot Emulator]:::game
            GC[Game Cores]:::game
            RE --> GC
        end

        AS[Animation System]:::anim
        CD[Command Line Draw]:::anim
        AS --> CD
    end

    subgraph Backend
        WS[WebSocket Server]:::comm
        
        subgraph DataProcessing
            PDP[Python Data Processors]:::data
            PC[Page Collator]:::data
            MI[MongoDB Interface]:::data
            PDP --> PC
            PDP --> MI
        end
    end

    WC <--> WS
    WS --> IP
    WS --> GameEngines
    WS --> AS

    %% Click Events
    click WC "https://github.com/SuppliedOrange/obcb-contraptions/blob/main/client.ts"
    click IP "https://github.com/SuppliedOrange/obcb-contraptions/blob/main/bitmap.ts"
    click DE "https://github.com/SuppliedOrange/obcb-contraptions/blob/main/generate_dithered_image.ts"
    click BC "https://github.com/SuppliedOrange/obcb-contraptions/blob/main/bitmap.js"
    click PE "https://github.com/SuppliedOrange/obcb-contraptions/blob/main/ponggame/lib/pong.js"
    click TT "https://github.com/SuppliedOrange/obcb-contraptions/blob/main/run_tic_tac_toe_websocket.ts"
    click RE "https://github.com/SuppliedOrange/obcb-contraptions/tree/main/retrobot/src/"
    click GC "https://github.com/SuppliedOrange/obcb-contraptions/tree/main/retrobot/cores/"
    click AS "https://github.com/SuppliedOrange/obcb-contraptions/blob/main/ponggame/lib/animation.js"
    click CD "https://github.com/SuppliedOrange/obcb-contraptions/blob/main/ponggame/command-line-draw/lib/cmdDraw.js"
    click PDP "https://github.com/SuppliedOrange/obcb-contraptions/tree/main/py/"

    %% Styling
    classDef comm fill:#ff6b6b,stroke:#333,stroke-width:2px
    classDef ui fill:#4ecdc4,stroke:#333,stroke-width:2px
    classDef image fill:#ff9f43,stroke:#333,stroke-width:2px
    classDef game fill:#2ecc71,stroke:#333,stroke-width:2px
    classDef anim fill:#a8e6cf,stroke:#333,stroke-width:2px
    classDef data fill:#a55eea,stroke:#333,stroke-width:2px

    %% Legend
    subgraph Legend
        L1[Communication]:::comm
        L2[User Interface]:::ui
        L3[Image Processing]:::image
        L4[Game Systems]:::game
        L5[Animation]:::anim
        L6[Data Processing]:::data
    end
```
