# miwate/invasion-c architecture

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

- Interactive diagram: https://gitdiagram.com/miwate/invasion-c
- Repository: https://github.com/miwate/invasion-c

## Overview

#### Purpose and entry points
INVASION is a native C/SDL2 game, apparently centered on defending against zombie waves with manually or automatically placed turrets. The build entry point is `Makefile`; `make` produces `build/jeu`, while level-oriented targets select content such as `levels/impossible.txt` or the automated `levels/demo.txt` scenario. Runtime execution begins in `src/main.c`.

#### Application orchestration
`src/main.c` is the top-level coordinator. The declared module split is exposed by `prot/jeu.h`, `prot/video.h`, and `prot/replay.h`: main should initialize subsystems, select/load a level, run the game loop, and arrange shutdown. `src/jeu.c` contains core gameplay state and rules; `src/io.c` and `src/video.c` provide its interaction boundaries.

#### Gameplay and level content
The gameplay domain is isolated in `src/jeu.c` with its public interface in `prot/jeu.h`. Level files are data-driven scenario inputs rather than compiled maps: `levels/facile.txt`, `levels/survie.txt`, and `levels/demo.txt` represent selectable difficulty/mode variants. Control flows from level selection into game-state initialization, then through repeated gameplay updates until completion or failure.

#### Input/output and persistence boundary
`src/io.c` is the terminal/file interaction layer described by the repository architecture. It mediates user-facing textual I/O and communicates with gameplay rather than making the game engine depend directly on terminal behavior. Persistent artifacts include `replay.txt` and score/leaderboard files under `lb/`, notably `lb/scores.txt` and `lb/bravo.txt`; replay-facing declarations live in `prot/replay.h`.

#### Rendering and media
`src/video.c`, defined by `prot/video.h`, owns graphical presentation. It loads assets from `tex/` and renders through SDL image/window facilities; the source art includes `tex/zombies.psd`, `tex/fond.psd`, and font `tex/pixelgame.otf`. Audio is a separate runtime asset dependency, currently `audio/invasion.mp3`, likely consumed through SDL_mixer.

#### Runtime and build infrastructure
The executable is compiled with GCC via `Makefile`; generated objects and binary are placed in `build/` (`build/main.o`, `build/jeu.o`, `build/jeu`). Required external native libraries are SDL2 plus SDL_image, SDL_mixer, and SDL_ttf. This is a desktop native application, not a service or web runtime.

#### Legacy boundary
`_old/main_old.c` and `_old/` scripts are historical/alternative implementation material. They should not be treated as part of the active architecture unless the Makefile explicitly references them; the active source set is `src/` plus `prot/`.

