# eionrobb/purple-teams architecture

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

## Overview

##### Main Components

a. Core Plugin Components (Central):
- Teams Connection Handler (teams_connection.c/h)
- Authentication Module (teams_login.c/h)
- Message Processing (teams_messages.c/h)
- Contact Management (teams_contacts.c/h)
- Teams Router (teams_trouter.c/h)
- Cards Handler (teams_cards.c/h)

b. Integration Layers:
- Purple/Pidgin Integration Layer (purplecompat.h)
- WebSocket Handler (purple-websocket.c/h)
- Purple 2.x Compatibility Layer (purple2compat directory)

c. External Systems:
- Microsoft Teams Services
- Pidgin Client
- Browser (for authentication)

- Microsoft    |     |    Plugin     |     |    Pidgin     |
- Teams      |<--->|  Components   |<--->|    Client     |
- Services    |     |               |     |               |

##### Key Relationships

- Authentication flow from Plugin → Browser → Teams Services
- Message flow: Teams Services → Message Processing → Pidgin Client
- Contact sync: Teams Services → Contact Management → Pidgin Client

##### Technical Details

- JSON processing (indicated by libjson-glib dependency)
- WebSocket communication channels
- Contact caching mechanism
- Message format conversion between Teams and Pidgin

##### Implementation Notes

- Keep the main plugin components in the center
- Related functionality (e.g., all contact-related components together)
- Clear boundaries between the plugin and external systems
- Error handling and retry mechanisms

##### Data transformation between Teams and Pidgin formats

This design should reflect the plugin's lightweight nature (as mentioned in the README's pros section about using less RAM) while showing all the essential components that enable it to function as a full-featured Teams client within Pidgin.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Define styles
    classDef external fill:#90EE90,stroke:#333,stroke-width:2px
    classDef core fill:#ADD8E6,stroke:#333,stroke-width:2px
    classDef auth fill:#FFE4B5,stroke:#333,stroke-width:2px
    classDef compat fill:#D3D3D3,stroke:#333,stroke-width:2px
    classDef websocket fill:#FFB6C1,stroke:#333,stroke-width:2px

    %% External Systems
    subgraph ExternalServices
        Teams["Microsoft Teams Services"]:::external
        Browser["Web Browser"]:::external
        Pidgin["Pidgin Client"]:::external
    end

    %% Core Plugin Components
    subgraph PluginCore
        MainInterface["Main Plugin Interface"]:::core
        ConnHandler["Teams Connection Handler"]:::core
        AuthModule["Authentication Module"]:::auth
        MsgProcess["Message Processing"]:::core
        ContactMgmt["Contact Management"]:::core
        TeamsRouter["Teams Router"]:::core
        CardsHandler["Cards Handler"]:::core
        Utils["Utility Functions"]:::core
    end

    %% Integration Layers
    subgraph IntegrationLayers
        PurpleCompat["Purple/Pidgin Integration Layer"]:::compat
        WSHandler["WebSocket Handler"]:::websocket
        Purple2["Purple 2.x Compatibility Layer"]:::compat
        HTTPComm["HTTP Communication Layer"]:::compat
        SocketMgmt["Socket Management"]:::compat
    end

    %% Relationships
    Teams <--> ConnHandler
    Teams <--> TeamsRouter
    Browser <--> AuthModule
    AuthModule --> Teams
    
    ConnHandler --> MsgProcess
    MsgProcess --> PurpleCompat
    ContactMgmt --> PurpleCompat
    TeamsRouter --> WSHandler
    
    MainInterface --> ConnHandler
    MainInterface --> AuthModule
    MainInterface --> MsgProcess
    MainInterface --> ContactMgmt
    
    WSHandler --> Purple2
    HTTPComm --> Purple2
    SocketMgmt --> Purple2
    
    Purple2 --> PurpleCompat
    PurpleCompat --> Pidgin

    %% Click events for component mapping
    click ConnHandler "https://github.com/EionRobb/purple-teams/blob/master/teams_connection.c"
    click AuthModule "https://github.com/EionRobb/purple-teams/blob/master/teams_login.c"
    click MsgProcess "https://github.com/EionRobb/purple-teams/blob/master/teams_messages.c"
    click ContactMgmt "https://github.com/EionRobb/purple-teams/blob/master/teams_contacts.c"
    click TeamsRouter "https://github.com/EionRobb/purple-teams/blob/master/teams_trouter.c"
    click CardsHandler "https://github.com/EionRobb/purple-teams/blob/master/teams_cards.c"
    click PurpleCompat "https://github.com/EionRobb/purple-teams/blob/master/purplecompat.h"
    click WSHandler "https://github.com/EionRobb/purple-teams/blob/master/purple-websocket.c"
    click Purple2 "https://github.com/EionRobb/purple-teams/tree/master/purple2compat/"
    click MainInterface "https://github.com/EionRobb/purple-teams/blob/master/libteams.c"
    click Utils "https://github.com/EionRobb/purple-teams/blob/master/teams_util.c"
    click HTTPComm "https://github.com/EionRobb/purple-teams/blob/master/purple2compat/http.c"
    click SocketMgmt "https://github.com/EionRobb/purple-teams/blob/master/purple2compat/purple-socket.c"

    %% Legend
    subgraph Legend
        L1["External Systems"]:::external
        L2["Core Components"]:::core
        L3["Authentication"]:::auth
        L4["Compatibility Layer"]:::compat
        L5["WebSocket Components"]:::websocket
    end
```
