# qadric/minecraftclone architecture

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

- Interactive diagram: https://gitdiagram.com/qadric/minecraftclone
- Repository: https://github.com/qadric/minecraftclone

## Overview

##### Project Type and Purpose
- This is a standalone C++ voxel‐based game engine (Minecraft clone) built with modern C++17 and OpenGL.
- It performs procedural terrain generation, real‐time chunk management, block interactions, textured rendering, and a simple HUD.

##### File Structure
Top‐level directories:
- / – public headers and bundled libraries (FastNoiseLite, stb_image, GLAD)
- src/     – implementation of core engine classes and main.cpp
- shaders/ – GLSL vertex/fragment shaders for default, sea, wireframe, and selection effects
- textures/– texture atlases and block textures
- media/   – screenshots and other assets
Key patterns:
- Separation by subsystem (rendering, world, input, utilities)
- Build config via CMakeLists.txt
- External dependencies (GLFW, GLAD, stb_image, FastNoiseLite) isolated in include/

##### README Insights
- Procedural generation via FastNoiseLite
- Infinite chunk loading/unloading
- Mesh‐based rendering using VAO/VBO/EBO abstractions
- Custom shader pipeline plus post‐processing (underwater effect)
- Simple HUD overlay for block selection

##### Main Components and Their Interactions
A. Application / Core Loop
- main.cpp
- WindowManager (GLFW + glad initialization)
- InputManager (keyboard/mouse → camera/world updates)
- GameLoop (poll events → update → render → swap buffers)
B. World Management
- World class
– ChunkManager: handles chunk loading/unloading
– NoiseGenerator: FastNoiseLite wrapper for terrain height data
– BlockManager: tracks placed/removed blocks
- Sea: water plane with specialized shader
C. Rendering Subsystem
- Renderer
– Mesh classes (VAO, VBO, EBO)
– TextureAtlasManager (stb_image)
– ShaderManager (compiles and binds GLSL shaders)
– PostProcessor (underwater effect)
D. Camera & HUD
- CameraClass: view/projection matrices
- SelectedBlock: preview geometry + HUD overlay
E. External Services & Assets
- OpenGL 3.3+ (render API)
- GLFW (window & input)
- GLAD (OpenGL loader)
- stb_image (texture loading)
- FastNoiseLite (noise generation)
- Shader files (.vert/.frag)
- Texture atlas images

