Technical Architecture of the Emby Platform
1. Emby Server Architecture
1.1 Basic Server Components
Emby Server is built as a multi-tier application with the following main layers:
- Backend Service - Windows Service or Linux Daemon running in background
- Web Server - HTTP server managing client requests
- Database Layer - Database management layer
- API Layer - REST API for communication with clients
- Media Processing - Media processing and transcoding engine
1.2 Technologies and Programming Languages
Emby is developed primarily in C# and .NET, with components in:
- C# .NET for main business logic
- SQLite for embedded databases
- ASP.NET for web server and REST APIs
- FFmpeg for media processing and transcoding
- JavaScript/HTML/CSS for web interface
2. Database System
2.1 Database Structure
Emby uses multiple specialized SQLite databases:
library.db - Main database containing:
Users Table - users and authentication
Items Table - metadata for all media elements
UserData Table - preferences and playback progress
Images Table - information about associated images
activity.db - Activity logs and statistics devices.db - Records of connected devices channels.db - Data about channels and plugins
2.2 Main Table Schemes
CREATE TABLE Users (
Id GUID PRIMARY KEY,
Name NVARCHAR(255) NOT NULL,
PasswordHash NVARCHAR(255),
Salt NVARCHAR(255),
IsAdministrator BIT,
IsHidden BIT,
LastLoginDate DATETIME,
LastActivityDate DATETIME
);CREATE TABLE TypedBaseItems (
Id GUID PRIMARY KEY,
Type NVARCHAR(255),
Path NVARCHAR(MAX),
Name NVARCHAR(255),
Overview TEXT,
ProductionYear INTEGER,
PremiereDate DATETIME,
DateCreated DATETIME,
DateModified DATETIME
);CREATE TABLE UserData (
Id INTEGER PRIMARY KEY AUTOINCREMENT,
UserId GUID,
ItemId GUID,
PlayCount INTEGER,
IsFavorite BIT,
PlaybackPositionTicks BIGINT,
LastPlayedDate DATETIME
);3. Web Server and REST API
3.1 Web Server Architecture
Emby incorporates an ASP.NET web server that:
- Manages HTTP/HTTPS requests
- Serves web interface and APIs
- Manages authentication and authorization
- Processes media streams
3.2 Main API Endpoints
/api/users - User management
/api/items - Operations on media elements
/api/sessions - Playback session management
/api/library - Library operations
/api/plugins - Plugin management
3.3 Authentication System
Emby uses token-based authentication:
- Access Token is generated at login
- Token is included in request headers
- Each user can have multiple tokens for different devices
- Tokens expire after a configured period
4. Media Processing System
4.1 Transcoding Engine Architecture
Emby integrates FFmpeg for:
- Real-time transcoding for device compatibility
- Metadata extraction from media files
- Thumbnail and chapter generation
- Audio and subtitle processing
4.2 Transcoding Pipeline
Media processing flow:
- Detection of client device capabilities
- Analysis of codecs and media containers
- Source media decoding
- Processing (rescale, audio transcode, subtitle burning)
- Encoding in compatible format
- Streaming to client
5. Plugin and Extensions System
5.1 Plugin Architecture
Emby supports plugins developed in C# that can:
- Add new metadata providers
- Extend web interface with new functionalities
- Add additional media formats
- Integrate with external services
5.2 Plugin Structure
A typical Emby plugin contains:
- .NET DLL assembly with business logic
- Configuration files
- Web resources (JavaScript, CSS, images)
- Manifest with plugin metadata
6. Network and Communication System
6.1 Communication Protocol
Emby uses multiple protocols:
- HTTP/HTTPS for API and web interface
- WebSockets for real-time notifications
- UDP for discoverability on local network
- RTSP/HTTP for media streaming
6.2 Automatic Network Discovery
The service uses SSDP (Simple Service Discovery Protocol) for:
- Announcing server presence on network
- Automatic discovery by clients
- Quick connection configuration
7. Cache and Performance System
7.1 Cache Layer
Emby implements multiple cache levels:
- Image cache (posters, backdrops)
- Metadata cache for search performance
- API result cache
- Web resource cache
7.2 Performance Optimizations
Techniques used for performance:
- Aggressive indexing in databases
- Pagination for large results
- Compression for data transfer
- Load balancing for multiple requests
8. Security System
8.1 Implemented Security Measures
Emby includes:
- Token-based authentication
- Role-based authorization
- Input validation to prevent attacks
- Extensive logging for audit
- Options for HTTPS and certification
9. Server Initialization Process
9.1 Startup Sequence
At startup, Emby Server executes:
- Configuration initialization from XML files
- Connection to SQLite databases
- Loading installed plugins
- Scanning configured media libraries
- Starting web server and network services
- Announcing presence on local network