# grafana/explore-profiles architecture

> Architecture diagram of the GitHub repository grafana/explore-profiles, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/grafana/explore-profiles
- Repository: https://github.com/grafana/explore-profiles

## Overview

##### Main Components Architecture

a) Frontend Application Layer
- Sub-components:
- Pages Module (/src/pages)
- Shared Components (/src/shared)
- App Core (/src/app)

b) Integration Layer
- Plugin Registration (module.ts)
- Scene System Integration
- Data Source Integration

c) External Services
- Pyroscope Backend
- Grafana Core
- GitHub Integration (for code viewing)

##### Key Architectural Patterns to Highlight

a) Domain-Driven Design (DDD) Structure
- Domain logic (/domain folders)
- Infrastructure (/infrastructure folders)
- UI components (/ui folders)

b) Scene System Architecture
- Scene components hierarchy:
- SceneProfilesExplorer
- SceneByVariableRepeaterGrid
- SceneFlameGraph
- SceneFunctionDetailsPanel

##### Data Flow Patterns

a) Query Flow
- User Input → Query Builder → Data Source
- Data Source → Pyroscope Backend → Flame Graph Rendering

b) State Management Flow
- URL Parameters → Scene State → Component State
- User Interactions → Event System → State Updates

##### Integration Points

Connection points with:
a) Grafana Core
- Plugin API
- Data Source API
- Scene System

b) External Services
- GitHub API (for code viewing)
- Pyroscope API
- Faro Tracking

##### Component Details

a) Flame Graph Visualization
- Data Processing
- Rendering Pipeline
- Interaction Handlers

b) Query Builder
- State Machine
- Filter Management
- Auto-suggestion System

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Frontend["Frontend Application Layer"]
        Pages["Pages Module"]
        Shared["Shared Components"]
        AppCore["App Core"]
    end

    subgraph Integration["Integration Layer"]
        PluginReg["Plugin Registration"]
        SceneInt["Scene System Integration"]
        DataInt["Data Source Integration"]
    end

    subgraph External["External Services"]
        Pyroscope["Pyroscope Backend"]
        GrafanaCore["Grafana Core"]
        GitHub["GitHub Integration"]
    end

    subgraph Components["Key Components"]
        FlameGraph["Flame Graph Visualization"]
        QueryBuilder["Query Builder"]
        TimeSeriesAnalysis["Time Series Analysis"]
        ServiceMonitoring["Service Monitoring"]
    end

    subgraph SceneSystem["Scene Components"]
        ProfilesExplorer["SceneProfilesExplorer"]
        FlameGraphScene["SceneFlameGraph"]
        FunctionDetails["SceneFunctionDetailsPanel"]
        LabelTimeseries["SceneLabelValuesTimeseries"]
    end

    %% Relationships
    Pages --> SceneSystem
    Shared --> FlameGraph
    Shared --> QueryBuilder
    AppCore --> PluginReg
    PluginReg --> GrafanaCore
    SceneInt --> GrafanaCore
    DataInt --> Pyroscope
    FlameGraph --> Pyroscope
    ServiceMonitoring --> Pyroscope
    FunctionDetails --> GitHub
    TimeSeriesAnalysis --> Pyroscope
    QueryBuilder --> DataInt

    %% Click Events
    click Pages "https://github.com/grafana/explore-profiles/tree/main/src/pages"
    click Shared "https://github.com/grafana/explore-profiles/tree/main/src/shared/components"
    click AppCore "https://github.com/grafana/explore-profiles/tree/main/src/app"
    click PluginReg "https://github.com/grafana/explore-profiles/blob/main/src/module.ts"
    click ProfilesExplorer "https://github.com/grafana/explore-profiles/blob/main/src/pages/ProfilesExplorerView/components/SceneProfilesExplorer/SceneProfilesExplorer.tsx"
    click FlameGraphScene "https://github.com/grafana/explore-profiles/blob/main/src/pages/ProfilesExplorerView/components/SceneExploreServiceFlameGraph/SceneExploreServiceFlameGraph.tsx"
    click FlameGraph "https://github.com/grafana/explore-profiles/blob/main/src/shared/components/FlameGraph/FlameGraph.tsx"
    click QueryBuilder "https://github.com/grafana/explore-profiles/blob/main/src/shared/components/QueryBuilder/QueryBuilder.tsx"
    click GitHub "https://github.com/grafana/explore-profiles/tree/main/src/pages/ProfilesExplorerView/components/SceneExploreServiceFlameGraph/components/SceneFunctionDetailsPanel/components/GitHubContextProvider"
    click TimeSeriesAnalysis "https://github.com/grafana/explore-profiles/blob/main/src/pages/ProfilesExplorerView/infrastructure/timeseries/buildTimeSeriesQueryRunner.ts"
    click ServiceMonitoring "https://github.com/grafana/explore-profiles/tree/main/src/pages/ProfilesExplorerView/components/SceneExploreServiceFlameGraph"
    click DataInt "https://github.com/grafana/explore-profiles/blob/main/src/pages/ProfilesExplorerView/infrastructure/series/SeriesDataSource.ts"
    click LabelTimeseries "https://github.com/grafana/explore-profiles/tree/main/src/pages/ProfilesExplorerView/components/SceneLabelValuesTimeseries"

    %% Styling
    classDef frontend fill:#3572A5,color:#fff
    classDef integration fill:#2B7489,color:#fff
    classDef external fill:#E34C26,color:#fff
    classDef component fill:#563D7C,color:#fff
    classDef scene fill:#F1E05A,color:#000

    class Frontend,Pages,Shared,AppCore frontend
    class Integration,PluginReg,SceneInt,DataInt integration
    class External,Pyroscope,GrafanaCore,GitHub external
    class Components,FlameGraph,QueryBuilder,TimeSeriesAnalysis,ServiceMonitoring component
    class SceneSystem,ProfilesExplorer,FlameGraphScene,FunctionDetails,LabelTimeseries scene
```
