# disgoorg/disgo architecture

> Architecture diagram of the GitHub repository disgoorg/disgo, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/disgoorg/disgo
- Repository: https://github.com/disgoorg/disgo

## Overview

##### Main Components Identification
The system should be divided into these major components:

a) Core Components:
- Gateway Service (gateway/*)
- REST API Client (rest/*)
- Bot Client (bot/*)
- Cache System (cache/*)
- Event System (events/*)
- Handler System (handler/*)
- Voice System (voice/*)
- OAuth2 System (oauth2/*)
- Webhook System (webhook/*)
- HTTP Server (httpserver/*)
- Sharding Manager (sharding/*)

##### Component Relationships

**Client (Core)**
- Gateway Service
- Sharding Manager
- Event System
- REST API Client
- Rate Limiter
- Cache System
- Handler System
- Command Router
- Component Handler
- Middleware
- Voice System
- OAuth2 System
- Webhook System

##### Specific Design Elements

- Rectangles: Core services (Gateway, REST, Cache)
- Hexagons: Managers (Sharding, Event)
- Diamonds: Decision points (Handler Router)

- Blue: Core components
- Green: External communication (Gateway, REST)
- Yellow: Processing systems (Handlers, Cache)
- Purple: Authentication/Security (OAuth2)
- Red: Critical systems (Rate Limiters)

##### Flow Directions

- Circular flow between Cache and other components

##### Important Details

a) External Interfaces:
- Discord Gateway Connection
- REST API Endpoints
- Voice Connections
- Webhook Endpoints
- OAuth2 Flow

b) Internal Systems:
- Rate Limiting Mechanisms
- Event Dispatch System
- Caching Policies
- Sharding Logic

##### Technical Specifications

Technical details such as:
- Supported Gateway Intents
- Rate Limit Configurations
- Cache Policies
- Supported Discord Features

Remember to:
- Both synchronous and asynchronous communication paths
- Event-driven architecture
- Error handling and recovery paths
- Integration points with Discord's various APIs

This design should reflect DisGo's architecture as a highly modular, feature-rich Discord API wrapper with emphasis on its core features: Gateway communication, REST API handling, event management, and various Discord-specific functionalities.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Core
        Client["Bot Client"]
    end

    subgraph Communication
        Gateway["Gateway Service"]
        REST["REST API Client"]
        RateLimiter["Rate Limiter"]
        HTTP["HTTP Server"]
    end

    subgraph Management
        ShardMgr["Sharding Manager"]
        EventMgr["Event Manager"]
        VoiceMgr["Voice System"]
    end

    subgraph Handlers
        HandlerSys["Handler System"]
        Router["Command Router"]
        CompHandler["Component Handler"]
        Middleware["Middleware System"]
    end

    subgraph Storage
        Cache[(Cache System)]
    end

    subgraph Security
        OAuth["OAuth2 System"]
        Webhook["Webhook System"]
    end

    %% Core Relationships
    Client --> Gateway
    Client --> REST
    Client --> HandlerSys
    Client --> Cache
    
    %% Communication Layer
    Gateway --> ShardMgr
    Gateway --> EventMgr
    REST --> RateLimiter
    
    %% Handler System
    HandlerSys --> Router
    HandlerSys --> CompHandler
    HandlerSys --> Middleware
    HandlerSys --> EventMgr
    
    %% Management Systems
    VoiceMgr --> Gateway
    EventMgr --> Cache
    
    %% Security Systems
    OAuth --> REST
    Webhook --> HTTP
    
    %% Cache Relationships
    Cache --> HandlerSys
    Cache --> Gateway
    Cache --> REST

    %% Click Events
    click Gateway "https://github.com/disgoorg/disgo/blob/master/gateway/gateway.go"
    click REST "https://github.com/disgoorg/disgo/blob/master/rest/rest_client.go"
    click Client "https://github.com/disgoorg/disgo/blob/master/bot/client.go"
    click Cache "https://github.com/disgoorg/disgo/blob/master/cache/cache.go"
    click HandlerSys "https://github.com/disgoorg/disgo/blob/master/handler/handler.go"
    click VoiceMgr "https://github.com/disgoorg/disgo/blob/master/voice/manager.go"
    click OAuth "https://github.com/disgoorg/disgo/blob/master/oauth2/client.go"
    click Webhook "https://github.com/disgoorg/disgo/blob/master/webhook/webhook_client.go"
    click HTTP "https://github.com/disgoorg/disgo/blob/master/httpserver/server.go"
    click ShardMgr "https://github.com/disgoorg/disgo/blob/master/sharding/shard_manager.go"
    click RateLimiter "https://github.com/disgoorg/disgo/blob/master/rest/rest_rate_limiter.go"
    click EventMgr "https://github.com/disgoorg/disgo/blob/master/bot/event_manager.go"
    click Router "https://github.com/disgoorg/disgo/blob/master/handler/router.go"
    click CompHandler "https://github.com/disgoorg/disgo/blob/master/handler/component.go"
    click Middleware "https://github.com/disgoorg/disgo/blob/master/handler/middleware/middleware.go"

    classDef core fill:#2b7ce9,stroke:#2b7ce9,color:white
    classDef communication fill:#85d075,stroke:#85d075,color:black
    classDef management fill:#ffd700,stroke:#ffd700,color:black
    classDef handler fill:#ff9900,stroke:#ff9900,color:black
    classDef storage fill:#c0c0c0,stroke:#c0c0c0,color:black
    classDef security fill:#9370db,stroke:#9370db,color:white
    
    class Client core
    class Gateway,REST,RateLimiter,HTTP communication
    class ShardMgr,EventMgr,VoiceMgr management
    class HandlerSys,Router,CompHandler,Middleware handler
    class Cache storage
    class OAuth,Webhook security
```
