# pterodactyl/wings architecture

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

- Interactive diagram: https://gitdiagram.com/pterodactyl/wings
- Repository: https://github.com/pterodactyl/wings

## Overview

##### Main Components

a. Core Components:
- HTTP API Server (router package)
- SFTP Server (sftp package)
- Docker Environment Manager (environment/docker package)
- Server Manager (server package)
- File System Handler (server/filesystem package)
- Backup System (server/backup package)
- Transfer System (server/transfer package)
- WebSocket Handler (router/websocket package)

b. External Integrations:
- Docker Engine
- Panel Communication Interface
- S3 Storage (for backups)
- Local File System

##### Component Relationships

- ┌─────────────────┐
- Panel API      │
- ┬────────┘

- ▼
**┌─────────────┐                    ┌──────────────┐**
- SFTP       │◄───────────────────┤              │
- Server     │                    │              │
- ┘                    │    Wings     │
- Core      │
**┌─────────────┐                    │              │──────────┐**
- WebSocket  │◄───────────────────┤              │          │
- Server     │                    └──────┬───────┘          │
- ┘                           │                  │

- ▼                  ▼
- ┌─────────────────┐  ┌────────────────┐
- Docker Engine   │  │ File System    │
- ┘  └────────────────┘

##### Important Architectural Elements to Highlight

a. Service Layer:
- HTTP API endpoints (router package)
- WebSocket handlers for real-time communication
- SFTP server for file management

b. Core Processing:
- Server management and lifecycle control
- Docker container orchestration
- Resource monitoring and statistics collection

c. Storage Layer:
- Local filesystem operations
- Backup management (local and S3)
- Transfer system for server migrations

##### Implementation Details

- The modular nature of the system (separate packages for different functionalities)
- The event-driven architecture (events package)
- The separation of concerns between server management and container orchestration
- The multiple communication protocols (HTTP, WebSocket, SFTP)

##### Infrastructure Layer (Docker Engine, S3)

Remember to maintain a balance between showing enough detail to understand the system's architecture while keeping it clean and readable. Focus on the major components and their interactions rather than implementation details.

## Diagram (Mermaid)

```mermaid
%%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#007bff', 'primaryTextColor': '#fff', 'primaryBorderColor': '#007bff', 'lineColor': '#555', 'secondaryColor': '#6c757d', 'tertiaryColor': '#28a745'}}}%%

flowchart TB
    subgraph External["External Layer"]
        Panel["Panel API"]:::external
        S3["S3 Storage"]:::external
        DockerEngine["Docker Engine"]:::external
    end

    subgraph Interface["Interface Layer"]
        HTTP["HTTP API Server"]:::interface
        SFTP["SFTP Server"]:::interface
        WS["WebSocket Handler"]:::interface
        PanelComm["Panel Communication"]:::interface
    end

    subgraph Core["Core Processing Layer"]
        Config["Configuration Manager"]:::core
        ServerMgr["Server Manager"]:::core
        DockerMgr["Docker Environment Manager"]:::core
        Events["Event System"]:::core
    end

    subgraph Storage["Storage Layer"]
        FS["File System Handler"]:::storage
        Backup["Backup System"]:::storage
        Transfer["Transfer System"]:::storage
        LocalFS["Local File System"]:::storage
    end

    Panel --> PanelComm
    PanelComm --> HTTP
    HTTP --> ServerMgr
    SFTP --> FS
    WS --> ServerMgr
    
    ServerMgr --> DockerMgr
    ServerMgr --> Events
    DockerMgr --> DockerEngine
    
    Events --> Backup
    Events --> Transfer
    
    Backup --> S3
    Backup --> LocalFS
    Transfer --> LocalFS
    FS --> LocalFS

    %% Click Events
    click HTTP "https://github.com/pterodactyl/wings/blob/develop/router/router.go"
    click SFTP "https://github.com/pterodactyl/wings/blob/develop/sftp/server.go"
    click DockerMgr "https://github.com/pterodactyl/wings/blob/develop/environment/docker/environment.go"
    click ServerMgr "https://github.com/pterodactyl/wings/blob/develop/server/server.go"
    click FS "https://github.com/pterodactyl/wings/blob/develop/server/filesystem/filesystem.go"
    click Backup "https://github.com/pterodactyl/wings/blob/develop/server/backup/backup.go"
    click Transfer "https://github.com/pterodactyl/wings/blob/develop/server/transfer/transfer.go"
    click WS "https://github.com/pterodactyl/wings/blob/develop/router/websocket/websocket.go"
    click Config "https://github.com/pterodactyl/wings/blob/develop/config/config.go"
    click Events "https://github.com/pterodactyl/wings/blob/develop/events/events.go"
    click PanelComm "https://github.com/pterodactyl/wings/blob/develop/remote/http.go"
    click DockerEngine "https://github.com/pterodactyl/wings/blob/develop/environment/docker/api.go"
    click S3 "https://github.com/pterodactyl/wings/blob/develop/server/backup/backup_s3.go"
    click LocalFS "https://github.com/pterodactyl/wings/blob/develop/internal/ufs/filesystem.go"

    %% Styling
    classDef external fill:#28a745,stroke:#28a745,color:white
    classDef interface fill:#fd7e14,stroke:#fd7e14,color:white
    classDef core fill:#007bff,stroke:#007bff,color:white
    classDef storage fill:#6c757d,stroke:#6c757d,color:white

    %% Legend
    subgraph Legend
        E1["External Service"]:::external
        I1["Interface Component"]:::interface
        C1["Core Component"]:::core
        S1["Storage Component"]:::storage
    end
```
