# bitsbytoader/tudorcraft architecture

> Architecture diagram of the GitHub repository bitsbytoader/tudorcraft, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/bitsbytoader/tudorcraft
- Repository: https://github.com/bitsbytoader/tudorcraft

## Overview

##### Main Components Overview

a) Core Components:
- Engine System
- Rendering System
- Networking System
- UI System
- Protocol Implementation

##### Detailed Component Breakdown

A. Engine System (Blue components):
- Core Engine (/Engine/Engine.hpp)
- Physics System (/Engine/Physics/)
- Collidable
- PhysicsConformable
- World Management (/Engine/World/)
- World
- Chunk
- BlockState
- Entity System (/Engine/Mobs/)
- Entity
- EntityComponent
- MobEntity

B. Rendering System (Green components):
- Metal Renderer (/Renderer/)
- Renderer class
- Shaders
- TextureAtlas
- Asset Management (/Assets.xcassets/)

C. Networking System (Purple components):
- TCP Implementation (/Networking/)
- TCPClient
- TCPStream
- Minecraft Protocol (/Minecraft Protocol/)
- Packet System
- NBT Implementation
- Protocol Types (VarInt, UUID)

D. UI System (Orange components):
- SwiftUI Views (/UI/)
- MainScreenView
- GameView
- ConnectionView
- GameHudView
- IPC Communication (NotificationCenter)

##### Connection Flow Representation

**UI Layer → Engine → Networking → Minecraft Server**
**↑                                      ↓**
**UI ← Renderer ← Engine ← Protocol Handler**

##### Specific Design Elements

Crucial interactions:
- IPC communication between Swift UI and C++ engine
- Metal rendering pipeline flow
- Entity component system relationships
- Network protocol packet flow
- Physics system interaction with world and entities

##### Technical Details

