# couchpotato/couchpotatoserver architecture

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

## Overview

##### Main Components Identification

The system should be divided into these major components:

a. Core System
- Media Management Core (/core/media)
- Plugin System (/core/plugins)
- Database Layer (/core/database.py)
- API Layer (/api.py)
- Event System (/core/event.py)

b. Media Providers
- Torrent Providers (/core/media/_base/providers/torrent)
- NZB Providers (/core/media/_base/providers/nzb)
- Metadata Providers (/core/media/_base/providers/metadata)

c. Downloaders
- Multiple Download Clients (/core/downloaders)
- Download Management System (/core/_base/downloader)

d. Notification System
- Various Notification Providers (/core/notifications)

##### Component Relationships

a. Data Flow
**Web UI <-> API Layer <-> Core System <-> Database**

- v
**Media Providers <-> Search System <-> Download Manager**

- v
- Download Clients

b. Event System Connections
**Core System -> Event Bus -> Notification System**
- > Plugins
- > Media Providers

##### Detailed Component Breakdown

For each major component, include:

a. Core System
- Movie Library Manager
- Quality Profiles
- Scheduler
- Update System

b. Media Providers Section
- Torrent Sites (TPB, YTS, etc.)
- NZB Sites (Newznab, etc.)
- Metadata Sources (TMDB, OMDB)

c. Downloader Section
- Torrent Clients (Transmission, uTorrent, etc.)
- NZB Clients (SABnzbd, NZBGet)
- Download Queue Manager

##### Integration Points

External service connections:
- Movie Information APIs
- Torrent Trackers
- NZB Indexers
- Media Players/Servers
- Notification Services

##### Key Workflows

Essential flows:
**Movie Search -> Provider Check -> Download Selection -> Queue Management -> File Processing**
**Movie Addition -> Wanted List -> Automated Search -> Download -> Library Update**

##### Technical Details

Annotations for:
- Python-based architecture
- Web interface (Tornado framework)
- SQLite database
- RESTful API endpoints
- Background task scheduling

##### The extensive integration capabilities with external services

- Clear hierarchical layout
- Logical grouping of related components
- Detailed but uncluttered connection lines

This system design should capture both the high-level architecture and the detailed component interactions while maintaining clarity and readability.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Core Components
    subgraph Core
        CoreServer["Core Server"]:::core
        DB[(Database)]:::storage
        PluginMgr["Plugin Manager"]:::core
        EventSys["Event System"]:::core
        Scheduler["Scheduler"]:::core
    end

    %% Web and API Layer
    subgraph Interface
        WebUI["Web Interface"]:::ui
        Auth["Auth Manager"]:::security
        API["API Layer"]:::api
    end

    %% Media Processing
    subgraph MediaProcessing
        Scanner["Scanner"]:::media
        Renamer["Renamer 🐛"]:::media
        Quality["Quality Control"]:::media
    end

    %% Provider System
    subgraph Providers
        NZB["NZB Providers 🐛"]:::provider
        Torrent["Torrent Providers"]:::provider
        Meta["Metadata Providers"]:::provider
    end

    %% Download Management
    subgraph Downloaders
        SAB["SABnzbd"]:::downloader
        TorrentClient["Torrent Clients 🐛"]:::downloader
        Blackhole["Blackhole"]:::downloader
    end

    %% Notification System
    NotifSystem["Notification System"]:::notification

    %% File System
    FileSystem["File System Access 🐛"]:::system

    %% Relationships
    WebUI --> Auth
    Auth --> API
    API --> CoreServer
    CoreServer --> DB
    CoreServer --> PluginMgr
    CoreServer --> EventSys
    CoreServer --> Scheduler
    
    Scheduler --> |"Search Tasks 🐛"| Providers
    Providers --> Downloaders
    Downloaders --> FileSystem
    FileSystem --> MediaProcessing
    
    CoreServer --> NotifSystem
    EventSys --> NotifSystem

    %% Styling
    classDef core fill:#2374ab
    classDef storage fill:#457b9d
    classDef ui fill:#a8dadc
    classDef api fill:#48cae4
    classDef security fill:#ffd60a
    classDef media fill:#fb8500
    classDef provider fill:#219ebc
    classDef downloader fill:#023047
    classDef notification fill:#ffb703
    classDef system fill:#8ecae6

    %% Click events
    click CoreServer "https://github.com/CouchPotato/CouchPotatoServer/blob/master/couchpotato/core/_base/_core.py"
    click DB "https://github.com/CouchPotato/CouchPotatoServer/blob/master/couchpotato/core/database.py"
    click API "https://github.com/CouchPotato/CouchPotatoServer/blob/master/couchpotato/api.py"
    click EventSys "https://github.com/CouchPotato/CouchPotatoServer/blob/master/couchpotato/core/event.py"
    click Scheduler "https://github.com/CouchPotato/CouchPotatoServer/blob/master/couchpotato/core/_base/scheduler.py"
    click Scanner "https://github.com/CouchPotato/CouchPotatoServer/blob/master/couchpotato/core/plugins/scanner.py"
    click Renamer "https://github.com/CouchPotato/CouchPotatoServer/blob/master/couchpotato/core/plugins/renamer.py"
    click Quality "https://github.com/CouchPotato/CouchPotatoServer/tree/master/couchpotato/core/plugins/quality/"
    click NZB "https://github.com/CouchPotato/CouchPotatoServer/tree/master/couchpotato/core/media/_base/providers/nzb/"
    click Torrent "https://github.com/CouchPotato/CouchPotatoServer/tree/master/couchpotato/core/media/_base/providers/torrent/"
    click Meta "https://github.com/CouchPotato/CouchPotatoServer/tree/master/couchpotato/core/media/_base/providers/metadata/"
    click NotifSystem "https://github.com/CouchPotato/CouchPotatoServer/tree/master/couchpotato/core/notifications/"
    click PluginMgr "https://github.com/CouchPotato/CouchPotatoServer/tree/master/couchpotato/core/plugins/"

    %% Legend
    subgraph Legend
        L1[Core Components]:::core
        L2[(Storage)]:::storage
        L3[UI Elements]:::ui
        L4[API Components]:::api
        L5[Security]:::security
        L6[Media Processing]:::media
        L7[Providers]:::provider
        L8[Downloaders]:::downloader
        L9[Notifications]:::notification
        L10[System]:::system
        Bug["🐛 Known Bug Areas"]
    end
```
