How frost-phoenix/zig-sweeper works
Project Type and Purpose
• This is a single‐process, full‐stack (client‐only) graphical application.
• Purpose: Run a Minesweeper game on the desktop, parse CLI options, generate and manage the grid, handle input, and render graphics via Raylib.
File Structure
• Top‐level:
• build.zig / flake.nix / treefmt.nix → build & packaging
• res/ → resource assets (if any)
• src/ → core Zig modules
• src/ modules indicate a modular monolith:
• args.zig → CLI parsing
• common.zig → shared types & constants
• grid.zig → grid generation & cell‐state logic
• game.zig → game‐loop, win/loss, flag logic
• camera.zig → zoom/pan transforms
• camera.zig & main.zig → tie modules together
• main.zig → entrypoint, initializes Raylib, starts the loop
Key Components
a. External Systems
• Operating System (Windowing, input events)
• Raylib (graphics & input bindings)
b. Zig‐Sweeper Application Boundary
• Main Entrypoint (main.zig)
• Argument Parser (args.zig)
• Game Core
– Grid Manager (grid.zig)
– Game Logic (game.zig)
• Camera/Viewport (camera.zig)
• Renderer (calls Raylib API)
• Shared Utilities (common.zig)
c. Build & Packaging
• build.zig (Zig build script)
• flake.nix / nix-run (Nix integration)
Relationships & Data Flows
• On launch, Main invokes Argument Parser → config struct
• Main initializes Raylib window & input system
• Game Loop Iteration:
1. Poll OS events → feed into Input Handler
2. Input Handler modifies Game State (grid flags, cell opens)
3. Game Logic updates Grid Manager (win/loss, flood‐fill)
4. Camera updates viewport transforms
6. Raylib presents buffer to OS window
• The loop repeats until exit
Architectural Patterns & Principles
• Modular Monolith: clear separation by concern (parsing, logic, rendering)
• Single‐Threaded Game Loop: deterministic update→render cycle
• Dependency Injection: pass config & shared state into modules
• Layered: CLI → Core → Rendering → External
Elements
• Labels: “Argument Parser,” “Game Loop,” “Grid Manager,” etc.
• Optionally, annotate module filenames to map directly to code (e.g., args.zig)