# bbycroft/llm-viz architecture

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

- Interactive diagram: https://gitdiagram.com/bbycroft/llm-viz
- Repository: https://github.com/bbycroft/llm-viz

## Overview

##### Project Type & Purpose
- The repository is a multi-project full-stack application built with Next.js. It integrates a homepage, interactive LLM visualization, and a (work‐in‐progress) CPU simulation tool.
- LLM Visualization focuses on rendering complex neural network structures interactively (supporting both small and larger “GPT” models).
- CPU Simulation provides a digital schematic editor, complete with simulation of circuit execution, including RISC-V instruction sets and low-level gate–based interactions.

##### Main Components
- Frontend (Next.js Application):
– Pages and routes (see src/app folders for cpu, llm, fluidsim, homepage).
– UI components: Each project has its React components (e.g., in src/cpu, src/llm, etc.), styled using SCSS and Tailwind CSS.
- CPU Simulation Module:
– Schematic Editor: Components, guides, toolbars, and schematics (refer to src/cpu/guide, src/cpu/schematics, and src/cpu/toolbars).
– Execution Model & API: Backend API endpoints for operations like “save-schematic-to-file” (src/app/cpu/api) and simulation logic found in src/cpu modules.
– Test assets and example RISC-V binaries located in public/riscv.
- LLM Visualization Module:
– 3D Interactive Model components appear in src/llm and related component folders.
– Rendering logic includes WebGPU support (see src/llm/gpu) and WASM integration (src/llm/wasm) for intensive computations.
– Interaction components (like controls, commentary, and walk-through modules in src/llm/walkthrough).
- Shared Utilities & Assets:
– Common utilities in src/utils (for math, hooks, pointer events, etc.)
– Fonts and images found in public and fonts directories (which tie into the rendering of text/models).
– Global styling via styles/main.css, tailwind.config.js, etc.
- Deployment & Config:
– Next.js configurations (next.config.js, next-env.d.ts) and package.json for dependency management.
– Build scripts and configuration files (e.g., .editorconfig, tsconfig.json) that support the overall development environment.

##### Relationships & Interactions
- User Interaction Flow: End users interact via a browser that loads the Next.js application.
- Routing: Clear separation across the three main areas (homepage, LLM visualization, CPU simulation) via the app and page components.
- Component Communication:
– UI components call shared utilities for rendering updates.
– The CPU simulation API (e.g., “save-schematic-to-file”) accepts data from the schematic editor and saves or processes it.
– The LLM module works with rendering layers and WASM modules to perform heavy computations.
- Data Flow:
– Demonstrate dependency links such that both the LLM and CPU modules rely on shared utilities and styling resources.

##### Architectural Patterns & Technologies
- Modular, component-based design using React. Each major project is architected using modular React components and routes.
- Use of Next.js means SSR and API endpoints are integrated into a single project structure.
- Separation between presentation (React/SCSS) and logic (CPU simulation calculations, WASM-based LLM model).
- WebAssembly integration in the LLM module for performance-intensive tasks.
- Use of configuration management and build tooling (e.g., npm, yarn, and build scripts in the project).

## Diagram (Mermaid)

