# wilsonsilva/raylib-tic-tac-toe architecture

> Architecture diagram of the GitHub repository wilsonsilva/raylib-tic-tac-toe, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/wilsonsilva/raylib-tic-tac-toe
- Repository: https://github.com/wilsonsilva/raylib-tic-tac-toe

## Overview

##### Project type and purpose
- This is a small, single-player tic-tac-toe game written in C, using the raylib graphics library.
- It targets two platforms: native desktop (Windows/Linux/Mac) and web via Emscripten (WASM + HTML shell).

##### File structure
- Top-level:
- CMakeLists.txt & Justfile – build orchestration (native and web)
- resources/textures – static assets (images, sprites)
- src/ – C source code and HTML shells for web
- src modules:
- main.c – application entry point, game loop
- animations.c/.h – animation routines
- reasings.h – easing functions for animations
- shell.html & minshell.html – HTML wrapper for the WASM build

##### Key insights from README
- Dependencies: raylib, CMake, optionally Just, Emscripten for web
- Build targets: build-debug, build-release (desktop), build-web (WASM + HTML)
- Runtime: loads textures at startup, runs a continuous game loop (input → update → render)

- Build System
– Justfile / CMake → native toolchain or Emscripten
- Platform Layer
– Native OS (GLFW/window management) OR Browser (HTML shell + JS glue + WASM)
- raylib Library
– Graphics, input, audio, timing
- Game Core
– main.c (game loop)
– Input Handler
– Game Logic (board state, win detection)
– Animation Module (animations.c + reasings.h)
- Resource Manager
– Texture loader (resources/textures)
- Output
– Native executable (.exe/.app) OR HTML + WASM module

b. Relationships and data flow
- Build System → compiles → Game Core + raylib → Produces native EXE or WASM
- At runtime: User input → Platform Layer → Game Core → Resource Manager/raylib → Render surface → Display to user
- Game Core calls Animation Module for smooth UI transitions
- Resource Manager loads textures at init and provides to raylib

c. Architectural patterns & design principles
- Modular separation:
– Clear division of concerns (input, logic, rendering, animations)
- Single game loop architecture (update → render cycle)
- Cross-platform abstraction via CMake/Emscripten

d. Technology & libraries
- raylib (C graphics/input)
- CMake + Just (build definitions)
- Emscripten (WASM + HTML shell)

## Diagram (Mermaid)

```mermaid
graph TD
    %% Build System
    subgraph "Build System"
        CMake["CMakeLists.txt"]:::build
        JustfileF["Justfile"]:::build
    end

    %% Toolchains
    subgraph "Toolchains"
        NativeTool["Native Toolchain"]:::build
        Emscripten["Emscripten"]:::build
    end

    %% Outputs
    subgraph "Build Outputs"
        NativeExe["Native Executable"]:::output
        WASMHTML["WASM + HTML Shell"]:::output
    end

    %% Platform Layer
    subgraph "Platform Layer"
        NativeOS["Native OS (GLFW/window)"]:::platform
        subgraph "Browser"
            Shell["shell.html"]:::platform
            Minishell["minshell.html"]:::platform
        end
    end

    %% Runtime Components
    subgraph "Runtime"
        raylibLib["raylib Library"]:::lib
        ResourceMgr["Resource Manager\n(textures)"]:::resource
        subgraph "Game Core"
            Main["main.c\n(Game Loop)"]:::core
            Input["Input Handler"]:::core
            Logic["Game Logic\n(board state)"]:::core
            subgraph "Animation Module"
                AnimC["animations.c"]:::core
                AnimH["animations.h"]:::core
                Easing["reasings.h"]:::core
            end
        end
    end

    %% Build pipelines
    CMake -->|"compile/native"| NativeTool
    JustfileF -->|"invoke CMake"| CMake
    NativeTool -->|"produces"| NativeExe
    JustfileF -->|"compile/web"| Emscripten
    Emscripten -->|"produces"| WASMHTML

    %% Runtime flows
    UserInput["User Input"]:::external --> NativeOS
    UserInput --> Shell
    NativeOS -->|passes input| Main
    Shell -->|JS glue + input| Main
    Main -->|calls| Input
    Main -->|calls| Logic
    Main -->|calls| AnimC
    Main -->|uses| ResourceMgr
    ResourceMgr -->|loads textures| raylibLib
    Main -->|renders via| raylibLib
    raylibLib -->|draw frame| Display["Display Surface"]:::external

    %% Click Events
    click CMake "https://github.com/wilsonsilva/raylib-tic-tac-toe/blob/main/CMakeLists.txt"
    click JustfileF "https://github.com/wilsonsilva/raylib-tic-tac-toe/tree/main/Justfile"
    click Main "https://github.com/wilsonsilva/raylib-tic-tac-toe/blob/main/src/main.c"
    click AnimC "https://github.com/wilsonsilva/raylib-tic-tac-toe/blob/main/src/animations.c"
    click AnimH "https://github.com/wilsonsilva/raylib-tic-tac-toe/blob/main/src/animations.h"
    click Easing "https://github.com/wilsonsilva/raylib-tic-tac-toe/blob/main/src/reasings.h"
    click ResourceMgr "https://github.com/wilsonsilva/raylib-tic-tac-toe/tree/main/resources/textures"
    click Shell "https://github.com/wilsonsilva/raylib-tic-tac-toe/blob/main/src/shell.html"
    click Minishell "https://github.com/wilsonsilva/raylib-tic-tac-toe/blob/main/src/minshell.html"

    %% Styles
    classDef build fill:#d3d3d3,stroke:#333,stroke-width:1px
    classDef core fill:#add8e6,stroke:#333,stroke-width:1px
    classDef lib fill:#90ee90,stroke:#333,stroke-width:1px
    classDef resource fill:#ffff99,stroke:#333,stroke-width:1px
    classDef platform fill:#ffcc99,stroke:#333,stroke-width:1px
    classDef output fill:#e6e6fa,stroke:#333,stroke-width:1px
    classDef external fill:#ffffff,stroke:#333,stroke-width:1px,stroke-dasharray: 5 5
```
