# willtobyte/carimbo architecture

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

- Interactive diagram: https://gitdiagram.com/willtobyte/carimbo
- Repository: https://github.com/willtobyte/carimbo

## Overview

##### Project type and purpose
- Carimbo is a modern, cross-platform 2D game engine written in modern C++ using SDL and scriptable in Lua.
- It targets platforms: Linux, Windows, macOS, WebAssembly, Android, iOS.
- Key features: rendering, audio, input, resource loading, scene & state management, scripting, event handling.

##### File structure
- Top-level build/config files:
- CMakeLists.txt, Makefile, conanfile.py – build and dependency management
- .github/workflows/* – CI configurations for all platforms
- src/ directory – the entire engine code:
- application.* – entry point for user applications built on the engine
- engine.* and enginefactory.* – the core engine interfaces and factories
- window.*, audiodevice.*, soundmanager.*, soundfx.* – platform & audio subsystems
- scene.*, scenemanager.*, object*, objectmanager*, particlesystem* – scene and object management
- eventmanager.*, timermanager.*, lifecycleobserver* – core loop, timing, and event system
- scriptengine.* – Lua binding and script integration
- filesystem.*, io.* – resource I/O and virtual filesystem
- resourcemanager.*, fontfactory.*, querybuilder* – resource loading, fonts, and data queries
- design patterns: factory (enginefactory, fontfactory), singleton, observer/delegate (lifecycleobserver), pooling (objectpool, pixmappool), reflection (reflection.hpp), defer (defer.hpp).

##### README for additional insights
- Confirms it is a full-stack game engine core, not an application/game itself.
- Mentions scripting, cross-platform via SDL & WebAssembly.

##### Diagramming the system architecture
a. Main components
1. Application Layer
– application.cpp/hpp: user-implemented game entry
– scripts (Lua) loaded via scriptengine
2. Engine Core
– Engine API (engine.hpp)
– EngineFactory: creates platform-specific engine instance
– Subsystems:
- Rendering (renderer, canvas, pixmap, tilemap)
- Audio (audiodevice, soundmanager, soundfx)
- Input & Window Management (window, cursor)
- Scene & Object Management (scene, scenemanager, object, objectmanager)
- Event & Timing (eventmanager, timermanager, lifecycleobserver)
- Resource Management (filesystem, resourcemanager, fontfactory)
- Scripting (scriptengine, Lua)
- Networking (socket) & Steam integration
3. Platform Layer
– SDL backend for windowing, input, audio
– WebAssembly port
– Native mobile/desktop implementations
4. External Services
– Lua interpreter
– SDL
– (Optional) Steam SDK

b. Relationships and interactions
- Application calls EngineFactory → Engine
- Engine initializes subsystems (rendering, audio, input, scripting)
- Main loop: Timemanager ticks → Eventmanager dispatches → SceneManager updates objects → ScriptEngine executes game logic → Renderer draws → AudioDevice plays sounds
- ResourceManager/Filesystem load assets on demand
- ScriptEngine uses ResourceManager for scripts and game assets
- Networking/socket & Steam modules plug into event loop
- Factories (font, engine) produce subsystem instances
- Observers subscribe to lifecycle events (init, update, shutdown)

c. Architectural patterns & principles
- Layered architecture: Application → Engine Core → Platform
- Modular subsystems with clear interfaces
- Factory pattern for engine and resource instantiation
- Observer/Event Dispatcher for decoupling event handling
- Singleton for global managers (optional usage)
- Object Pool for performance (pixmappool, objectpool)
- Reflection and script-binding for dynamic behaviors

d. Key technologies & libraries
- C++17 (modern C++)
- SDL (cross-platform multimedia)
- Lua (scripting language)
- CMake & Conan (build & package management)
- WebAssembly toolchain (emscripten)
- Steamworks SDK (optional)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Layers
    subgraph "Application Layer"
        direction TB
        Main["main.cpp"]:::app
        AppEntry["application.cpp/hpp"]:::app
    end

    subgraph "Engine Core"
        direction TB
        EngineFactory["EngineFactory"]:::core
        EngineAPI["Engine API"]:::core

        subgraph "Subsystems"
            direction TB

            subgraph "Rendering" 
                direction TB
                Renderer["Renderer"]:::subsys
                Canvas["Canvas"]:::subsys
                Pixmap["Pixmap"]:::subsys
                Tilemap["Tilemap"]:::subsys
                Color["Color"]:::subsys
                Geometry["Geometry Helpers"]:::subsys
            end

            subgraph "Audio"
                direction TB
                AudioDevice["AudioDevice"]:::subsys
                SoundManager["SoundManager"]:::subsys
                SoundFX["SoundFX"]:::subsys
                Envelope["Envelope"]:::subsys
            end

            subgraph "Input & Window"
                direction TB
                Window["Window"]:::subsys
                Cursor["Cursor"]:::subsys
            end

            subgraph "Scene & Object"
                direction TB
                SceneGraph["Scene Graph"]:::subsys
                SceneManager["SceneManager"]:::subsys
                GameObject["GameObject"]:::subsys
                ObjectManager["ObjectManager"]:::subsys
                ParticleSystem["ParticleSystem"]:::subsys
                Overlay["Overlay/UI"]:::subsys
            end

            subgraph "Event & Timing"
                direction TB
                EventMgr["EventManager"]:::subsys
                EventReceiver["EventReceiver"]:::subsys
                TimerMgr["TimerManager"]:::subsys
                LifecycleObs["LifecycleObserver"]:::subsys
                Loopable["Loopable"]:::subsys
            end

            subgraph "Resource Management"
                direction TB
                FileSystem["Virtual FileSystem"]:::subsys
                IO["I/O Utilities"]:::subsys
                ResourceMgr["ResourceManager"]:::subsys
                FontFactory["FontFactory"]:::subsys
                QueryBuilder["QueryBuilder"]:::subsys
                Localization["Localization/KV"]:::subsys
            end

            subgraph "Scripting"
                direction TB
                ScriptEngine["ScriptEngine"]:::subsys
                Reflection["Reflection"]:::subsys
            end

            subgraph "Networking & External"
                direction TB
                Socket["Socket"]:::subsys
                Steam["Steam Integration"]:::subsys
                Postal["PostalService"]:::subsys
            end

        end
    end

    subgraph "Platform Layer"
        direction TB
        SDL["SDL Backend"]:::platform
        WebASM["WebAssembly Port"]:::platform
        Native["Native Mobile/Desktop"]:::platform
    end

    subgraph "External Services"
        direction TB
        LuaVM["Lua VM"]:::ext
        SteamSDK["Steam SDK (optional)"]:::ext
    end

    %% Connections
    Main -->|calls| AppEntry
    AppEntry -->|uses| EngineFactory
    EngineFactory -->|creates| EngineAPI
    EngineAPI -->|initializes| Renderer
    EngineAPI -->|initializes| AudioDevice
    EngineAPI -->|initializes| Window
    EngineAPI -->|initializes| SceneManager
    EngineAPI -->|initializes| EventMgr
    EngineAPI -->|initializes| ResourceMgr
    EngineAPI -->|initializes| ScriptEngine
    EngineAPI -->|initializes| Socket

    TimerMgr -->|"tick"| EventMgr
    EventMgr -->|"dispatch"| SceneManager
    SceneManager -->|"update objects"| ScriptEngine
    ScriptEngine -->|"exec scripts"| LuaVM
    ScriptEngine -->|"load assets"| ResourceMgr
    ScriptEngine -->|"reflection"| Reflection
    SceneManager -->|"render data"| Renderer
    SceneManager -->|"audio cues"| SoundManager
    Renderer -->|"draw calls"| SDL
    AudioDevice -->|"play audio"| SDL
    Window -->|"window/input"| SDL

    ResourceMgr -->|"read files"| FileSystem
    FileSystem -->|"I/O ops"| IO

    Socket -->|"network events"| EventMgr
    Steam -->|"steam events"| EventMgr

    EngineAPI -->|"factory pattern"| FontFactory
    LifecycleObs -->|"observe"| EngineAPI

    %% Engine to Platform
    Renderer --> SDL
    AudioDevice --> SDL
    Window --> SDL

    %% Click Events
    click Main "https://github.com/willtobyte/carimbo/blob/main/src/main.cpp"
    click AppEntry "https://github.com/willtobyte/carimbo/blob/main/src/application.cpp"
    click EngineFactory "https://github.com/willtobyte/carimbo/blob/main/src/enginefactory.hpp"
    click EngineAPI "https://github.com/willtobyte/carimbo/blob/main/src/engine.hpp"
    click Renderer "https://github.com/willtobyte/carimbo/blob/main/src/renderer.hpp"
    click Canvas "https://github.com/willtobyte/carimbo/blob/main/src/canvas.hpp"
    click Pixmap "https://github.com/willtobyte/carimbo/blob/main/src/pixmap.hpp"
    click Tilemap "https://github.com/willtobyte/carimbo/blob/main/src/tilemap.hpp"
    click Color "https://github.com/willtobyte/carimbo/blob/main/src/color.hpp"
    click Geometry "https://github.com/willtobyte/carimbo/blob/main/src/vector2d.hpp"
    click AudioDevice "https://github.com/willtobyte/carimbo/blob/main/src/audiodevice.hpp"
    click SoundManager "https://github.com/willtobyte/carimbo/blob/main/src/soundmanager.hpp"
    click SoundFX "https://github.com/willtobyte/carimbo/blob/main/src/soundfx.hpp"
    click Envelope "https://github.com/willtobyte/carimbo/blob/main/src/envelope.hpp"
    click Window "https://github.com/willtobyte/carimbo/blob/main/src/window.hpp"
    click Cursor "https://github.com/willtobyte/carimbo/blob/main/src/cursor.hpp"
    click SceneGraph "https://github.com/willtobyte/carimbo/blob/main/src/scene.hpp"
    click SceneManager "https://github.com/willtobyte/carimbo/blob/main/src/scenemanager.hpp"
    click GameObject "https://github.com/willtobyte/carimbo/blob/main/src/object.hpp"
    click ObjectManager "https://github.com/willtobyte/carimbo/blob/main/src/objectmanager.hpp"
    click ParticleSystem "https://github.com/willtobyte/carimbo/blob/main/src/particlesystem.hpp"
    click Overlay "https://github.com/willtobyte/carimbo/blob/main/src/overlay.hpp"
    click EventMgr "https://github.com/willtobyte/carimbo/blob/main/src/eventmanager.hpp"
    click EventReceiver "https://github.com/willtobyte/carimbo/blob/main/src/eventreceiver.hpp"
    click TimerMgr "https://github.com/willtobyte/carimbo/blob/main/src/timermanager.hpp"
    click LifecycleObs "https://github.com/willtobyte/carimbo/blob/main/src/lifecycleobserver.hpp"
    click Loopable "https://github.com/willtobyte/carimbo/blob/main/src/loopable.hpp"
    click FileSystem "https://github.com/willtobyte/carimbo/blob/main/src/filesystem.hpp"
    click IO "https://github.com/willtobyte/carimbo/blob/main/src/io.hpp"
    click ResourceMgr "https://github.com/willtobyte/carimbo/blob/main/src/resourcemanager.hpp"
    click FontFactory "https://github.com/willtobyte/carimbo/blob/main/src/fontfactory.hpp"
    click QueryBuilder "https://github.com/willtobyte/carimbo/blob/main/src/querybuilder.hpp"
    click Localization "https://github.com/willtobyte/carimbo/blob/main/src/locales.hpp"
    click ScriptEngine "https://github.com/willtobyte/carimbo/blob/main/src/scriptengine.hpp"
    click Reflection "https://github.com/willtobyte/carimbo/blob/main/src/reflection.hpp"
    click Socket "https://github.com/willtobyte/carimbo/blob/main/src/socket.hpp"
    click Steam "https://github.com/willtobyte/carimbo/blob/main/src/steam.hpp"
    click Postal "https://github.com/willtobyte/carimbo/blob/main/src/postalservice.hpp"

    %% Styles
    classDef app fill:#E3F2FD,stroke:#42A5F5,color:#0D47A1
    classDef core fill:#E8F5E9,stroke:#66BB6A,color:#1B5E20
    classDef subsys fill:#FFF3E0,stroke:#FFA726,color:#E65100
    classDef platform fill:#EDE7F6,stroke:#7E57C2,color:#4A148C
    classDef ext fill:#F3E5F5,stroke:#AB47BC,color:#6A1B9A
```