```mermaid
graph TD
    Browser("User Browser"):::external
    NextJS("Next.js Application"):::frontend
    Browser --> NextJS

    subgraph "Frontend"
        AppRoutes("Pages & Routes (src/app)"):::route
        Homepage("Homepage (src/homepage)"):::page
        CPUSimulationPage("CPU Simulation Page"):::page
        LLMVisualizationPage("LLM Visualization Page"):::page
        FluidSimPage("Fluid Simulation Page"):::page
    end

    NextJS --> AppRoutes
    NextJS --> Homepage
    NextJS --> CPUSimulationPage
    NextJS --> LLMVisualizationPage
    NextJS --> FluidSimPage

    subgraph "CPU Simulation Module"
        SchematicEditor("Schematic Editor & UI (src/cpu)"):::cpu
        ExecutionModel("Execution Model & API (src/app/cpu/api/save-schematic-to-file/route.ts)"):::api
        TestAssets("RISC-V Test Assets (public/riscv)"):::test
    end

    CPUSimulationPage --> SchematicEditor
    SchematicEditor --> ExecutionModel
    SchematicEditor --> TestAssets

    subgraph "LLM Visualization Module"
        Model3D("3D Interactive Model & UI (src/llm)"):::llm
        WebGPURendering("WebGPU Rendering (src/llm/gpu/WebGpuMain.ts)"):::llm
        WASMIntegration("WASM Integration (src/llm/wasm)"):::llm
    end

    LLMVisualizationPage --> Model3D
    Model3D --> WebGPURendering
    Model3D --> WASMIntegration

    subgraph "Fluid Simulation Module"
        FluidSim("2D Schematic Editor & Simulation (src/fluidsim)"):::fluid
    end

    FluidSimPage --> FluidSim

    subgraph "Shared & Assets"
        SharedUtils("Shared Utilities (src/utils)"):::utils
        GlobalStyles("Global Styles (styles/main.css, tailwind.config.js)"):::styles
        PublicAssets("Public Assets (public)"):::public
    end

    AppRoutes --> SharedUtils
    Homepage --> SharedUtils
    CPUSimulationPage --> SharedUtils
    LLMVisualizationPage --> SharedUtils
    FluidSimPage --> SharedUtils
    NextJS --> PublicAssets

    %% Click Events
    click AppRoutes "https://github.com/bbycroft/llm-viz/tree/main/src/app"
    click Homepage "https://github.com/bbycroft/llm-viz/tree/main/src/homepage"
    click SchematicEditor "https://github.com/bbycroft/llm-viz/tree/main/src/cpu"
    click ExecutionModel "https://github.com/bbycroft/llm-viz/blob/main/src/app/cpu/api/save-schematic-to-file/route.ts"
    click TestAssets "https://github.com/bbycroft/llm-viz/tree/main/public/riscv"
    click Model3D "https://github.com/bbycroft/llm-viz/tree/main/src/llm"
    click WebGPURendering "https://github.com/bbycroft/llm-viz/blob/main/src/llm/gpu/WebGpuMain.ts"
    click WASMIntegration "https://github.com/bbycroft/llm-viz/tree/main/src/llm/wasm"
    click FluidSim "https://github.com/bbycroft/llm-viz/tree/main/src/fluidsim"
    click SharedUtils "https://github.com/bbycroft/llm-viz/tree/main/src/utils"
    click GlobalStyles "https://github.com/bbycroft/llm-viz/blob/main/styles/main.css"
    click PublicAssets "https://github.com/bbycroft/llm-viz/tree/main/public"

    %% Styles
    classDef external fill:#FFF,stroke:#333,stroke-width:2px;
    classDef frontend fill:#BEE3F8,stroke:#2C5282,stroke-width:2px;
    classDef page fill:#FEEBC8,stroke:#975A16,stroke-width:2px;
    classDef route fill:#FEEBC8,stroke:#975A16,stroke-width:2px;
    classDef cpu fill:#C6F6D5,stroke:#2F855A,stroke-width:2px;
    classDef api fill:#FAF089,stroke:#D69E2E,stroke-width:2px;
    classDef test fill:#FAF089,stroke:#D69E2E,stroke-width:2px;
    classDef llm fill:#FED7E2,stroke:#C53030,stroke-width:2px;
    classDef fluid fill:#E9D8FD,stroke:#6B46C1,stroke-width:2px;
    classDef utils fill:#EDF2F7,stroke:#4A5568,stroke-width:2px;
    classDef styles fill:#F0FFF4,stroke:#38A169,stroke-width:2px;
    classDef public fill:#FFF5F7,stroke:#DD6B20,stroke-width:2px;
```
