# k4yseer/pc_playground_frontend architecture

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

- Interactive diagram: https://gitdiagram.com/k4yseer/pc_playground_frontend
- Repository: https://github.com/k4yseer/pc_playground_frontend

## Overview

##### Project type and purpose
- This is a SvelteKit-powered, front-end web application for PC part browsing and a 3D PC-building simulator.
- It uses:
– SvelteKit’s file-based routing and SSR/hydration
– A client-side Three.js simulation engine
– A thin “API” layer (lib/api) that fetches part data
– Svelte stores to manage app state
– Static assets (textures, videos) under “static/”

##### File structure
- Top-level:
– src/routes → SvelteKit pages: /, /simulator, /webpages/*
– src/lib/api → modules to load CPU, GPU, RAM, etc., from a data service
– src/lib/simulator → Three.js engine classes (SceneManager, RendererManager, ControlsManager, etc.), Svelte components for tutorial/UI, stores
– src/lib/webpages → site UI components: navbar, cards, sidebar
– static/assets, static/textures, static/videos → 3D model textures and tutorial videos
– config: svelte.config.js, vite.config.ts, tsconfig.json
- No server-side source code beyond SvelteKit – likely all logic runs in the browser (SSR only for initial HTML).

##### README for architecture hints
- It’s a standard SvelteKit/Vite project
- No custom backend adapter shown – probably relies on client-side fetch to some external part-data API.

##### Main components & their relationships
A. SvelteKit Router & SSR Server
– Serves initial HTML for each route (/, /simulator, /webpages/...)
– Hydrates to a SPA in the browser
B. UI Layer
– Route pages (src/routes/*.svelte) use lib/webpages components (navbar, cards, sidebar)
– Simulator page uses lib/simulator UI components + hooks into Simulation Engine
C. Simulation Engine (lib/simulator)
– Three.js managers: SceneManager, RendererManager, ControlsManager, etc.
– TutorialManager orchestrates on-screen guides + video playback
– ModelsManager loads 3D models & textures (static/textures)
– AnimationManager, PostProcessingManager handle visuals
D. State Management (Svelte Stores)
– recommendation.ts, selectedPart.ts, etc. feed both UI and simulator
E. API Layer (lib/api)
– Exposes functions (cpu.ts, gpu.ts, etc.) that fetch part data from an external REST service
– Called by UI components and possibly by simulation logic to fetch compatibility data
F. Static Assets
– Textures & videos served as static files by SvelteKit
G. External Services
– Third-party/data service for PC-part metadata

##### Architectural patterns & design principles
- Separation of concerns:
– Routing/SSR vs. client-side SPA
– UI components vs. simulation engine vs. API modules
- Modular Three.js engine:
– Each Manager class encapsulates one subsystem
- Unidirectional data flow:
– UI dispatch → API fetch → Svelte store update → UI/simulator react

– “SvelteKit Server / Router (SSR + Hydration)”
– “Browser Client”
- UI Layer (Route Pages + Webpage Components)
- Simulation Engine (Three.js Managers)
- State Store Layer (Svelte stores)
- API Client Module (lib/api)
– “Static Assets” (textures, videos)
– “External Part-Data Service”
– “Build & Deployment” (Vite bundler, adapters)
– Browser → SvelteKit Server: initial page request
– SvelteKit Server → Browser: HTML + JS bundle
– Browser UI → API Client → External Service → API Client → Store → UI/Simulator
– UI controls → Simulator Managers → WebGL Canvas
– Simulator Managers → ModelsManager → Static Assets
– Build & Deploy → produces CDN-served JS/CSS/HTML
c. Patterns:
d. Technologies:
– SvelteKit, Vite, TypeScript, Three.js, Svelte stores

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Top-level infrastructure
    SKSR["SvelteKit Server / Router<br/>(SSR + Hydration)"]:::infra
    Build["Build & Deployment<br/>(Vite Bundler)"]:::infra
    External["External Part-Data Service"]:::external

    %% Browser Client
    subgraph "Browser Client"
        direction TB

        %% UI Layer
        subgraph "UI Layer" 
            direction TB
            Routes["Route Pages<br/>(src/routes)"]:::frontend
            WebComp["Webpage Components<br/>(lib/webpages)"]:::frontend
        end

        %% Simulation Engine
        subgraph "Simulation Engine" 
            direction TB
            ThreeInit["threejsapp.ts"]:::simulation
            subgraph "Managers (lib/simulator/classes)"
                direction TB
                SceneMgr["SceneManager"]:::simulation
                RendererMgr["RendererManager"]:::simulation
                ControlsMgr["ControlsManager"]:::simulation
                CameraMgr["CameraManager"]:::simulation
                ModelsMgr["ModelsManager"]:::simulation
                AnimMgr["AnimationManager"]:::simulation
                PostProcMgr["PostProcessingManager"]:::simulation
                TutorialMgr["TutorialManager"]:::simulation
                GameMgr["GameManager"]:::simulation
                CableMgr["CableManager"]:::simulation
                OutlinePass["OutlinePassCustom"]:::simulation
            end
        end

        %% State Stores
        subgraph "State Management<br/>(Svelte Stores)"
            direction TB
            GlobalStores["Global Stores<br/>(lib/stores)"]:::data
            SimStores["Simulator Stores<br/>(lib/simulator)"]:::data
        end

        %% API Client
        APIClient["API Layer<br/>(lib/api)"]:::data

        %% Static Assets access
        StaticAssets["Static Assets<br/>(static/)"]:::assets
    end

    %% Data flow arrows
    SKSR -->|Serves HTML & JS| Routes
    SKSR -->|Serves HTML & JS| WebComp
    Build -->|Bundles & Deploys| SKSR

    %% UI to API and State
    Routes -->|fetch data| APIClient
    WebComp -->|fetch data| APIClient
    APIClient -->|update| GlobalStores
    APIClient -->|update| SimStores
    GlobalStores -->|provide state| Routes
    GlobalStores -->|provide state| WebComp
    SimStores -->|provide state| ThreeInit

    %% UI controls simulation
    WebComp -->|control| ThreeInit
    ThreeInit -->|orchestrates managers| SceneMgr
    ThreeInit -->|orchestrates managers| RendererMgr
    ThreeInit -->|orchestrates managers| ControlsMgr
    ThreeInit -->|orchestrates managers| CameraMgr
    ThreeInit -->|orchestrates managers| ModelsMgr
    ThreeInit -->|orchestrates managers| AnimMgr
    ThreeInit -->|orchestrates managers| PostProcMgr
    ThreeInit -->|orchestrates managers| TutorialMgr
    ThreeInit -->|orchestrates managers| GameMgr
    ThreeInit -->|orchestrates managers| CableMgr
    ThreeInit -->|orchestrates managers| OutlinePass

    ModelsMgr -->|load textures| StaticAssets
    TutorialMgr -->|play videos| StaticAssets

    %% API to external
    APIClient -->|REST requests| External
    External -->|responses| APIClient

    %% Click events
    click Routes "https://github.com/k4yseer/pc_playground_frontend/tree/main/src/routes"
    click SKSR "https://github.com/k4yseer/pc_playground_frontend/blob/main/src/routes/+layout.svelte"
    click SKSR "https://github.com/k4yseer/pc_playground_frontend/blob/main/src/routes/+page.svelte"
    click Routes "https://github.com/k4yseer/pc_playground_frontend/blob/main/src/routes/simulator/+page.svelte"
    click Routes "https://github.com/k4yseer/pc_playground_frontend/blob/main/src/routes/webpages/homepage/+page.svelte"
    click Routes "https://github.com/k4yseer/pc_playground_frontend/blob/main/src/routes/webpages/partSearch/+page.svelte"
    click Routes "https://github.com/k4yseer/pc_playground_frontend/blob/main/src/routes/webpages/pcbuild/+page.svelte"
    click Routes "https://github.com/k4yseer/pc_playground_frontend/blob/main/src/routes/webpages/questionnaire/+page.svelte"

    click WebComp "https://github.com/k4yseer/pc_playground_frontend/blob/main/src/lib/webpages/components/navbar.svelte"
    click WebComp "https://github.com/k4yseer/pc_playground_frontend/blob/main/src/lib/webpages/components/partCard.svelte"
    click WebComp "https://github.com/k4yseer/pc_playground_frontend/blob/main/src/lib/webpages/components/partInfo.svelte"
    click WebComp "https://github.com/k4yseer/pc_playground_frontend/blob/main/src/lib/webpages/components/gameCard.svelte"
    click WebComp "https://github.com/k4yseer/pc_playground_frontend/blob/main/src/lib/webpages/components/postCard.svelte"
    click WebComp "https://github.com/k4yseer/pc_playground_frontend/blob/main/src/lib/webpages/components/btnIcon.svelte"
    click WebComp "https://github.com/k4yseer/pc_playground_frontend/blob/main/src/lib/webpages/components/sidebar.svelte"

    click ThreeInit "https://github.com/k4yseer/pc_playground_frontend/blob/main/src/lib/simulator/threejsapp.ts"
    click SceneMgr "https://github.com/k4yseer/pc_playground_frontend/blob/main/src/lib/simulator/classes/SceneManager.ts"
    click RendererMgr "https://github.com/k4yseer/pc_playground_frontend/blob/main/src/lib/simulator/classes/RendererManager.ts"
    click ControlsMgr "https://github.com/k4yseer/pc_playground_frontend/blob/main/src/lib/simulator/classes/ControlsManager.ts"
    click CameraMgr "https://github.com/k4yseer/pc_playground_frontend/blob/main/src/lib/simulator/classes/CameraManager.ts"
    click ModelsMgr "https://github.com/k4yseer/pc_playground_frontend/blob/main/src/lib/simulator/classes/ModelsManager.ts"
    click AnimMgr "https://github.com/k4yseer/pc_playground_frontend/blob/main/src/lib/simulator/classes/AnimationManager.ts"
    click PostProcMgr "https://github.com/k4yseer/pc_playground_frontend/blob/main/src/lib/simulator/classes/PostProcessingManager.ts"
    click TutorialMgr "https://github.com/k4yseer/pc_playground_frontend/blob/main/src/lib/simulator/classes/TutorialManager.ts"
    click GameMgr "https://github.com/k4yseer/pc_playground_frontend/blob/main/src/lib/simulator/classes/GameManager.ts"
    click CableMgr "https://github.com/k4yseer/pc_playground_frontend/blob/main/src/lib/simulator/classes/CableManager.ts"
    click OutlinePass "https://github.com/k4yseer/pc_playground_frontend/blob/main/src/lib/simulator/classes/OutlinePassCustom.js"

    click GlobalStores "https://github.com/k4yseer/pc_playground_frontend/blob/main/src/lib/stores/recommendation.ts"
    click GlobalStores "https://github.com/k4yseer/pc_playground_frontend/blob/main/src/lib/stores/selectedPart.ts"
    click SimStores "https://github.com/k4yseer/pc_playground_frontend/blob/main/src/lib/simulator/stores.ts"

    click APIClient "https://github.com/k4yseer/pc_playground_frontend/blob/main/src/lib/api/cpu.ts"
    click APIClient "https://github.com/k4yseer/pc_playground_frontend/blob/main/src/lib/api/gpu.ts"
    click APIClient "https://github.com/k4yseer/pc_playground_frontend/blob/main/src/lib/api/ram.ts"
    click APIClient "https://github.com/k4yseer/pc_playground_frontend/blob/main/src/lib/api/motherboard.ts"
    click APIClient "https://github.com/k4yseer/pc_playground_frontend/blob/main/src/lib/api/psu.ts"
    click APIClient "https://github.com/k4yseer/pc_playground_frontend/blob/main/src/lib/api/cooler.ts"
    click APIClient "https://github.com/k4yseer/pc_playground_frontend/blob/main/src/lib/api/storage.ts"
    click APIClient "https://github.com/k4yseer/pc_playground_frontend/blob/main/src/lib/api/case.ts"
    click APIClient "https://github.com/k4yseer/pc_playground_frontend/blob/main/src/lib/api/compatible.ts"
    click APIClient "https://github.com/k4yseer/pc_playground_frontend/blob/main/src/lib/api/recommendation.ts"
    click APIClient "https://github.com/k4yseer/pc_playground_frontend/blob/main/src/lib/api/searchColumns.ts"
    click APIClient "https://github.com/k4yseer/pc_playground_frontend/blob/main/src/lib/api/sidebarData.ts"
    click APIClient "https://github.com/k4yseer/pc_playground_frontend/blob/main/src/lib/api/game.ts"
    click APIClient "https://github.com/k4yseer/pc_playground_frontend/blob/main/src/lib/api/index.ts"

    click StaticAssets "https://github.com/k4yseer/pc_playground_frontend/tree/main/static/textures"
    click StaticAssets "https://github.com/k4yseer/pc_playground_frontend/tree/main/static/assets"
    click StaticAssets "https://github.com/k4yseer/pc_playground_frontend/tree/main/static/videos"

    %% Styles
    classDef frontend fill:#D6EFFF,stroke:#02457A,stroke-width:2px
    classDef simulation fill:#FFF4D6,stroke:#A07400,stroke-width:2px
    classDef data fill:#E8F9E9,stroke:#1B5E20,stroke-width:2px
    classDef assets fill:#F0E6FF,stroke:#4A148C,stroke-width:2px
    classDef external fill:#FFEDE0,stroke:#BF360C,stroke-width:2px
    classDef infra fill:#E0E0E0,stroke:#424242,stroke-width:2px
```
