# notzun/coolplatformer architecture

> Architecture diagram of the GitHub repository notzun/coolplatformer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-06-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/notzun/coolplatformer
- Repository: https://github.com/notzun/coolplatformer

## Overview

1. **Overall shape**
   This is a small native **C++ / SDL2** game project, currently centered on a simple **2D platformer** with walking and jumping. The repository looks like a **single executable** rather than a multi-service or engine-based system.

2. **Runtime boundary**
   The only runtime dependency called out in the README is **SDL2**, so the architecture is likely:
   **OS window/input/audio/video stack → SDL2 → game loop → game state update → sprite rendering**.
   There is no sign of networking, persistence, or backend services.

3. **Entry and game loop**
   `basic.cpp` is likely the top-level program file: SDL initialization, window creation, event polling, the main loop, and shutdown. This file is probably where the application repeatedly:
   - reads keyboard input,
   - updates player/world state,
   - triggers drawing.

4. **Gameplay logic**
   `functions.cpp` likely contains most of the reusable game logic and helper routines: movement handling, jump physics, collision or bounds checks, and other utility functions used by the loop. For diagram purposes, treat this as the **simulation/update layer** between input and rendering.

5. **Rendering layer**
   `sprites.cpp` appears to own sprite-related work: loading image resources, selecting frames, and drawing them to the SDL renderer. This is the main **presentation boundary** in the project, separating visual assets from gameplay logic.

6. **Asset definitions**
   `assets.h` probably centralizes asset references and constants such as image paths, sprite dimensions, and maybe shared enums or identifiers. This file acts as a lightweight **asset catalog / shared constants** layer that other `.cpp` files include.

7. **Data flow**
   The likely flow is:
   **keyboard input from SDL → player state changes in update functions → current state passed to sprite rendering → SDL draws to the window**.
   In other words, input affects game state, and game state drives what gets drawn.

8. **Current gameplay scope**
   Based on the README, the implemented mechanics are minimal: **move left, move right, and jump**. That means the current architecture is probably centered on a single controllable character and a small amount of world geometry, not a full entity/component system.

9. **Build and developer tooling**
   `Makefile` is the primary build entrypoint for compiling the C++ sources into the game binary. `shell.nix` indicates a **Nix-based development environment**, likely used to pin SDL2 and compiler dependencies for reproducible local builds.

10. **Repository intent**
   The README says the author plans to grow this into a **danmaku/Touhou-style game**, so the current codebase is an early foundation. The architecture will likely expand from a simple platformer loop into more systems later, but right now it is a compact SDL2 game with clear separation between **app startup, gameplay logic, sprite rendering, and asset definitions**.