Annotations for:
- Metal-cpp integration points
- Smart pointer usage (both Apple's MRC and std::shared_ptr)
- Thread management for networking and UI
- Memory management strategies
- Platform-specific considerations (iOS/macOS)

##### Implementation Notes

Notes regarding:
- Multiplatform support requirements
- Metal API integration points
- SwiftUI and C++ bridging
- Protocol compatibility requirements
- Memory management strategies

Key Considerations:
- Separation between the C++ game engine and Swift UI
- Metal rendering pipeline
- Clear boundaries between networking, game logic, and presentation
- Cross-platform considerations
- Important synchronization points

This will provide a clear understanding of how TudorCraft's components interact while maintaining the game's performance and multiplatform capabilities.

## Diagram (Mermaid)

```mermaid
%%{init: {'theme': 'base', 'themeVariables': { 'fontSize': '16px'}}}%%
flowchart TB
    subgraph UI_Layer
        MainScreen["Main Screen View"]:::ui
        GameView["Game View"]:::ui
        ConnView["Connection View"]:::ui
        GameHUD["Game HUD"]:::ui
        TouchControls["Touch Controls"]:::ui
        BridgeHeader["Bridge Header"]:::bridge
    end

    subgraph Engine_Core
        CoreEngine["Core Engine"]:::engine
        
        subgraph Physics
            PhysicsSystem["Physics System"]:::engine
            Collidable["Collidable"]:::engine
            PhysicsConform["Physics Conformable"]:::engine
        end
        
        subgraph World
            WorldMgmt["World Management"]:::engine
            Chunk["Chunk"]:::engine
            BlockState["Block State"]:::engine
        end
        
        subgraph Entity
            EntitySystem["Entity System"]:::engine
            EntityComp["Entity Component"]:::engine
            MobEntity["Mob Entity"]:::engine
        end

        Math3D["Math Utilities"]:::util
    end

    subgraph Render_System
        MetalRenderer["Metal Renderer"]:::render
        Shaders["Shaders"]:::render
        TextureAtlas["Texture Atlas"]:::render
        Assets["Asset Management"]:::render
        MetalCPP["Metal Framework Integration"]:::render
    end

    subgraph Network_Layer
        TCPImpl["TCP Implementation"]:::network
        MinecraftProto["Minecraft Protocol"]:::network
        ProtoTypes["Protocol Types"]:::network
        PacketSystem["Packet System"]:::network
        NBTImpl["NBT Implementation"]:::network
    end

    %% Connections
    UI_Layer <--> |"IPC Communication"| Engine_Core
    Engine_Core --> Render_System
    Engine_Core <--> Network_Layer
    Render_System --> UI_Layer
    
    %% Internal Connections
    CoreEngine <--> PhysicsSystem
    CoreEngine <--> WorldMgmt
    CoreEngine <--> EntitySystem
    PhysicsSystem --> Collidable
    PhysicsSystem --> PhysicsConform
    WorldMgmt --> Chunk
    WorldMgmt --> BlockState
    EntitySystem --> EntityComp
    EntitySystem --> MobEntity
    
    TCPImpl <--> MinecraftProto
    MinecraftProto <--> ProtoTypes
    MinecraftProto <--> PacketSystem
    MinecraftProto <--> NBTImpl

    MetalRenderer --> Shaders
    MetalRenderer --> TextureAtlas
    MetalRenderer --> Assets
    MetalRenderer <--> MetalCPP

    %% Click Events
    click CoreEngine "https://github.com/BitsByToader/TudorCraft/blob/main//TudorCraft/Engine/Engine.hpp"
    click PhysicsSystem "https://github.com/BitsByToader/TudorCraft/tree/main//TudorCraft/Engine/Physics/"
    click WorldMgmt "https://github.com/BitsByToader/TudorCraft/tree/main//TudorCraft/Engine/World/"
    click EntitySystem "https://github.com/BitsByToader/TudorCraft/tree/main//TudorCraft/Engine/Mobs/"
    click MetalRenderer "https://github.com/BitsByToader/TudorCraft/tree/main//TudorCraft/Renderer/"
    click Shaders "https://github.com/BitsByToader/TudorCraft/blob/main//TudorCraft/Renderer/Shaders.metal"
    click TextureAtlas "https://github.com/BitsByToader/TudorCraft/blob/main//TudorCraft/Textures/TextureAtlas.hpp"
    click Assets "https://github.com/BitsByToader/TudorCraft/tree/main//TudorCraft/Assets.xcassets/"
    click TCPImpl "https://github.com/BitsByToader/TudorCraft/tree/main//TudorCraft/Networking/"
    click MinecraftProto "https://github.com/BitsByToader/TudorCraft/tree/main//TudorCraft/Minecraft Protocol/"
    click ProtoTypes "https://github.com/BitsByToader/TudorCraft/blob/main//TudorCraft/Minecraft Protocol/PacketTypes.hpp"
    click MainScreen "https://github.com/BitsByToader/TudorCraft/blob/main//TudorCraft/UI/MainScreenView.swift"
    click GameView "https://github.com/BitsByToader/TudorCraft/blob/main//TudorCraft/UI/GameView.swift"
    click ConnView "https://github.com/BitsByToader/TudorCraft/blob/main//TudorCraft/UI/ConnectionView.swift"
    click GameHUD "https://github.com/BitsByToader/TudorCraft/blob/main//TudorCraft/UI/GameHudView.swift"
    click TouchControls "https://github.com/BitsByToader/TudorCraft/blob/main//TudorCraft/UI/TouchControlsView.swift"
    click Math3D "https://github.com/BitsByToader/TudorCraft/blob/main//TudorCraft/Utilities/Math3D.hpp"
    click BridgeHeader "https://github.com/BitsByToader/TudorCraft/blob/main//TudorCraft/TudorCraft-Bridging-Header.h"
    click MetalCPP "https://github.com/BitsByToader/TudorCraft/tree/main//metal-cpp/Metal/"

    %% Styles
    classDef engine fill:#a8d0e6,stroke:#333,stroke-width:2px
    classDef render fill:#95e1d3,stroke:#333,stroke-width:2px
    classDef network fill:#a8a8e6,stroke:#333,stroke-width:2px
    classDef ui fill:#f8b195,stroke:#333,stroke-width:2px
    classDef util fill:#f67280,stroke:#333,stroke-width:2px
    classDef bridge fill:#c06c84,stroke:#333,stroke-width:2px

    %% Legend
    subgraph Legend
        Engine["Engine Component"]:::engine
        Renderer["Rendering Component"]:::render
        Network["Network Component"]:::network
        UIComp["UI Component"]:::ui
        Utility["Utility Component"]:::util
        Bridge["Bridge Component"]:::bridge
    end
```
