# youcef3939/frostforge architecture

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

- Interactive diagram: https://gitdiagram.com/youcef3939/frostforge
- Repository: https://github.com/youcef3939/frostforge

## Overview

#### Purpose and Top-Level Shape
FrostForge is a local AI-assisted 3D world generator for the Frostbyte game jam. A React/Vite client collects a scene prompt and style, while a Python API enhances the prompt, invokes the adjacent WorldGen stack, persists GLB output, and exposes it for browser rendering. Core roots are `frontend/`, `backend/`, and `WorldGen/`.

#### Runtime Entry Points
- Python API: `backend/main.py`, launched through Uvicorn (`python -m uvicorn main:app --reload`) or `backend/run_backend.bat`; listens on localhost:8000.
- Browser client: `frontend/src/main.jsx` bootstraps the React application; Vite is configured by `frontend/vite.config.js` and normally serves localhost:5173.
- Generation runtime: `backend/services.py` integrates the externally supplied local `WorldGen/` directory, expected as a sibling of `backend/`.

#### Frontend Interaction Layer
`frontend/src/App.jsx` composes the generation interface and owns high-level UI coordination. User input originates in `frontend/src/components/PromptBar.jsx`; style-related controls are provided by `frontend/src/components/SettingsPanel.jsx`. The client sends raw prompt input to the backend rather than performing prompt construction locally, preserving the API as the prompt and generation boundary.

#### Prompt Enrichment Stage
`backend/prompt_engine.py` centralizes prompt optimization and visual-style keyword injection. `backend/main.py` orchestrates this stage before model generation, allowing the UI’s selected style (such as realistic or low-poly) to become a WorldGen-ready textual request without exposing that transformation as a frontend concern.

#### Generation and Artifact Boundary
`backend/services.py` is the protective adapter around WorldGen imports and generation operations; it isolates the API from the underlying GPU/3D-library stack and its failure modes. `backend/main.py` coordinates request handling, prompt enrichment, service invocation, and response formation. Generated GLB artifacts are written under `backend/static/models` and served statically, separating potentially expensive generation from later asset retrieval.

#### 3D Presentation Flow
`frontend/src/components/Viewer3D.jsx` loads and displays generated GLB models using React Three Fiber, including day/night display controls. The expected flow is: prompt/style input → API request → enhanced prompt → WorldGen output → static model URL → viewer load. `frontend/src/components/Snowflakes.jsx` and `frontend/src/App.css` support the themed presentation but are outside generation logic.

#### Material Dependencies and Infrastructure
The backend requires Python 3.10+, Uvicorn, WorldGen dependencies, PyTorch, and 3D libraries; CUDA is recommended for WorldGen execution. The frontend requires Node.js 18+, React/Vite, Tailwind configuration in `frontend/tailwind.config.js`, and React Three Fiber for model rendering. All described services are local-process infrastructure; no hosted external API is specified.

