# kunalb/panopticon architecture

> Architecture diagram of the GitHub repository kunalb/panopticon, 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/kunalb/panopticon
- Repository: https://github.com/kunalb/panopticon

## Overview

##### Main Components

a) Core Components:
- Tracer Engine (panopticon/tracer.py)
- Probe System (panopticon/probe.py)
- Trace Generator (panopticon/trace.py)
- Post-processing System (panopticon/post.py)

b) Interface Components:
- CLI Interface (__main__.py)
- API Interface (exposed through __init__.py)

c) External Integration:
- Chrome Tracing (Catapult) Output
- Python Debugger Integration

**Top Layer: User Interfaces**

**Middle Layer: Core Processing**

**Bottom Layer: Output & Integration**

##### Component Relationships

a) Input Flow:
- User Code → CLI Interface / API Interface
- Interfaces → Probe System
- Probe System → Tracer Engine

b) Processing Flow:
- Tracer Engine → Trace Generator
- Trace Generator → Post-processing System

c) Output Flow:
- Post-processing System → Catapult-compatible Trace Files

##### Detailed Component Descriptions

Annotations for key components:

a) Probe System:
- Function/class instrumentation
- Multiple trace support
- Argument capture capability

b) Tracer Engine:
- Python debugger integration
- Frame execution tracking
- State management

c) Trace Generator:
- Catapult format compliance
- Flow event generation
- Timing capture

##### Additional Notes

- The non-intrusive nature of the tracing system
- The flexibility of probe placement
- The ability to handle both synchronous and asynchronous code
- The integration with Chrome's tracing infrastructure

Remember to include version information (currently Alpha) and note that the architecture supports future extensibility, as indicated by the ongoing development status in the README.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef interface fill:#90EE90,stroke:#333,stroke-width:2px
    classDef core fill:#87CEEB,stroke:#333,stroke-width:2px
    classDef external fill:#FFA500,stroke:#333,stroke-width:2px
    classDef async fill:#DDA0DD,stroke:#333,stroke-width:2px
    classDef testing fill:#FFE4B5,stroke:#333,stroke-width:2px
    classDef docs fill:#F0F8FF,stroke:#333,stroke-width:2px

    %% User Interfaces Layer
    subgraph Interfaces
        CLI["CLI Interface"]:::interface
        API["API Interface"]:::interface
        VM["Version Management"]:::interface
    end

    %% Core Processing Layer
    subgraph Core
        PS["Probe System"]:::core
        TE["Tracer Engine"]:::core
        TG["Trace Generator"]:::core
        PP["Post-processing System"]:::core
    end

    %% Async Support Layer
    subgraph AsyncSupport
        AS["Async Function Support"]:::async
        GF["Generator Functions"]:::async
        CO["Coroutines"]:::async
    end

    %% Testing Layer
    subgraph Testing
        PT["Probe Tests"]:::testing
        TT["Tracer Tests"]:::testing
        PPT["Post-processing Tests"]:::testing
        ATP["Async Test Probe"]:::testing
    end

    %% External Integration Layer
    subgraph Output
        CT["Chrome Tracing (Catapult)"]:::external
        PDB["Python Debugger"]:::external
    end

    %% Documentation
    DOC["Documentation"]:::docs

    %% Relationships
    CLI --> PS
    API --> PS
    PS --> TE
    TE --> TG
    TG --> PP
    PP --> CT
    TE --> PDB

    AS --> PS
    GF --> PS
    CO --> PS

    %% Click Events
    click CLI "https://github.com/kunalb/panopticon/blob/master/panopticon/__main__.py"
    click API "https://github.com/kunalb/panopticon/blob/master/panopticon/__init__.py"
    click VM "https://github.com/kunalb/panopticon/blob/master/panopticon/version.py"
    click PS "https://github.com/kunalb/panopticon/blob/master/panopticon/probe.py"
    click TE "https://github.com/kunalb/panopticon/blob/master/panopticon/tracer.py"
    click TG "https://github.com/kunalb/panopticon/blob/master/panopticon/trace.py"
    click PP "https://github.com/kunalb/panopticon/blob/master/panopticon/post.py"
    click ATP "https://github.com/kunalb/panopticon/blob/master/tests/test_async_probe.py"
    click PT "https://github.com/kunalb/panopticon/blob/master/tests/test_probe.py"
    click TT "https://github.com/kunalb/panopticon/blob/master/tests/test_tracer.py"
    click PPT "https://github.com/kunalb/panopticon/blob/master/tests/test_post.py"
    click DOC "https://github.com/kunalb/panopticon/tree/master/docs/panopticon/"

    %% Legend
    subgraph Legend
        L1["Interface Components"]:::interface
        L2["Core Components"]:::core
        L3["External Integration"]:::external
        L4["Async Components"]:::async
        L5["Testing Components"]:::testing
        L6["Documentation"]:::docs
    end
```
