# artcfox/circuit architecture

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

## Overview

##### Main System Components

a) Core Game Engine
- Circuit simulation logic (circuit.c)
- Game state management
- Rule checker system

b) Resource Management System
- Audio assets (PCM files in /data)
- Visual assets (sprites, tilesets)
- Level data

c) Development Tools
- Oracle2 subsystem (for circuit validation)
- Ramfont system (for font rendering)

**┌─────────────────────────────────────────────┐**
- Game Runtime                 │
- ┬───────────────────────┤
- Core Engine      │   Resource Manager    │
- ┌─────────────┐    │   ┌─────────────┐    │
- Circuit Logic│    │   │Asset Loader │    │
- ┘    │   └─────────────┘    │
- ┌─────────────┐    │   ┌─────────────┐    │
- State Manager│    │   │Sound System │    │
- ┘    │   └─────────────┘    │
- ┴───────────────────────┤
- Hardware Abstraction Layer        │
- ┤
- Uzebox Hardware               │
- (AVR 8-bit microcontroller)         │
- ┘

##### Component Details

- Rectangles: Main components
- Rounded rectangles: Subsystems
- Hexagons: Hardware elements

##### Development Tools Integration

How the development tools interact:
**┌─────────────┐    ┌─────────────┐**
- Oracle2   │    │   Ramfont   │
- Validator  │    │  Generator  │
- ┘    └─────────────┘
- ↓                  ↓
**┌─────────────────────────────────────────┐**
- Build System                  │
- ┘

##### Asset Pipeline

**┌─────────────┐    ┌─────────────┐    ┌─────────────┐**
- Raw Assets │ → │  Converters │ → │ Game Assets  │
- (.xml,.wav)│    │(.inc files) │    │(Compressed) │
- ┘    └─────────────┘    └─────────────┘

##### Key Elements to Highlight

- Circuit simulation core (main gameplay mechanic)
- Level progression system (60 levels across 4 difficulty tiers)
- Input handling system (keyboard/controller support)
- Sound system (PCM audio playback)
- Sprite and tileset management
- Rule checking system

##### Documentation Integration

References to:
- Web emulator support (docs/cuzebox.js)
- Hardware specifications
- Development tools documentation

- Blue: Core game systems
- Green: Resource management
- Yellow: User interface elements
- Red: Critical hardware interfaces
- Purple: Development tools

Remember to maintain appropriate abstraction while showing the unique aspects of this retro console game, particularly the hardware constraints and optimization requirements.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph GameRuntime
        direction TB
        subgraph CoreEngine
            direction TB
            CircuitLogic["Circuit Simulation Core"]:::core
            StateManager["Game State Manager"]:::core
            RuleChecker["Rule Checker System"]:::core
        end

        subgraph ResourceManager
            direction TB
            AssetLoader["Asset Loader"]:::resource
            SoundSystem["Sound System"]:::resource
            
            subgraph Assets
                direction TB
                VisualAssets["Visual Assets"]:::asset
                AudioAssets["Audio Assets"]:::asset
                LevelData["Level Data"]:::asset
            end
        end
    end

    subgraph DevelopmentTools
        direction TB
        Oracle2["Oracle2 Validator"]:::tool
        Ramfont["Ramfont Generator"]:::tool
        BuildSystem["Build System"]:::tool
    end

    subgraph HardwareLayer
        direction TB
        HAL["Hardware Abstraction Layer"]:::hardware
        UzeboxHW["Uzebox Hardware (AVR 8-bit)"]:::hardware
        WebEmulator["Web Emulator Interface"]:::hardware
    end

    subgraph AssetPipeline
        direction TB
        RawAssets["Raw Assets (.xml, .wav)"]:::asset
        Converters["Asset Converters"]:::tool
        GameAssets["Compressed Game Assets"]:::asset
    end

    %% Relationships
    CircuitLogic --> StateManager
    StateManager --> RuleChecker
    AssetLoader --> Assets
    SoundSystem --> AudioAssets
    Assets --> GameRuntime
    
    Oracle2 --> BuildSystem
    Ramfont --> BuildSystem
    BuildSystem --> GameRuntime
    
    GameRuntime --> HAL
    HAL --> UzeboxHW
    HAL --> WebEmulator
    
    RawAssets --> Converters
    Converters --> GameAssets
    GameAssets --> AssetLoader

    %% Styles
    classDef core fill:#2196F3,stroke:#1565C0,color:white
    classDef resource fill:#4CAF50,stroke:#2E7D32,color:white
    classDef asset fill:#FFC107,stroke:#FFA000,color:black
    classDef tool fill:#9C27B0,stroke:#7B1FA2,color:white
    classDef hardware fill:#F44336,stroke:#C62828,color:white

    %% Click Events
    click CircuitLogic "https://github.com/artcfox/circuit/blob/master/circuit.c"
    click Oracle2 "https://github.com/artcfox/circuit/blob/master/oracle2/main.c"
    click Ramfont "https://github.com/artcfox/circuit/blob/master/ramfont/main.c"
    click AudioAssets "https://github.com/artcfox/circuit/blob/master/data/sounds.inc"
    click VisualAssets "https://github.com/artcfox/circuit/blob/master/data/sprites.inc"
    click BuildSystem "https://github.com/artcfox/circuit/tree/master/default/Makefile"
    click WebEmulator "https://github.com/artcfox/circuit/blob/master/docs/cuzebox.js"
    click RawAssets "https://github.com/artcfox/circuit/blob/master/data/sprites.xml"
    click Oracle2 "https://github.com/artcfox/circuit/blob/master/oracle2/netlist.h"
```