Main entry points: [`frontend/src/App.jsx`](https://github.com/youcef3939/frostforge/blob/main/frontend/src/App.jsx) (Generation UI), [`backend/main.py`](https://github.com/youcef3939/frostforge/blob/main/backend/main.py) (Generation API), [`backend/services.py`](https://github.com/youcef3939/frostforge/blob/main/backend/services.py) (WorldGen Adapter), [`frontend/src/main.jsx`](https://github.com/youcef3939/frostforge/blob/main/frontend/src/main.jsx) (React Bootstrap)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["React Client"]
  node_browser(("Browser User"))
  node_client_entry["React Bootstrap<br/>React entry<br/>[main.jsx]"]
  node_app["Generation UI<br/>React coordinator<br/>[App.jsx]"]
  node_prompt_bar["Prompt Input<br/>React component<br/>[PromptBar.jsx]"]
  node_settings["Style Controls<br/>React component<br/>[SettingsPanel.jsx]"]
  node_viewer["GLB Viewer<br/>React Three Fiber<br/>[Viewer3D.jsx]"]
  node_vite["Vite Dev Server<br/>frontend runtime<br/>[vite.config.js]"]
end

subgraph group_backend["Python API"]
  node_api{{"Generation API<br/>FastAPI/Uvicorn<br/>[main.py]"}}
  node_prompt_engine["Prompt Enrichment<br/>prompt processor<br/>[prompt_engine.py]"]
  node_worldgen_adapter["WorldGen Adapter<br/>generation service<br/>[services.py]"]
  node_model_store[("Generated GLBs<br/>static artifacts")]
end

subgraph group_worldgen["Local WorldGen"]
  node_worldgen["World Generator<br/>local 3D generation stack"]
end

node_browser -->|"opens client"| node_vite
node_vite -->|"serves"| node_client_entry
node_client_entry -->|"mounts"| node_app
node_app -->|"collects prompt"| node_prompt_bar
node_app -->|"collects style"| node_settings
node_app -->|"raw prompt + style"| node_api
node_api -->|"enriches request"| node_prompt_engine
node_prompt_engine -->|"WorldGen-ready prompt"| node_worldgen_adapter
node_api -->|"orchestrates"| node_worldgen_adapter
node_worldgen_adapter -->|"invokes"| node_worldgen
node_worldgen_adapter -->|"writes GLB"| node_model_store
node_api -->|"serves static URL"| node_model_store
node_api -->|"returns model URL"| node_app
node_app -->|"passes model URL"| node_viewer
node_viewer -->|"loads GLB"| node_model_store

click node_client_entry "https://github.com/youcef3939/frostforge/blob/main/frontend/src/main.jsx"
click node_app "https://github.com/youcef3939/frostforge/blob/main/frontend/src/App.jsx"
click node_prompt_bar "https://github.com/youcef3939/frostforge/blob/main/frontend/src/components/PromptBar.jsx"
click node_settings "https://github.com/youcef3939/frostforge/blob/main/frontend/src/components/SettingsPanel.jsx"
click node_viewer "https://github.com/youcef3939/frostforge/blob/main/frontend/src/components/Viewer3D.jsx"
click node_vite "https://github.com/youcef3939/frostforge/blob/main/frontend/vite.config.js"
click node_api "https://github.com/youcef3939/frostforge/blob/main/backend/main.py"
click node_prompt_engine "https://github.com/youcef3939/frostforge/blob/main/backend/prompt_engine.py"
click node_worldgen_adapter "https://github.com/youcef3939/frostforge/blob/main/backend/services.py"
click node_worldgen "https://github.com/youcef3939/frostforge/tree/main/WorldGen"

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_browser,node_client_entry,node_app,node_prompt_bar,node_settings,node_viewer,node_vite toneBlue
class node_api,node_prompt_engine,node_worldgen_adapter,node_model_store toneAmber
class node_worldgen toneMint
```

## Components

### React Client

- **Browser User**: user
- [React Bootstrap](https://github.com/youcef3939/frostforge/blob/main/frontend/src/main.jsx): React entry · `frontend/src/main.jsx`
- [Generation UI](https://github.com/youcef3939/frostforge/blob/main/frontend/src/App.jsx): React coordinator · `frontend/src/App.jsx`
- [Prompt Input](https://github.com/youcef3939/frostforge/blob/main/frontend/src/components/PromptBar.jsx): React component · `frontend/src/components/PromptBar.jsx`
- [Style Controls](https://github.com/youcef3939/frostforge/blob/main/frontend/src/components/SettingsPanel.jsx): React component · `frontend/src/components/SettingsPanel.jsx`
- [GLB Viewer](https://github.com/youcef3939/frostforge/blob/main/frontend/src/components/Viewer3D.jsx): React Three Fiber · Loads generated models and provides day/night controls. · `frontend/src/components/Viewer3D.jsx`
- [Vite Dev Server](https://github.com/youcef3939/frostforge/blob/main/frontend/vite.config.js): frontend runtime · `frontend/vite.config.js`

### Python API

- [Generation API](https://github.com/youcef3939/frostforge/blob/main/backend/main.py): FastAPI/Uvicorn · Coordinates generation requests and static model delivery. · `backend/main.py`
- [Prompt Enrichment](https://github.com/youcef3939/frostforge/blob/main/backend/prompt_engine.py): prompt processor · Applies optimization and selected visual-style keywords. · `backend/prompt_engine.py`
- [WorldGen Adapter](https://github.com/youcef3939/frostforge/blob/main/backend/services.py): generation service · Isolates API code from WorldGen and GPU/3D failures. · `backend/services.py`
- **Generated GLBs**: static artifacts · Persisted models are available after generation.

### Local WorldGen

- [World Generator](https://github.com/youcef3939/frostforge/tree/main/WorldGen): local 3D generation stack · Adjacent local runtime using PyTorch and 3D libraries. · `WorldGen`

## Connections

- Browser User → Vite Dev Server: opens client
- Vite Dev Server → React Bootstrap: serves
- React Bootstrap → Generation UI: mounts
- Generation UI → Prompt Input: collects prompt
- Generation UI → Style Controls: collects style
- Generation UI → Generation API: raw prompt + style
- Generation API → Prompt Enrichment: enriches request
- Prompt Enrichment → WorldGen Adapter: WorldGen-ready prompt
- Generation API → WorldGen Adapter: orchestrates
- WorldGen Adapter → World Generator: invokes
- WorldGen Adapter → Generated GLBs: writes GLB
- Generation API → Generated GLBs: serves static URL
- Generation API → Generation UI: returns model URL
- Generation UI → GLB Viewer: passes model URL
- GLB Viewer → Generated GLBs: loads GLB
