# jlfwong/speedscope architecture

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

- Interactive diagram: https://gitdiagram.com/jlfwong/speedscope
- Repository: https://github.com/jlfwong/speedscope

## Overview

##### Main Components Identification

The system should be represented with these key components:

a) Frontend Application Core
- Profile Viewer Engine
- Rendering System (WebGL-based)
- State Management
- File Import System

b) Profile Parsers Layer
- Multiple Format Parsers
- Source Map Support
- Profile Data Transformers

c) Visualization Components
- Flamechart Renderer
- Time Order View
- Left Heavy View
- Sandwich View
- Search & Navigation System

##### Component Relationships

**[File Input] → [Import System] → [Profile Parsers] → [Profile Data Model]**
- ↓
**[User Interface] ← [State Management] ← [Visualization Engine]**
- ↓
**[View Components]**

##### Technical Implementation Details

Important technical aspects:

a) Core Technologies:
- Browser-based application (Web Platform)
- WebGL for rendering
- TypeScript/JavaScript
- Preact for UI components

b) Key Subsystems:
- GL Rendering Pipeline (/src/gl/*)
- Profile Import System (/src/import/*)
- Core Library (/src/lib/*)
- View System (/src/views/*)

##### Important Architectural Patterns

- Component-based architecture (views)
- Pipeline processing (import → parse → transform → render)
- State management system
- Plugin-style import system for different profile formats

##### Implementation Details

a) File Processing Pipeline:
**[Profile File] → [Format Detection] → [Specific Parser] → [Internal Format] → [Visualization]**

b) Rendering Pipeline:
**[Profile Data] → [WebGL Renderer] → [Frame Buffer] → [Screen]**

##### The real-time interactive nature of the visualization

This system design should reflect speedscope's nature as a sophisticated, client-side profile visualization tool with emphasis on performance and interactivity.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Browser Environment"
        FileInput["File Input System"]
        DragDrop["Drag & Drop Interface"]
    end

    subgraph "Core Application"
        FrontendCore["Frontend Application Core"]:::core
        StateManagement["State Management"]:::state
        click FrontendCore "https://github.com/jlfwong/speedscope/blob/main/src/speedscope.tsx"
        click StateManagement "https://github.com/jlfwong/speedscope/tree/main/src/app-state"
    end

    subgraph "Profile Processing"
        ImportSystem["Import System"]
        Parsers["Profile Parsers"]:::parser
        ProfileCore["Profile Core"]:::core
        click Parsers "https://github.com/jlfwong/speedscope/tree/main/src/import"
        click ProfileCore "https://github.com/jlfwong/speedscope/blob/main/src/lib/profile.ts"
    end

    subgraph "Rendering Engine"
        GLRenderer["WebGL Renderer"]:::renderer
        CanvasContext["Canvas Context"]:::renderer
        GraphicsCore["Graphics Core"]:::renderer
        click GLRenderer "https://github.com/jlfwong/speedscope/blob/main/src/gl/flamechart-renderer.ts"
        click CanvasContext "https://github.com/jlfwong/speedscope/blob/main/src/gl/canvas-context.ts"
        click GraphicsCore "https://github.com/jlfwong/speedscope/blob/main/src/gl/graphics.ts"
    end

    subgraph "Visualization Layer"
        FlamechartView["Flamechart View"]:::view
        SandwichView["Sandwich View"]:::view
        SearchView["Search View"]:::view
        ProfileTableView["Profile Table View"]:::view
        click FlamechartView "https://github.com/jlfwong/speedscope/blob/main/src/views/flamechart-view.tsx"
        click SandwichView "https://github.com/jlfwong/speedscope/blob/main/src/views/sandwich-view.tsx"
        click SearchView "https://github.com/jlfwong/speedscope/blob/main/src/views/search-view.tsx"
        click ProfileTableView "https://github.com/jlfwong/speedscope/blob/main/src/views/profile-table-view.tsx"
    end

    subgraph "Theme System"
        ThemeCore["Theme Core"]:::theme
        LightTheme["Light Theme"]:::theme
        DarkTheme["Dark Theme"]:::theme
        click ThemeCore "https://github.com/jlfwong/speedscope/blob/main/src/views/themes/theme.tsx"
        click LightTheme "https://github.com/jlfwong/speedscope/blob/main/src/views/themes/light-theme.ts"
        click DarkTheme "https://github.com/jlfwong/speedscope/blob/main/src/views/themes/dark-theme.ts"
    end

    FileInput --> DragDrop
    DragDrop --> ImportSystem
    ImportSystem --> Parsers
    Parsers --> ProfileCore
    ProfileCore --> StateManagement
    StateManagement --> FrontendCore

    FrontendCore --> GLRenderer
    GLRenderer --> CanvasContext
    CanvasContext --> GraphicsCore

    StateManagement --> FlamechartView
    StateManagement --> SandwichView
    StateManagement --> SearchView
    StateManagement --> ProfileTableView

    ThemeCore --> FrontendCore
    LightTheme --> ThemeCore
    DarkTheme --> ThemeCore

    classDef core fill:#2374ab
    classDef state fill:#7d3c98
    classDef parser fill:#27ae60
    classDef renderer fill:#e67e22
    classDef view fill:#f1c40f
    classDef theme fill:#95a5a6

    %% Legend
    subgraph Legend
        CoreComponent["Core Components"]:::core
        StateComponent["State Management"]:::state
        ParserComponent["Parsers"]:::parser
        RenderComponent["Rendering Components"]:::renderer
        ViewComponent["View Components"]:::view
        ThemeComponent["Theme Components"]:::theme
    end
```
