# titaniummonkey/llm_hardware_calculator architecture

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

- Interactive diagram: https://gitdiagram.com/titaniummonkey/llm_hardware_calculator
- Repository: https://github.com/titaniummonkey/llm_hardware_calculator

## Overview

##### Project type and purpose
- This is a single-page web application (SPA) built with React, TypeScript, Tailwind CSS, and Vite.
- Purpose: Provide a VRAM and storage requirements calculator for large language models (LLMs), fetching metadata from the Hugging Face API or accepting manual parameters.

##### File structure
- Top-level files show it’s a frontend project (package.json, Vite configs, ESLint, Tailwind).
- src/ contains:
- App.tsx and main.tsx – application entry point and React root
- components/ – UI components (ModelInput, ManualInput, RequirementsDisplay, Calculator, etc.)
- utils/ – calculation and data-extraction logic
- types/ – TypeScript interfaces (model parameters)
- No server or backend folder: all processing runs in the browser, using fetch to call external services.

##### README for additional insights
- Confirms tech stack (React 18, TS, Tailwind, Vite) and key modules (Model Input, Manual Input, Calculation Engine, GPU Compatibility).
- Describes runtime behavior: real-time updates, API key support, multi-GPU logic, overhead calculations.

##### Main components and interactions
a. Frontend Application
- Browser (client) loading a static bundle served by Vite or any static host
- React App container (App.tsx)
- UI Components:
- ModelInput: handles Hugging Face URL/key input and calls Hugging Face REST API
- ManualInput: user-entered LLM parameters
- Calculator/Calculation Engine: core logic (in utils) computing VRAM/storage and GPU compatibility
- RequirementsDisplay & GpuCompatibilityList: render results
- ThemeProvider and layout / styling modules (Tailwind CSS)
b. External Services
- Hugging Face API – REST endpoint for model metadata
c. Data Flow
1. User enters a Hugging Face link & optional API key in ModelInput
2. App dispatches fetch() to Hugging Face API → returns model size, quantization, context length
3. or User enters parameters in ManualInput
4. Both paths pass data to Calculation Engine (utils/calculationUtils.ts)
5. Calculation Engine uses extractionUtils, formatUtils, types/model.ts to produce VRAM & storage numbers and candidate GPU lists
6. Results passed to RequirementsDisplay and GpuCompatibilityList for rendering

##### Architectural patterns & design principles
- Component-based UI (React) separating presentation (components) from logic (utils).
- Unidirectional data flow: Props/state flow down, callbacks bubble up.
- Single responsibility: each component has a clear domain (input vs. display).
- Layered separation:
- Presentation layer (components)
- Business logic layer (calculation/utils)
- API integration layer (fetch in ModelInput)

## Diagram (Mermaid)

```mermaid
graph TB
    %% External Client
    Browser["Browser (User)"]:::external

    %% React Initialization
    ReactRoot["React Root (src/main.tsx)"]:::ui
    AppContainer["React App Container (src/App.tsx)"]:::ui

    %% App Layout
    ThemeProvider["ThemeProvider (src/components/ThemeProvider.tsx)"]:::ui
    subgraph "Calculator Component"
        direction TB
        CalculatorUI["Calculator UI (src/components/Calculator.tsx)"]:::ui
        ModelInput["ModelInput Component (src/components/ModelInput.tsx)"]:::ui
        ManualInput["ManualInput Component (src/components/ManualInput.tsx)"]:::ui
        RequirementsDisplay["RequirementsDisplay (src/components/RequirementsDisplay.tsx)"]:::ui
        GpuCompatibilityList["GpuCompatibilityList (src/components/GpuCompatibilityList.tsx)"]:::ui
    end

    %% Logic Layer
    subgraph "Logic & Utilities"
        direction TB
        CalculationEngine["Calculation Engine (src/utils/calculationUtils.ts)"]:::logic
        ExtractionUtils["Extraction Utils (src/utils/extractionUtils.ts)"]:::logic
        FormatUtils["Formatting Utils (src/utils/formatUtils.ts)"]:::logic
        ModelTypes["Type Definitions (src/types/model.ts)"]:::types
    end

    %% External Service
    HuggingFaceAPI[(Hugging Face API)]:::external

    %% Data Flow
    Browser --> ReactRoot
    ReactRoot --> AppContainer
    AppContainer --> ThemeProvider
    ThemeProvider --> CalculatorUI

    CalculatorUI --> ModelInput
    CalculatorUI --> ManualInput
    CalculatorUI --> RequirementsDisplay
    CalculatorUI --> GpuCompatibilityList

    ModelInput -->|fetch metadata| HuggingFaceAPI
    ModelInput --> CalculationEngine
    ManualInput --> CalculationEngine

    CalculationEngine --> ExtractionUtils
    CalculationEngine --> FormatUtils
    CalculationEngine --> ModelTypes

    CalculationEngine --> RequirementsDisplay
    CalculationEngine --> GpuCompatibilityList

    %% Click Events
    click ReactRoot "https://github.com/titaniummonkey/llm_hardware_calculator/blob/main/src/main.tsx"
    click AppContainer "https://github.com/titaniummonkey/llm_hardware_calculator/blob/main/src/App.tsx"
    click ModelInput "https://github.com/titaniummonkey/llm_hardware_calculator/blob/main/src/components/ModelInput.tsx"
    click ManualInput "https://github.com/titaniummonkey/llm_hardware_calculator/blob/main/src/components/ManualInput.tsx"
    click CalculatorUI "https://github.com/titaniummonkey/llm_hardware_calculator/blob/main/src/components/Calculator.tsx"
    click RequirementsDisplay "https://github.com/titaniummonkey/llm_hardware_calculator/blob/main/src/components/RequirementsDisplay.tsx"
    click GpuCompatibilityList "https://github.com/titaniummonkey/llm_hardware_calculator/blob/main/src/components/GpuCompatibilityList.tsx"
    click ThemeProvider "https://github.com/titaniummonkey/llm_hardware_calculator/blob/main/src/components/ThemeProvider.tsx"
    click CalculationEngine "https://github.com/titaniummonkey/llm_hardware_calculator/blob/main/src/utils/calculationUtils.ts"
    click ExtractionUtils "https://github.com/titaniummonkey/llm_hardware_calculator/blob/main/src/utils/extractionUtils.ts"
    click FormatUtils "https://github.com/titaniummonkey/llm_hardware_calculator/blob/main/src/utils/formatUtils.ts"
    click ModelTypes "https://github.com/titaniummonkey/llm_hardware_calculator/blob/main/src/types/model.ts"

    %% Styles
    classDef ui fill:#D0E8FF,stroke:#558ED5;
    classDef logic fill:#D6F5D6,stroke:#3CA63C;
    classDef external fill:#FFE0B3,stroke:#F29300;
    classDef types fill:#ECECEC,stroke:#CCCCCC;
```