##### Architectural Patterns and Design Principles
- Modular subsystems communicate via well‐defined interfaces:
Renderer ← World (mesh data)
World ← NoiseGenerator (terrain data)
InputManager → Camera/World
- Data‐driven rendering: chunk meshes generated in CPU, sent to GPU via VAO/VBO/EBO
- Single application monolith, but layered:
Application Layer → Game Logic Layer → Rendering Layer → Hardware/API Layer

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Application Core" 
        direction TB
        Main["main.cpp"]:::engine
        WindowMgr["WindowManager\n(window & input init)"]:::engine
        GameLoop["GameLoop"]:::engine
    end

    subgraph "WorldManager" 
        direction TB
        World["World"]:::engine
        ChunkMgr["ChunkManager"]:::engine
        NoiseGen["NoiseGenerator"]:::engine
        BlockMgr["BlockManager"]:::engine
        SeaPlane["Sea"]:::engine
    end

    subgraph "Rendering Subsystem"
        direction TB
        MeshMgr["MeshManager"]:::engine
        ShaderMgr["ShaderManager"]:::engine
        TextureMgr["TextureAtlasManager"]:::engine
        PostProc["PostProcessor"]:::engine
    end

    subgraph "Camera & HUD"
        direction TB
        Camera["CameraClass"]:::engine
        SelectedBlk["SelectedBlock"]:::engine
    end

    subgraph "External Libraries" 
        direction TB
        GLFW["GLFW"]:::external
        GLAD["GLAD"]:::external
        stbImg["stb_image"]:::external
        FastNoise["FastNoiseLite"]:::external
        GPU["GPU / OpenGL"]:::external
    end

    subgraph "Assets" 
        direction TB
        Shaders["Shaders (.vert/.frag)"]:::asset
        Textures["Textures"]:::asset
        Media["Media Assets"]:::asset
    end

    %% Connections
    Main -->|"initializes"| WindowMgr
    WindowMgr -->|"polls events"| GameLoop
    GameLoop -->|"updates"| World
    GameLoop -->|"renders"| Renderer[("Renderer")]:::engine
    WindowMgr -->|"input to"| World
    WindowMgr -->|"camera control"| Camera
    World -->|"provides mesh data"| MeshMgr
    NoiseGen -->|"terrain data"| ChunkMgr
    ChunkMgr -->|"chunks"| World
    World -->|"blocks"| BlockMgr
    World -->|"water plane"| SeaPlane
    MeshMgr -->|"draw calls"| GPU
    ShaderMgr -->|"binds shaders"| GPU
    TextureMgr -->|"binds textures"| GPU
    Camera -->|"view/proj matrices"| Renderer
    SelectedBlk -->|"overlay data"| Renderer
    Renderer -->|"post process"| PostProc
    PostProc -->|"framebuffer"| GPU

    %% Dependencies
    WindowMgr -->|"uses"| GLFW
    WindowMgr -->|"uses"| GLAD
    TextureMgr -->|"loads textures via"| stbImg
    NoiseGen -->|"uses"| FastNoise
    ShaderMgr -->|"loads from"| Shaders
    TextureMgr -->|"loads from"| Textures

    %% Click Events
    click Main "https://github.com/qadric/minecraftclone/blob/main/src/main.cpp"
    click WindowMgr "https://github.com/qadric/minecraftclone/blob/main/include/windowClass.hpp"
    click WindowMgr "https://github.com/qadric/minecraftclone/blob/main/src/windowClass.cpp"
    click World "https://github.com/qadric/minecraftclone/blob/main/include/world.hpp"
    click World "https://github.com/qadric/minecraftclone/blob/main/src/world.cpp"
    click ChunkMgr "https://github.com/qadric/minecraftclone/blob/main/include/chunk.hpp"
    click ChunkMgr "https://github.com/qadric/minecraftclone/blob/main/src/chunk.cpp"
    click NoiseGen "https://github.com/qadric/minecraftclone/blob/main/include/FastNoiseLite.hpp"
    click BlockMgr "https://github.com/qadric/minecraftclone/blob/main/include/block.hpp"
    click BlockMgr "https://github.com/qadric/minecraftclone/blob/main/src/block.cpp"
    click SeaPlane "https://github.com/qadric/minecraftclone/blob/main/include/sea.hpp"
    click SeaPlane "https://github.com/qadric/minecraftclone/blob/main/src/sea.cpp"
    click MeshMgr "https://github.com/qadric/minecraftclone/blob/main/include/VAO.hpp"
    click MeshMgr "https://github.com/qadric/minecraftclone/blob/main/src/VAO.cpp"
    click MeshMgr "https://github.com/qadric/minecraftclone/blob/main/include/VBO.hpp"
    click MeshMgr "https://github.com/qadric/minecraftclone/blob/main/src/VBO.cpp"
    click MeshMgr "https://github.com/qadric/minecraftclone/blob/main/include/EBO.hpp"
    click MeshMgr "https://github.com/qadric/minecraftclone/blob/main/src/EBO.cpp"
    click ShaderMgr "https://github.com/qadric/minecraftclone/blob/main/include/shaderClass.hpp"
    click ShaderMgr "https://github.com/qadric/minecraftclone/blob/main/src/shaderClass.cpp"
    click TextureMgr "https://github.com/qadric/minecraftclone/blob/main/include/textureClass.hpp"
    click TextureMgr "https://github.com/qadric/minecraftclone/blob/main/src/textureClass.cpp"
    click Camera "https://github.com/qadric/minecraftclone/blob/main/include/cameraClass.hpp"
    click Camera "https://github.com/qadric/minecraftclone/blob/main/src/cameraClass.cpp"
    click SelectedBlk "https://github.com/qadric/minecraftclone/blob/main/include/selectedBlock.hpp"
    click SelectedBlk "https://github.com/qadric/minecraftclone/blob/main/src/selectedBlock.cpp"
    click GLAD "https://github.com/qadric/minecraftclone/blob/main/include/glad/glad.h"
    click GLAD "https://github.com/qadric/minecraftclone/blob/main/src/glad.c"
    click stbImg "https://github.com/qadric/minecraftclone/blob/main/include/stb/stb_image.h"
    click stbImg "https://github.com/qadric/minecraftclone/blob/main/src/stb.cpp"

    %% Styles
    classDef engine fill:#cce5ff,stroke:#0066cc
    classDef external fill:#d4edda,stroke:#228B22
    classDef asset fill:#fff3cd,stroke:#e69a00
```
