# kanaries/pygwalker architecture

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

- Interactive diagram: https://gitdiagram.com/kanaries/pygwalker
- Repository: https://github.com/kanaries/pygwalker

## Overview

##### Main Components

a) Frontend Layer:
- React-based UI components (in app/src/components)
- Data visualization interface
- Modal components for code export, chart upload, and initialization
- UI components library (app/src/components/ui)

b) Backend Layer:
- Core Python package (pygwalker/)
- API interfaces for different environments
- Data parsing system
- Communication handlers
- Service modules

c) Integration Layer:
- Multiple platform connectors (Jupyter, Streamlit, Gradio, etc.)
- Communication protocols
- Template rendering system

##### Key Relationships to Highlight

**[Data Sources] → [Data Parsers] → [Core Engine] → [Communication Layer] → [Frontend UI]**

##### Detailed Component Breakdown

**Frontend (React App)**
- UI Components
- Chart Visualization
- Data Table
- Control Panels
- State Management
- Communication Handlers

**Backend (Python Package)**
- API Layer
- Jupyter Integration
- Streamlit Integration
- Other Platform Integrations
- Data Processing
- Multiple Parser Types
- Data Transformation
- Services
- Configuration
- Rendering
- Cloud Integration
- Communication
- Protocol Handlers
- Message Formatting

##### Important Architectural Patterns to Emphasize

- Plugin Architecture: Show how different data parsers can be plugged in
- Communication Pattern: Demonstrate bidirectional data flow between frontend and backend
- Integration Pattern: Show how different notebook environments are supported
- Service Pattern: Illustrate how various services interact with core components

##### Implementation Details

- Data Flow: Show how data moves from source through parsers to visualization
- State Management: Indicate how chart configurations are maintained
- Extension Points: Mark where new integrations can be added
- Service Integration: Show cloud service connections and update checking

##### Data Source Layer (Bottom)

- Component types and their visual representations
- Data flow indicators
- Integration points
- Configuration options

Keep the abstraction level high enough to be understandable but detailed enough to show the sophisticated architecture of PyGWalker's multiple integration capabilities and data processing features.

Remember to indicate the extensibility points where new parsers, integrations, or features can be added to the system.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Frontend
        UI["UI Components"]
        click UI "https://github.com/Kanaries/pygwalker/tree/main/app/src/components/"
        VIS["Data Visualization"]
        click VIS "https://github.com/Kanaries/pygwalker/tree/main/app/src/components/preview/"
        MOD["Modal Components"]
        click MOD "https://github.com/Kanaries/pygwalker/tree/main/app/src/components/codeExportModal/"
        UICOMP["UI Component Library"]
        click UICOMP "https://github.com/Kanaries/pygwalker/tree/main/app/src/components/ui/"
        STATE["State Management"]
        click STATE "https://github.com/Kanaries/pygwalker/tree/main/app/src/store/"
        
        UI --> VIS
        UI --> MOD
        UI --> UICOMP
        UI --> STATE
    end

    subgraph Integration
        JINT["Jupyter Integration"]
        click JINT "https://github.com/Kanaries/pygwalker/blob/main/pygwalker/api/jupyter.py"
        SINT["Streamlit Integration"]
        click SINT "https://github.com/Kanaries/pygwalker/blob/main/pygwalker/api/streamlit.py"
        GINT["Gradio Integration"]
        click GINT "https://github.com/Kanaries/pygwalker/blob/main/pygwalker/api/gradio.py"
        MINT["Marimo Integration"]
        click MINT "https://github.com/Kanaries/pygwalker/blob/main/pygwalker/api/marimo.py"
    end

    subgraph Communication
        COMM["Communication Handlers"]
        click COMM "https://github.com/Kanaries/pygwalker/tree/main/pygwalker/communications/"
        BPROT["Base Protocol"]
        click BPROT "https://github.com/Kanaries/pygwalker/blob/main/pygwalker/communications/base.py"
        SPROT["Streamlit Protocol"]
        click SPROT "https://github.com/Kanaries/pygwalker/blob/main/pygwalker/communications/streamlit_comm.py"
        GPROT["Gradio Protocol"]
        click GPROT "https://github.com/Kanaries/pygwalker/blob/main/pygwalker/communications/gradio_comm.py"

        BPROT --> SPROT
        BPROT --> GPROT
        COMM --> BPROT
    end

    subgraph Core
        ENGINE["Core Engine"]
        click ENGINE "https://github.com/Kanaries/pygwalker/blob/main/pygwalker/api/pygwalker.py"
        TEMP["Template System"]
        click TEMP "https://github.com/Kanaries/pygwalker/tree/main/pygwalker/templates/"
        
        subgraph Services
            CLOUD["Cloud Service"]
            click CLOUD "https://github.com/Kanaries/pygwalker/blob/main/pygwalker/services/cloud_service.py"
            RENDER["Rendering Service"]
            click RENDER "https://github.com/Kanaries/pygwalker/blob/main/pygwalker/services/render.py"
            CONFIG["Configuration"]
            click CONFIG "https://github.com/Kanaries/pygwalker/blob/main/pygwalker/services/config.py"
            TRACK["Tracking Service"]
            click TRACK "https://github.com/Kanaries/pygwalker/blob/main/pygwalker/services/track.py"
            UPDATE["Update Service"]
            click UPDATE "https://github.com/Kanaries/pygwalker/blob/main/pygwalker/services/check_update.py"
        end
        
        subgraph DataProcessing
            PPARSER["Pandas Parser"]
            click PPARSER "https://github.com/Kanaries/pygwalker/blob/main/pygwalker/data_parsers/pandas_parser.py"
            PLPARSER["Polars Parser"]
            click PLPARSER "https://github.com/Kanaries/pygwalker/blob/main/pygwalker/data_parsers/polars_parser.py"
            SPARSER["Spark Parser"]
            click SPARSER "https://github.com/Kanaries/pygwalker/blob/main/pygwalker/data_parsers/spark_parser.py"
            DBPARSER["Database Parser"]
            click DBPARSER "https://github.com/Kanaries/pygwalker/blob/main/pygwalker/data_parsers/database_parser.py"
        end
    end

    %% Connections between layers
    Frontend --> Integration
    Integration --> Communication
    Communication --> Core
    
    %% Service connections
    ENGINE --> Services
    ENGINE --> DataProcessing
    ENGINE --> TEMP

    classDef frontend fill:#2374ab
    classDef integration fill:#ff7f50
    classDef communication fill:#9370db
    classDef core fill:#2f4f4f
    classDef service fill:#228b22
    classDef dataprocessing fill:#daa520

    class UI,VIS,MOD,UICOMP,STATE frontend
    class JINT,SINT,GINT,MINT integration
    class COMM,BPROT,SPROT,GPROT communication
    class ENGINE,TEMP core
    class CLOUD,RENDER,CONFIG,TRACK,UPDATE service
    class PPARSER,PLPARSER,SPARSER,DBPARSER dataprocessing
```