Main entry points: [`basic.cpp`](https://github.com/notzun/coolplatformer/blob/main/basic.cpp) (Main loop), [`sprites.cpp`](https://github.com/notzun/coolplatformer/blob/main/sprites.cpp) (Sprite render), [`functions.cpp`](https://github.com/notzun/coolplatformer/blob/main/functions.cpp) (Gameplay logic), [`shell.nix`](https://github.com/notzun/coolplatformer/blob/main/shell.nix) (Dev env)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_basic_cpp["Main loop<br/>C++ entrypoint<br/>[basic.cpp]"]
  node_sdl2{{"SDL2<br/>native library"}}
  node_os(("OS<br/>platform runtime"))
end

subgraph group_gameplay["Gameplay"]
  node_functions_cpp["Gameplay logic<br/>C++ update<br/>[functions.cpp]"]
end

subgraph group_presentation["Presentation"]
  node_sprites_cpp["Sprite render<br/>C++ rendering<br/>[sprites.cpp]"]
  node_assets_h["Assets<br/>shared constants<br/>[assets.h]"]
end

subgraph group_tooling["Tooling"]
  node_makefile["Build"]
  node_shell_nix["Dev env<br/>nix config<br/>[shell.nix]"]
end

node_os -->|"hosts"| node_sdl2
node_sdl2 -->|"drives"| node_basic_cpp
node_basic_cpp -->|"updates"| node_functions_cpp
node_basic_cpp -->|"renders via"| node_sprites_cpp
node_functions_cpp -->|"uses"| node_assets_h
node_sprites_cpp -->|"uses"| node_assets_h
node_basic_cpp -->|"initializes"| node_sdl2
node_sprites_cpp -->|"draws with"| node_sdl2
node_makefile -->|"builds"| node_basic_cpp
node_shell_nix -->|"supports"| node_makefile
node_shell_nix -->|"provides"| node_sdl2
node_basic_cpp -->|"calls"| node_functions_cpp
node_basic_cpp -->|"passes state to"| node_sprites_cpp

click node_basic_cpp "https://github.com/notzun/coolplatformer/blob/main/basic.cpp"
click node_functions_cpp "https://github.com/notzun/coolplatformer/blob/main/functions.cpp"
click node_sprites_cpp "https://github.com/notzun/coolplatformer/blob/main/sprites.cpp"
click node_assets_h "https://github.com/notzun/coolplatformer/blob/main/assets.h"
click node_makefile "https://github.com/notzun/coolplatformer/tree/main/Makefile"
click node_shell_nix "https://github.com/notzun/coolplatformer/blob/main/shell.nix"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_basic_cpp,node_sdl2,node_os toneBlue
class node_functions_cpp toneAmber
class node_sprites_cpp,node_assets_h toneMint
class node_makefile,node_shell_nix toneRose
```

## Components

### Runtime

Executable and SDL2 boundary

- [Main loop](https://github.com/notzun/coolplatformer/blob/main/basic.cpp): C++ entrypoint · Initializes SDL2, runs the event/update/render loop, and shuts down the game. · `basic.cpp`
- **SDL2**: native library · Provides windowing, input, and rendering services for the game.
- **OS**: platform runtime · Host system providing the process, window, and device environment.

### Gameplay

Input, simulation, and world state

- [Gameplay logic](https://github.com/notzun/coolplatformer/blob/main/functions.cpp): C++ update · Contains movement, jumping, and other reusable simulation helpers. · `functions.cpp`

### Presentation

Sprite loading and drawing

- [Sprite render](https://github.com/notzun/coolplatformer/blob/main/sprites.cpp): C++ rendering · Loads sprite assets, selects frames, and draws to the SDL renderer. · `sprites.cpp`
- [Assets](https://github.com/notzun/coolplatformer/blob/main/assets.h): shared constants · Defines asset references, sizes, and shared identifiers used across the game. · `assets.h`

### Tooling

Build and dev environment

- [Build](https://github.com/notzun/coolplatformer/tree/main/Makefile): build script · Compiles the C++ sources into the game executable. · `Makefile`
- [Dev env](https://github.com/notzun/coolplatformer/blob/main/shell.nix): nix config · Pins the development shell and native dependencies such as SDL2. · `shell.nix`

## Connections

- OS → SDL2: hosts · The operating system provides the runtime environment used by SDL2.
- SDL2 → Main loop: drives · SDL2 supplies the event loop, input, and rendering APIs used by the executable.
- Main loop → Gameplay logic: updates · The main loop invokes gameplay logic to change player and world state.
- Main loop → Sprite render: renders via · The main loop triggers drawing through the sprite rendering layer.
- Gameplay logic → Assets: uses · Gameplay code relies on shared asset and game constants.
- Sprite render → Assets: uses · Rendering code uses asset definitions and sprite metadata.
- Main loop → SDL2: initializes · The entrypoint sets up SDL2 windowing and rendering resources.
- Sprite render → SDL2: draws with · Sprite rendering issues draw calls through SDL2.
- Build → Main loop: builds · The Makefile compiles the executable from the C++ sources.
- Dev env → Build: supports · The Nix shell provides a reproducible environment for building.
- Dev env → SDL2: provides · The development shell likely supplies SDL2 and compiler dependencies.
- Main loop → Gameplay logic: calls · The executable depends on gameplay helpers for simulation.
- Main loop → Sprite render: passes state to · Current game state is handed to the renderer each frame.
