# Architecture Diagram - Agent Media
## System Overview
```mermaid
flowchart TB
subgraph Client["👤 Client"]
CHAT[Chat Interface
OpenWebUI / CLI / Custom]
end
subgraph AgentMedia["🎬 Agent Media"]
subgraph API["API Layer"]
FASTAPI[FastAPI Server
:8000]
end
subgraph Core["Core"]
AGENT[🤖 Agent
Orchestrator]
MEMORY[🧠 Memory
LTM + STM + Episodic]
end
subgraph Tools["Tools"]
T1[📁 Filesystem]
T2[🔍 Search]
T3[⬇️ Download]
end
end
subgraph LLM["🧠 LLM Provider"]
DEEPSEEK[DeepSeek API]
OLLAMA[Ollama
Local]
end
subgraph External["☁️ External Services"]
TMDB[(TMDB
Movie Database)]
KNABEN[(Knaben
Torrent Search)]
QBIT[qBittorrent
Download Client]
end
subgraph Storage["💾 Storage"]
JSON[(memory_data/
ltm.json)]
MEDIA[(Media Folders
/movies /tvshows)]
end
CHAT <-->|OpenAI API| FASTAPI
FASTAPI <--> AGENT
AGENT <--> MEMORY
AGENT <--> Tools
AGENT <-->|Chat Completion| LLM
T1 <--> MEDIA
T2 --> TMDB
T2 --> KNABEN
T3 --> QBIT
MEMORY <--> JSON
QBIT --> MEDIA
style AgentMedia fill:#1a1a2e,color:#fff
style AGENT fill:#ff6b6b,color:#fff
style MEMORY fill:#4ecdc4,color:#fff
```
## Detailed Architecture
```mermaid
flowchart TB
subgraph Clients["Clients"]
direction LR
OWU[OpenWebUI]
CLI[CLI Client]
CURL[cURL / HTTP]
end
subgraph LoadBalancer["Entry Point"]
NGINX[Nginx / Reverse Proxy
Optional]
end
subgraph Application["Agent Media Application"]
direction TB
subgraph Presentation["Presentation Layer"]
EP1["/v1/chat/completions"]
EP2["/v1/models"]
EP3["/health"]
EP4["/memory/state"]
end
subgraph AgentLayer["Agent Layer"]
direction LR
AG[Agent]
PB[PromptBuilder]
REG[Registry]
end
subgraph ToolsLayer["Tools Layer"]
direction LR
FS_TOOL[Filesystem Tools
set_path, list_folder]
API_TOOL[API Tools
find_torrent, add_torrent]
end
subgraph AppLayer["Application Layer"]
direction LR
UC1[SearchMovie
UseCase]
UC2[SearchTorrents
UseCase]
UC3[AddTorrent
UseCase]
UC4[SetFolderPath
UseCase]
end
subgraph DomainLayer["Domain Layer"]
direction LR
ENT[Entities
Movie, TVShow, Subtitle]
VO[Value Objects
ImdbId, Quality, FilePath]
REPO_INT[Repository
Interfaces]
end
subgraph InfraLayer["Infrastructure Layer"]
direction TB
subgraph Persistence["Persistence"]
MEM[Memory Manager]
REPO_IMPL[JSON Repositories]
end
subgraph APIClients["API Clients"]
TMDB_C[TMDB Client]
KNAB_C[Knaben Client]
QBIT_C[qBittorrent Client]
end
subgraph FSManager["Filesystem"]
FM[FileManager]
end
end
end
subgraph LLMProviders["LLM Providers"]
direction LR
DS[DeepSeek
api.deepseek.com]
OL[Ollama
localhost:11434]
end
subgraph ExternalAPIs["External APIs"]
direction LR
TMDB_API[TMDB API
api.themoviedb.org]
KNAB_API[Knaben API
knaben.eu]
QBIT_API[qBittorrent WebUI
localhost:8080]
end
subgraph DataStores["Data Stores"]
direction LR
LTM_FILE[(ltm.json
Persistent Config)]
MEDIA_DIR[(Media Directories
/downloads /movies /tvshows)]
end
%% Client connections
Clients --> LoadBalancer
LoadBalancer --> Presentation
%% Internal flow
Presentation --> AgentLayer
AgentLayer --> ToolsLayer
ToolsLayer --> AppLayer
AppLayer --> DomainLayer
AppLayer --> InfraLayer
InfraLayer -.->|implements| DomainLayer
%% Agent to LLM
AgentLayer <-->|HTTP| LLMProviders
%% Infrastructure to External
TMDB_C -->|HTTP| TMDB_API
KNAB_C -->|HTTP| KNAB_API
QBIT_C -->|HTTP| QBIT_API
%% Persistence
MEM <--> LTM_FILE
FM <--> MEDIA_DIR
QBIT_API --> MEDIA_DIR
```
## Memory System Architecture
```mermaid
flowchart TB
subgraph MemoryManager["Memory Manager"]
direction TB
subgraph LTM["💾 Long-Term Memory"]
direction LR
LTM_DESC["Persistent across restarts
Stored in ltm.json"]
subgraph LTM_DATA["Data"]
CONFIG["config{}
folder paths, API keys"]
PREFS["preferences{}
quality, languages"]
LIBRARY["library{}
movies[], tv_shows[]"]
FOLLOWING["following[]
watchlist"]
end
end
subgraph STM["🧠 Short-Term Memory"]
direction LR
STM_DESC["Session-based
Cleared on restart"]
subgraph STM_DATA["Data"]
HISTORY["conversation_history[]
last 20 messages"]
WORKFLOW["current_workflow{}
type, stage, target"]
ENTITIES["extracted_entities{}
title, year, quality"]
TOPIC["current_topic
searching, downloading"]
end
end
subgraph EPISODIC["⚡ Episodic Memory"]
direction LR
EPIS_DESC["Transient state
Cleared on restart"]
subgraph EPIS_DATA["Data"]
SEARCH["last_search_results{}
indexed torrents"]
DOWNLOADS["active_downloads[]
in-progress"]
ERRORS["recent_errors[]
last 5 errors"]
PENDING["pending_question{}
awaiting user input"]
EVENTS["background_events[]
notifications"]
end
end
end
subgraph Storage["Storage"]
FILE[(memory_data/ltm.json)]
end
subgraph Lifecycle["Lifecycle"]
SAVE[save()]
LOAD[load()]
CLEAR[clear_session()]
end
LTM <-->|read/write| FILE
SAVE --> LTM
LOAD --> LTM
CLEAR --> STM
CLEAR --> EPISODIC
style LTM fill:#4caf50,color:#fff
style STM fill:#2196f3,color:#fff
style EPISODIC fill:#ff9800,color:#fff
```
## Request Flow
```mermaid
flowchart LR
subgraph Request["1️⃣ Request"]
USER[User Message]
end
subgraph Parse["2️⃣ Parse"]
FASTAPI[FastAPI
Extract message]
end
subgraph Context["3️⃣ Build Context"]
PROMPT[PromptBuilder
+ Memory context
+ Tool descriptions]
end
subgraph Think["4️⃣ Think"]
LLM[LLM
Decide action]
end
subgraph Act["5️⃣ Act"]
TOOL[Execute Tool
or respond]
end
subgraph Store["6️⃣ Store"]
MEM[Update Memory
STM + Episodic]
end
subgraph Response["7️⃣ Response"]
RESP[JSON Response]
end
USER --> FASTAPI --> PROMPT --> LLM
LLM -->|Tool call| TOOL --> MEM --> LLM
LLM -->|Text response| MEM --> RESP
style Think fill:#ff6b6b,color:#fff
style Act fill:#4ecdc4,color:#fff
style Store fill:#45b7d1,color:#fff
```
## Deployment Architecture
```mermaid
flowchart TB
subgraph Host["Host Machine"]
subgraph Docker["Docker (Optional)"]
AGENT_CONTAINER[Agent Media
Container]
end
subgraph Native["Native Services"]
QBIT_SERVICE[qBittorrent
:8080]
OLLAMA_SERVICE[Ollama
:11434]
end
subgraph Storage["Local Storage"]
CONFIG_DIR[/config
memory_data/]
MEDIA_DIR[/media
downloads, movies, tvshows]
end
end
subgraph Cloud["Cloud Services"]
DEEPSEEK[DeepSeek API]
TMDB[TMDB API]
KNABEN[Knaben API]
end
subgraph Client["Client"]
BROWSER[Browser
OpenWebUI]
end
BROWSER <-->|:8000| AGENT_CONTAINER
AGENT_CONTAINER <-->|:8080| QBIT_SERVICE
AGENT_CONTAINER <-->|:11434| OLLAMA_SERVICE
AGENT_CONTAINER <--> CONFIG_DIR
AGENT_CONTAINER <--> MEDIA_DIR
QBIT_SERVICE --> MEDIA_DIR
AGENT_CONTAINER <-->|HTTPS| Cloud
```
## Technology Stack
```mermaid
mindmap
root((Agent Media))
API
FastAPI
Uvicorn
OpenAI Compatible
Agent
Python 3.11+
Dataclasses
Protocol typing
LLM
DeepSeek
Ollama
OpenAI compatible
Storage
JSON files
Filesystem
External APIs
TMDB
Knaben
qBittorrent WebUI
Architecture
DDD
Clean Architecture
Hexagonal
```
## Security Considerations
```mermaid
flowchart TB
subgraph Security["Security Layers"]
direction TB
subgraph Input["Input Validation"]
PATH_VAL[Path Traversal Protection
FileManager._sanitize_path]
INPUT_VAL[Input Sanitization
Tool parameters]
end
subgraph Auth["Authentication"]
API_KEYS[API Keys
Environment variables]
QBIT_AUTH[qBittorrent Auth
Username/Password]
end
subgraph Access["Access Control"]
FOLDER_RESTRICT[Folder Restrictions
Configured paths only]
SAFE_PATH[Safe Path Checks
_is_safe_path()]
end
end
subgraph Env["Environment"]
ENV_FILE[.env file
DEEPSEEK_API_KEY
TMDB_API_KEY
QBITTORRENT_*]
end
ENV_FILE --> Auth
Input --> Access
```
## Legend
| Icon | Meaning |
|------|---------|
| 🎬 | Agent Media System |
| 🤖 | AI Agent |
| 🧠 | Memory / LLM |
| 💾 | Persistent Storage |
| ⚡ | Transient / Fast |
| 📁 | Filesystem |
| 🔍 | Search |
| ⬇️ | Download |
| ☁️ | Cloud / External |
| 👤 | User / Client |