# buda9/moodle-local_chatwoot architecture

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

## Overview

##### Project Type Analysis
This is a Moodle local plugin that integrates an external service (Chatwoot) into the Moodle Learning Management System (LMS). It's an integration/extension project that connects two separate systems.

##### Key Components

A. Core Components:
- Moodle LMS (Host System)
- Local Chatwoot Plugin
- External Chatwoot Service
- User Interface (Chat Widget)

B. Plugin Internal Structure:
- Settings Management
- Database Layer
- Privacy Provider
- Helper Functions
- Language Support

**[External Layer]**
- Chatwoot Service

**[Integration Layer]**
- Local Chatwoot Plugin

**[Host Layer]**
- Moodle LMS

- Blue: Moodle Core Components
- Green: Local Plugin Components
- Orange: External Chatwoot Service
- Gray: Database Elements

##### Specific modules (based on file structure)
- [Plugin Core]
- Settings Module (settings.php)
- Database Handler (db/*.php)
- Privacy Provider (classes/privacy/provider.php)
- Helper Functions (classes/helper.php)

##### Data Flow Representation
- User data flow (name, email, phone)
- Configuration data path
- Chat widget embedding process

##### Important Elements to Highlight

a. Configuration Flow:
- Moodle Admin UI → Plugin Settings → Chatwoot Configuration

b. Runtime Flow:
- User → Moodle Page → Embedded Widget → Chatwoot Service

c. Data Collection Flow:
- Moodle User Data → Plugin Helper → Chatwoot Widget

##### Technical Details

- Database tables and their relationships
- Integration points with Moodle core
- Configuration parameters (websiteToken, baseUrl)
- Privacy API implementation
- Language file usage

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph External["External Layer"]
        CW[Chatwoot Service]:::external
    end

    subgraph Integration["Integration Layer"]
        LP["Local Chatwoot Plugin"]:::plugin
        click LP "https://github.com/Buda9/moodle-local_chatwoot/tree/main//"
        
        subgraph Core["Plugin Core Components"]
            LIB["Main Plugin Library"]:::core
            click LIB "https://github.com/Buda9/moodle-local_chatwoot/blob/main/lib.php"
            VER["Version Info"]:::core
            click VER "https://github.com/Buda9/moodle-local_chatwoot/blob/main/version.php"
            SET["Settings Management"]:::core
            click SET "https://github.com/Buda9/moodle-local_chatwoot/blob/main/settings.php"
            HELP["Helper Functions"]:::core
            click HELP "https://github.com/Buda9/moodle-local_chatwoot/blob/main/classes/helper.php"
        end

        subgraph DB["Database Layer"]
            INST["Installation"]:::db
            click INST "https://github.com/Buda9/moodle-local_chatwoot/blob/main/db/install.php"
            UNINST["Uninstallation"]:::db
            click UNINST "https://github.com/Buda9/moodle-local_chatwoot/blob/main/db/uninstall.php"
            UPG["Upgrade Handler"]:::db
            click UPG "https://github.com/Buda9/moodle-local_chatwoot/blob/main/db/upgrade.php"
            UPGL["Upgrade Library"]:::db
            click UPGL "https://github.com/Buda9/moodle-local_chatwoot/blob/main/db/upgradelib.php"
        end

        subgraph Support["Support Components"]
            PRIV["Privacy Provider"]:::support
            click PRIV "https://github.com/Buda9/moodle-local_chatwoot/blob/main/classes/privacy/provider.php"
            LANG["Language Support"]:::support
            click LANG "https://github.com/Buda9/moodle-local_chatwoot/blob/main/lang/en/local_chatwoot.php"
        end
    end

    subgraph Host["Host Layer"]
        ML[Moodle LMS]:::host
        MAU["Moodle Admin UI"]:::host
        MUI["Moodle User Interface"]:::host
        MUD["Moodle User Data"]:::host
    end

    %% Connections
    CW <-.->|Chat Communication| LP
    LP -->|Embeds Widget| MUI
    MAU -->|Configures| SET
    SET -.->|Stores Settings| DB
    MUD -->|User Info| HELP
    HELP -.->|Formats Data| LP
    LP -.->|Privacy Compliance| PRIV
    LANG -.->|Localization| LP
    LIB -->|Core Functions| LP
    VER -->|Version Control| LP
    
    %% Styles
    classDef external fill:#FFA500,stroke:#FF8C00
    classDef plugin fill:#90EE90,stroke:#32CD32
    classDef core fill:#ADD8E6,stroke:#4682B4
    classDef db fill:#D3D3D3,stroke:#A9A9A9
    classDef support fill:#DDA0DD,stroke:#9370DB
    classDef host fill:#87CEEB,stroke:#4169E1

    %% Legend
    subgraph Legend
        E1[External Service]:::external
        P1[Plugin Components]:::plugin
        C1[Core Components]:::core
        D1[Database Elements]:::db
        S1[Support Components]:::support
        H1[Host System]:::host
    end
```
