# sebaw65/rocket_game architecture

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

- Interactive diagram: https://gitdiagram.com/sebaw65/rocket_game
- Repository: https://github.com/sebaw65/rocket_game

## Overview

##### Project Type and Purpose
- Project type: A browser-based 2D game built with TypeScript and ECS (Entity‑Component‑System) architecture.
- Purpose: Simulate and render a cellular‑automata‑driven environment (“rocket” game) in a canvas context, processing user input, physics, and rendering in a game loop.

##### File Structure
Top‑level folders & files:
- public/index.html – Hosts the canvas and bootstraps the game.
- src/
– core/application/GameApplication.ts – The central game loop and system orchestrator.
– components/… – Definitions of ECS components (e.g. InputComponent, PositionComponent, RenderComponent).
– entities/Entity.ts – Base entity class holding components.
– systems/… – Distinct systems grouped by concern:
· input/MouseSystem.ts
· physics/CellularAutomataSystem.ts, GravitySystem.ts
· rendering/CanvasSystem.ts, RenderSystem.ts, ResizeSystem.ts
– main.ts – Entry point that instantiates GameApplication.

##### README
- Confirms ECS architecture, Canvas API for rendering, cellular automata for simulation.
- No external backend or microservice layer – it’s pure front end with a rendering engine.

a) Main Components
1) Entry Point (main.ts)
2) GameApplication (core) – orchestrator & loop
3) Entity Store – holds all Entity instances
4) Component Registry – available component types
5) Systems:
- Input System (MouseSystem)
- Physics Systems (CellularAutomataSystem, GravitySystem)
- Rendering Systems (CanvasSystem, RenderSystem, ResizeSystem)
6) Canvas Context (HTML5 Canvas)
7) Browser/Event Layer (DOM events for input & resize)

b) Relationships and Interactions
1) main.ts → GameApplication (initialization)
2) GameApplication registers Systems & Entities
3) Game loop tick:
- Input System reads DOM events → updates InputComponents
- Physics Systems read PositionComponent & neighbor data → mutate PositionComponent
- CanvasSystem issues actual Canvas API calls to HTML5 Canvas
4) Resize System listens to window resize events → updates Canvas dimensions
5) Entities act as data carriers; Components are plain data

c) Architectural Patterns & Principles
- ECS: Decoupling of data (Components) and logic (Systems)
- Single Responsibility: Each System focuses on one concern (input, physics, rendering)
- Dependency Injection: GameApplication injects references to Systems & Entity store

d) Key Technologies & Frameworks
- TypeScript + ES Modules
- Vite (build & dev server)
- Canvas API for rendering
- Cellular Automata algorithm in physics

## Diagram (Mermaid)

```mermaid
flowchart TB
  subgraph "Layer 1: Browser/Host"
    H1["index.html"]:::browser
    H2["vite-env.d.ts"]:::browser
  end

  subgraph "Layer 2: Application Core"
    M["main.ts"]:::core
    GA["GameApplication"]:::core
  end

  subgraph "Layer 3: ECS Domain"
    subgraph "Store & Registry"
      ES["Entity Store"]:::ecs
      CR["Component Registry"]:::ecs
    end
    subgraph "Components"
      IC["InputComponent"]:::ecs
      PC["PositionComponent"]:::ecs
      RC["RenderComponent"]:::ecs
    end
    subgraph "Systems"
      SI["MouseSystem"]:::system
      SP_CA["CellularAutomataSystem"]:::system
      SP_G["GravitySystem"]:::system
      SR_CAN["CanvasSystem"]:::system
      SR_R["RenderSystem"]:::system
      SR_Res["ResizeSystem"]:::system
    end
  end

  subgraph "Layer 4: Rendering Output"
    CANVAS["HTML5 Canvas Context"]:::browser
  end

  H1 -->|"loads"| M
  M -->|"instantiates"| GA
  GA -->|"manages"| ES
  GA -->|"manages"| CR
  GA -->|"registers"| SI
  GA -->|"registers"| SP_CA
  GA -->|"registers"| SP_G
  GA -->|"registers"| SR_CAN
  GA -->|"registers"| SR_R
  GA -->|"registers"| SR_Res

  GA -->|"tick() calls"| SI
  GA -->|"tick() calls"| SP_CA
  GA -->|"tick() calls"| SP_G
  GA -->|"tick() calls"| SR_R
  SR_CAN -->|"draw"| CANVAS
  H1 -->|"DOM events"| SI
  H1 -->|"resize events"| SR_Res
  SI -->|"updates"| IC
  SP_CA -->|"mutates"| PC
  SP_G -->|"mutates"| PC
  SR_R -->|"reads"| PC
  SR_R -->|"reads"| RC
  ES -->|"contains"| IC
  ES -->|"contains"| PC
  ES -->|"contains"| RC
  CR -->|"defines"| IC
  CR -->|"defines"| PC
  CR -->|"defines"| RC

  click M "https://github.com/sebaw65/rocket_game/blob/main/src/main.ts"
  click GA "https://github.com/sebaw65/rocket_game/blob/main/src/core/application/GameApplication.ts"
  click ES "https://github.com/sebaw65/rocket_game/blob/main/src/entities/Entity.ts"
  click IC "https://github.com/sebaw65/rocket_game/blob/main/src/components/Input.ts"
  click PC "https://github.com/sebaw65/rocket_game/blob/main/src/components/PositionComponent.ts"
  click RC "https://github.com/sebaw65/rocket_game/blob/main/src/components/RenderComponent.ts"
  click SI "https://github.com/sebaw65/rocket_game/blob/main/src/systems/input/MouseSystem.ts"
  click SP_CA "https://github.com/sebaw65/rocket_game/blob/main/src/systems/physics/CellularAutomataSystem.ts"
  click SP_G "https://github.com/sebaw65/rocket_game/blob/main/src/systems/physics/GravitySystem.ts"
  click SR_CAN "https://github.com/sebaw65/rocket_game/blob/main/src/systems/rendering/CanvasSystem.ts"
  click SR_R "https://github.com/sebaw65/rocket_game/blob/main/src/systems/rendering/RenderSystem.ts"
  click SR_Res "https://github.com/sebaw65/rocket_game/blob/main/src/systems/rendering/ResizeSystem.ts"
  click H1 "https://github.com/sebaw65/rocket_game/blob/main/public/index.html"
  click H2 "https://github.com/sebaw65/rocket_game/blob/main/src/vite-env.d.ts"

  classDef browser fill:#cccccc,stroke:#333,stroke-width:1px
  classDef core fill:#85C1E9,stroke:#333,stroke-width:1px
  classDef ecs fill:#82E0AA,stroke:#333,stroke-width:1px
  classDef system fill:#F5B041,stroke:#333,stroke-width:1px
```
