# daangn/autopprof architecture

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

- Interactive diagram: https://gitdiagram.com/daangn/autopprof
- Repository: https://github.com/daangn/autopprof

## Overview

##### Main Components

a. Core Components:
- Profiler Manager (autopprof.go)
- Resource Queryer System (queryer/)
- Profile Handler (profile.go)
- Reporting System (report/)

b. External Interfaces:
- Target Go Application
- Container Runtime (cgroup v1/v2)
- Reporting Destinations (e.g., Slack)

##### Specific Implementation Details

- Rectangles: Core components
- Hexagons: External systems

**[Target Go Application]**
- ↓
**[Autopprof Manager]**
- ↙     ↓     ↘
**[Queryer] [Profiler] [Reporter]**
- ↓         ↓         ↓
**[cgroup]  [Profiles]  [Slack]**

##### Component Details

a. Queryer System:
- CPU Usage Monitor (cgroupv1.go/cgroupv2.go)
- Memory Usage Monitor
- Runtime Stats Collector
- Queue Manager

b. Profile Handler:
- CPU Profiler
- Memory Profiler
- Threshold Controller

c. Reporter:
- Slack Integration
- Report Formatter
- Async Delivery System

##### Important Notes

- Monitoring components (blue)
- Profiling components (green)
- Reporting components (orange)
- External systems (gray)

- Labels for:
- Threshold values (CPU: 0.75, Memory: 0.75)
- Monitoring intervals
- Supported platforms (Linux-only)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Main Application
    App[Target Go Application]:::application

    %% Core Components
    Manager[Profiler Manager]:::core
    click Manager "https://github.com/daangn/autopprof/blob/main/autopprof.go"
    
    %% Monitoring Layer
    subgraph Monitoring
        Queryer[Resource Queryer]:::monitor
        click Queryer "https://github.com/daangn/autopprof/blob/main/queryer/queryer.go"
        CgroupV1[CPU Monitor V1]:::monitor
        click CgroupV1 "https://github.com/daangn/autopprof/blob/main/queryer/cgroupv1.go"
        CgroupV2[CPU Monitor V2]:::monitor
        click CgroupV2 "https://github.com/daangn/autopprof/blob/main/queryer/cgroupv2.go"
        Runtime[Runtime Stats]:::monitor
        click Runtime "https://github.com/daangn/autopprof/blob/main/queryer/runtime.go"
        Queue[Queue Manager]:::monitor
        click Queue "https://github.com/daangn/autopprof/blob/main/queryer/queue.go"
    end

    %% Profiling Layer
    subgraph Profiling
        ProfHandler[Profile Handler]:::profiler
        click ProfHandler "https://github.com/daangn/autopprof/blob/main/profile.go"
        CPUProf[CPU Profiler]:::profiler
        MemProf[Memory Profiler]:::profiler
        ThresholdCtrl[Threshold Controller]:::profiler
    end

    %% Reporting Layer
    subgraph Reporting
        Reporter[Report System]:::reporter
        click Reporter "https://github.com/daangn/autopprof/blob/main/report/report.go"
        Slack[Slack Integration]:::reporter
        click Slack "https://github.com/daangn/autopprof/blob/main/report/slack.go"
        Formatter[Report Formatter]:::reporter
        AsyncDelivery[Async Delivery]:::reporter
    end

    %% Error Handling
    ErrorSystem[Error Handler]:::error
    click ErrorSystem "https://github.com/daangn/autopprof/blob/main/error.go"
    QError[Queryer Error Handler]:::error
    click QError "https://github.com/daangn/autopprof/blob/main/queryer/error.go"

    %% Configuration
    Config[Configuration Options]:::config
    click Config "https://github.com/daangn/autopprof/blob/main/option.go"

    %% Example
    Example[Example Implementation]:::example
    click Example "https://github.com/daangn/autopprof/blob/main/examples/example.go"

    %% Relationships
    App --> Manager
    Manager --> Queryer
    Manager --> ProfHandler
    Manager --> Reporter
    
    Queryer --> CgroupV1
    Queryer --> CgroupV2
    Queryer --> Runtime
    Queryer --> Queue
    
    ProfHandler --> CPUProf
    ProfHandler --> MemProf
    ProfHandler --> ThresholdCtrl
    
    Reporter --> Slack
    Reporter --> Formatter
    Reporter --> AsyncDelivery
    
    Queryer -.-> QError
    Manager -.-> ErrorSystem

    %% Styling
    classDef application fill:#f9f,stroke:#333,stroke-width:2px
    classDef core fill:#bbf,stroke:#333,stroke-width:2px
    classDef monitor fill:#dfd,stroke:#333
    classDef profiler fill:#fdd,stroke:#333
    classDef reporter fill:#ffd,stroke:#333
    classDef error fill:#fbb,stroke:#333
    classDef config fill:#ddd,stroke:#333
    classDef example fill:#fff,stroke:#333,stroke-dasharray: 5 5

    %% Legend
    subgraph Legend
        L1[Application]:::application
        L2[Core Component]:::core
        L3[Monitoring]:::monitor
        L4[Profiling]:::profiler
        L5[Reporting]:::reporter
        L6[Error Handling]:::error
        L7[Configuration]:::config
        L8[Example]:::example
    end
```