Main entry points: [`src/jeu.c`](https://github.com/miwate/invasion-c/blob/main/src/jeu.c) (Gameplay engine), [`src/main.c`](https://github.com/miwate/invasion-c/blob/main/src/main.c) (Main coordinator), [`src/video.c`](https://github.com/miwate/invasion-c/blob/main/src/video.c) (SDL renderer), [`build/jeu`](https://github.com/miwate/invasion-c/blob/main/build/jeu) (jeu)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_build["Build &amp; Runtime"]
  node_makefile["Makefile<br/>build entry"]
  node_gcc["GCC<br/>compiler"]
  node_sdl["SDL2 libraries<br/>native runtime"]
  node_game_binary["jeu<br/>native executable"]
end

subgraph group_app["Game Application"]
  node_main["Main coordinator<br/>application entry<br/>[main.c]"]
  node_gameplay_api["Gameplay API<br/>C header<br/>[jeu.h]"]
  node_gameplay["Gameplay engine<br/>game rules<br/>[jeu.c]"]
  node_io["Terminal &amp; file I/O<br/>interaction adapter<br/>[io.c]"]
  node_video_api["Video API<br/>C header<br/>[video.h]"]
  node_video["SDL renderer<br/>presentation<br/>[video.c]"]
  node_replay_api["Replay API<br/>C header<br/>[replay.h]"]
end

subgraph group_content["Game Content &amp; Persistence"]
  node_levels["Level scenarios<br/>scenario data<br/>[demo.txt]"]
  node_art["Textures &amp; font<br/>media assets<br/>[zombies.psd]"]
  node_audio["Game audio<br/>audio asset<br/>[invasion.mp3]"]
  node_replay["Replay record<br/>persistent data<br/>[replay.txt]"]
  node_leaderboard["Leaderboard files<br/>persistent data<br/>[scores.txt]"]
end

node_makefile -->|"invokes"| node_gcc
node_gcc -->|"builds"| node_game_binary
node_game_binary -->|"starts"| node_main
node_main -->|"uses"| node_gameplay_api
node_gameplay_api -->|"defines"| node_gameplay
node_main -->|"uses"| node_video_api
node_video_api -->|"defines"| node_video
node_main -->|"uses"| node_replay_api
node_main -->|"selects and loads"| node_levels
node_levels -->|"initializes scenario"| node_gameplay
node_gameplay -->|"exchanges text I/O"| node_io
node_gameplay -->|"provides state"| node_video
node_video -->|"loads"| node_art
node_video -->|"uses"| node_audio
node_gameplay -->|"records"| node_replay
node_replay_api -->|"declares access"| node_replay
node_gameplay -->|"updates scores"| node_leaderboard
node_game_binary -->|"links against"| node_sdl

click node_makefile "https://github.com/miwate/invasion-c/blob/main/Makefile"
click node_game_binary "https://github.com/miwate/invasion-c/blob/main/build/jeu"
click node_main "https://github.com/miwate/invasion-c/blob/main/src/main.c"
click node_gameplay_api "https://github.com/miwate/invasion-c/blob/main/prot/jeu.h"
click node_gameplay "https://github.com/miwate/invasion-c/blob/main/src/jeu.c"
click node_io "https://github.com/miwate/invasion-c/blob/main/src/io.c"
click node_video_api "https://github.com/miwate/invasion-c/blob/main/prot/video.h"
click node_video "https://github.com/miwate/invasion-c/blob/main/src/video.c"
click node_replay_api "https://github.com/miwate/invasion-c/blob/main/prot/replay.h"
click node_levels "https://github.com/miwate/invasion-c/blob/main/levels/demo.txt"
click node_art "https://github.com/miwate/invasion-c/blob/main/tex/zombies.psd"
click node_audio "https://github.com/miwate/invasion-c/blob/main/audio/invasion.mp3"
click node_replay "https://github.com/miwate/invasion-c/blob/main/replay.txt"
click node_leaderboard "https://github.com/miwate/invasion-c/blob/main/lb/scores.txt"

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_makefile,node_gcc,node_sdl,node_game_binary toneBlue
class node_main,node_gameplay_api,node_gameplay,node_io,node_video_api,node_video,node_replay_api toneAmber
class node_levels,node_art,node_audio,node_replay,node_leaderboard toneMint
```

## Components

### Build & Runtime

- [Makefile](https://github.com/miwate/invasion-c/blob/main/Makefile): build entry · Builds the native game executable and selects level scenarios. · `Makefile`
- **GCC**: compiler
- **SDL2 libraries**: native runtime · SDL2, SDL_image, SDL_mixer, and SDL_ttf.
- [jeu](https://github.com/miwate/invasion-c/blob/main/build/jeu): native executable · Generated desktop game binary. · `build/jeu`

### Game Application

- [Main coordinator](https://github.com/miwate/invasion-c/blob/main/src/main.c): application entry · Initializes subsystems, selects levels, runs the loop, and shuts down. · `src/main.c`
- [Gameplay API](https://github.com/miwate/invasion-c/blob/main/prot/jeu.h): C header · `prot/jeu.h`
- [Gameplay engine](https://github.com/miwate/invasion-c/blob/main/src/jeu.c): game rules · Owns game state, wave progression, and outcomes. · `src/jeu.c`
- [Terminal & file I/O](https://github.com/miwate/invasion-c/blob/main/src/io.c): interaction adapter · Keeps textual interaction outside the gameplay engine. · `src/io.c`
- [Video API](https://github.com/miwate/invasion-c/blob/main/prot/video.h): C header · `prot/video.h`
- [SDL renderer](https://github.com/miwate/invasion-c/blob/main/src/video.c): presentation · Creates graphical presentation and renders gameplay state. · `src/video.c`
- [Replay API](https://github.com/miwate/invasion-c/blob/main/prot/replay.h): C header · `prot/replay.h`

### Game Content & Persistence

- [Level scenarios](https://github.com/miwate/invasion-c/blob/main/levels/demo.txt): scenario data · Selectable difficulty and automated game scenarios. · `levels/demo.txt`
- [Textures & font](https://github.com/miwate/invasion-c/blob/main/tex/zombies.psd): media assets · Zombie art, background art, and game font. · `tex/zombies.psd`
- [Game audio](https://github.com/miwate/invasion-c/blob/main/audio/invasion.mp3): audio asset · `audio/invasion.mp3`
- [Replay record](https://github.com/miwate/invasion-c/blob/main/replay.txt): persistent data · `replay.txt`
- [Leaderboard files](https://github.com/miwate/invasion-c/blob/main/lb/scores.txt): persistent data · Scores and congratulatory leaderboard content. · `lb/scores.txt`

## Connections

- Makefile → GCC: invokes
- GCC → jeu: builds
- jeu → Main coordinator: starts
- Main coordinator → Gameplay API: uses
- Gameplay API → Gameplay engine: defines
- Main coordinator → Video API: uses
- Video API → SDL renderer: defines
- Main coordinator → Replay API: uses
- Main coordinator → Level scenarios: selects and loads
- Level scenarios → Gameplay engine: initializes scenario
- Gameplay engine → Terminal & file I/O: exchanges text I/O
- Gameplay engine → SDL renderer: provides state
- SDL renderer → Textures & font: loads
- SDL renderer → Game audio: uses
- Gameplay engine → Replay record: records
- Replay API → Replay record: declares access
- Gameplay engine → Leaderboard files: updates scores
- jeu → SDL2 libraries: links against
