milmilmilmil
Architecture

Architecture

milmil system architecture and internals.

System Overview

milmil is a monolithic Go backend with a React SPA frontend, designed for self-hosted deployment.

┌─────────────────────────────────────────────────┐
│                   Clients                       │
│         Browser (PWA)  │  Telegram/Discord Bot  │
└───────────┬─────────────────────┬───────────────┘
            │ HTTP/WS             │ Bot API
┌───────────▼─────────────────────▼───────────────┐
│                milmil-api (Go)                  │
│  ┌──────────┐ ┌──────────┐ ┌──────────────────┐│
│  │ REST API │ │WebSocket │ │ Bot Engine       ││
│  └────┬─────┘ └────┬─────┘ └───────┬──────────┘│
│       │             │               │           │
│  ┌────▼─────────────▼───────────────▼──────────┐│
│  │              Service Layer                  ││
│  │  Library │ Stream │ Download │ Discover     ││
│  │  Collection │ Auth │ Notification           ││
│  └────┬────────────────────────────────────────┘│
│       │                                         │
│  ┌────▼────────────────────────────────────────┐│
│  │           Infrastructure Layer              ││
│  │  PostgreSQL/SQLite │ Redis │ FFmpeg │ Rclone││
│  └─────────────────────────────────────────────┘│
└─────────────────────────────────────────────────┘

┌─────────────────────────────────────────────────┐
│              milmil-web (React SPA)             │
│  Served via Nginx or dev server                 │
└─────────────────────────────────────────────────┘

Component Overview

ComponentDescription
REST APIEcho router serving JSON endpoints. Handles auth, CRUD, streaming, and search.
WebSocketReal-time event push for danmaku, notifications, and scan progress.
Bot EnginePlatform-agnostic bot with adapters for Telegram and Discord.
Service LayerBusiness logic for library scanning, metadata matching, download management, and collection sync.
FFmpegMedia probing, container remuxing, and HLS transcoding.
RcloneCloud storage abstraction for 40+ providers.

Data Flow: Library Scan

File Discovery

Walk the storage backend (local, SMB, rclone, etc.) to enumerate all media files.

Media Probing

FFmpeg probes each file for codec info, resolution, duration, embedded subtitles, and audio tracks.

Metadata Matching

Match files to anime entries using the provider pipeline: DandanPlay (hash) → Bangumi (title) → AniList (title) → TMDB (fallback).

Enrichment

Fetch cover images, episode titles, descriptions, and ratings from matched providers.

Persistence

Store all metadata in the database. Send scan completion notification.

Data Flow: Streaming

Client request
    │
    ▼
┌─────────────────┐
│ Codec supported? │──yes──▶ Direct Play (byte-range)
└────────┬────────┘
         │ no
         ▼
┌─────────────────┐
│ Container only?  │──yes──▶ Remux (MKV→MP4, no re-encode)
└────────┬────────┘
         │ no
         ▼
    HLS Transcode (FFmpeg)

Technology Stack

TechnologyDescription
BackendGo — Chi router, sqlc, golang-migrate, anacrolix/torrent
FrontendReact — Vite, TanStack Router, TanStack Query, Tailwind CSS
DatabasePostgreSQL/SQLite — Schema managed with golang-migrate
CacheRedis — Optional, in-memory fallback available
MediaFFmpeg — Probing, remuxing, HLS transcoding
StorageRclone — 40+ cloud provider backends
DocsFumadocs — Next.js-based documentation with i18n

Repository Structure

go.mod
Makefile
docker-compose.yml
Makefile

On this page