# red5/red5-server architecture

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

- Interactive diagram: https://gitdiagram.com/red5/red5-server
- Repository: https://github.com/red5/red5-server

## Overview

##### Main Components Identification

The system should be divided into these major components:

a. Core Server Components:
- RTMP Protocol Stack
- Media Processing Engine
- Stream Management
- Shared Object System
- Security Layer
- Connection Management

b. Protocol Support Layer:
- RTMP
- RTMPT (Tunneled)
- RTMPS (Secure)
- RTMPE (Encrypted)

c. Media Handling:
- Video Processing (FLV, F4V, MP4, 3GP)
- Audio Processing (MP3, F4A, M4A, AAC)
- Recording System
- Streaming System

##### Architecture Layers

**[Client Layer]**
- ↕
**[Protocol Handler Layer]**
- ↕
**[Core Services Layer]**
- ↕
**[Media Processing Layer]**
- ↕
**[Storage Layer]**

##### Component Relationships

Key interactions:
- Client connections through protocol handlers
- Stream routing through the core
- Media processing pipeline
- Persistence and storage flows

##### Specific Implementation Details

Key classes/packages:
- org.red5.server.net.rtmp (RTMP handling)
- org.red5.server.stream (Stream processing)
- org.red5.server.so (Shared Objects)
- org.red5.server.api (Core APIs)

##### Integration Points

Highlight:
- WebSocket plugin interface
- RTSP plugin connection
- HLS plugin integration
- External application interfaces

Create distinct sections for:
a. Connection Handling:
**[Client] → [RTMPMinaIoHandler] → [RTMPHandler] → [StreamService]**

b. Media Processing:
**[MediaInput] → [Codec] → [StreamProcessor] → [MediaOutput]**

c. Service Layer:
**[SharedObjects] ↔ [ApplicationAdapter] ↔ [StreamManager]**

##### Additional Elements

Include:
- Configuration management
- Session handling
- Resource management
- Scheduling service

- Modularity of the system
- Plugin architecture
- Protocol abstraction
- Media processing pipeline
- Security integration points

This design should reflect Red5's architecture as a robust, extensible streaming media server with support for multiple protocols and media types, while showing the clear separation of concerns between different system components.

Remember to include version information (current version from README) and any relevant notes about scalability and deployment configurations.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Define styles
    classDef client fill:#f9f,stroke:#333,stroke-width:2px
    classDef protocol fill:#90EE90,stroke:#333,stroke-width:2px
    classDef core fill:#87CEEB,stroke:#333,stroke-width:2px
    classDef media fill:#FFD700,stroke:#333,stroke-width:2px
    classDef storage fill:#D3D3D3,stroke:#333,stroke-width:2px
    classDef security fill:#FF6B6B,stroke:#333,stroke-width:2px

    %% Client Layer
    subgraph ClientLayer
        Client["Client Applications"]:::client
    end

    %% Protocol Handler Layer
    subgraph ProtocolLayer
        RTMP["RTMP Handler"]:::protocol
        RTMPT["RTMPT Handler"]:::protocol
        RTMPS["RTMPS Handler"]:::protocol
        RTMPE["RTMPE Handler"]:::protocol
        WS["WebSocket Handler"]:::protocol
    end

    %% Core Services Layer
    subgraph CoreLayer
        ConnMgr["Connection Manager"]:::core
        StreamMgr["Stream Manager"]:::core
        SharedObj["Shared Object System"]:::core
        CoreServices["Core Services"]:::core
        Security["Security Layer"]:::security
    end

    %% Media Processing Layer
    subgraph MediaLayer
        VideoProc["Video Processing"]:::media
        AudioProc["Audio Processing"]:::media
        Codecs["Codecs"]:::media
        Formats["Media Formats"]:::media
    end

    %% Storage Layer
    subgraph StorageLayer
        Recording["Recording System"]:::storage
        Persistence["Persistence Layer"]:::storage
    end

    %% Relationships
    Client --> RTMP & RTMPT & RTMPS & RTMPE & WS
    RTMP & RTMPT & RTMPS & RTMPE & WS --> ConnMgr
    ConnMgr --> Security
    ConnMgr --> StreamMgr
    StreamMgr --> SharedObj
    StreamMgr --> CoreServices
    StreamMgr --> VideoProc & AudioProc
    VideoProc & AudioProc --> Codecs
    Codecs --> Formats
    Formats --> Recording
    CoreServices --> Persistence

    %% Click events
    click RTMP "https://github.com/Red5/red5-server/tree/master/common/src/main/java/org/red5/server/net/rtmp/"
    click RTMPT "https://github.com/Red5/red5-server/tree/master/server/src/main/java/org/red5/server/net/rtmpt/"
    click RTMPS "https://github.com/Red5/red5-server/tree/master/server/src/main/java/org/red5/server/net/rtmps/"
    click RTMPE "https://github.com/Red5/red5-server/tree/master/common/src/main/java/org/red5/server/net/rtmpe/"
    click StreamMgr "https://github.com/Red5/red5-server/tree/master/common/src/main/java/org/red5/server/stream/"
    click SharedObj "https://github.com/Red5/red5-server/tree/master/common/src/main/java/org/red5/server/so/"
    click Codecs "https://github.com/Red5/red5-server/tree/master/io/src/main/java/org/red5/codec/"
    click ConnMgr "https://github.com/Red5/red5-server/blob/master/common/src/main/java/org/red5/server/net/rtmp/RTMPConnManager.java"
    click Security "https://github.com/Red5/red5-server/tree/master/server/src/main/java/org/red5/server/security/"
    click CoreServices "https://github.com/Red5/red5-server/tree/master/common/src/main/java/org/red5/server/service/"
    click WS "https://github.com/Red5/red5-server/tree/master/server/src/main/java/org/red5/net/websocket/"
    click Formats "https://github.com/Red5/red5-server/tree/master/io/src/main/java/org/red5/io/flv/"

    %% Legend
    subgraph Legend
        Client_L["Client"]:::client
        Protocol_L["Protocol Handler"]:::protocol
        Core_L["Core Component"]:::core
        Media_L["Media Processing"]:::media
        Storage_L["Storage"]:::storage
        Security_L["Security"]:::security
    end
```
