-
Notifications
You must be signed in to change notification settings - Fork 1
Development
ZASENJC edited this page May 23, 2026
·
1 revision
English | 简体中文
mediatree/
├── backend/ # Python 3.12 + FastAPI
│ ├── app/
│ │ ├── main.py # FastAPI app, 85+ route handlers
│ │ ├── scanner.py # Core scan & scrape engine
│ │ ├── database.py # SQLite CRUD operations
│ │ ├── config.py # pydantic-settings + JSON persistence
│ │ ├── stream.py # Video streaming (Range, transcode)
│ │ ├── subtitles.py # Subtitle detection & conversion
│ │ ├── covers.py # Cover image download & caching
│ │ ├── watcher.py # File system watcher
│ │ ├── anime_naming.py # Anime filename parser
│ │ ├── tmdb.py # TMDB API client
│ │ ├── bangumi.py # Bangumi API client
│ │ ├── javdb.py # JavDatabase scraper
│ │ ├── jellyfin_compat.py # Jellyfin API routes
│ │ ├── jellyfin_mappers.py # Data mapping
│ │ ├── jellyfin_auth.py # Jellyfin auth
│ │ └── scrapers/ # Scraper plugin system
│ └── tests/ # Unit tests
│
├── frontend/ # React 18 + TypeScript 5
│ ├── src/
│ │ ├── App.tsx # Root component + routes + nav
│ │ ├── api.ts # API client (120s TTL cache)
│ │ ├── cache.ts # Response cache
│ │ ├── store.ts # localStorage preferences
│ │ ├── pages/ # 8 page components
│ │ ├── components/ # 16 reusable components
│ │ ├── utils/ # Helpers (VTT parser, polling)
│ │ └── index.css # Glassmorphism design system
│ └── public/fonts/ # Bundled fonts
│
├── data/ # Runtime data (gitignored)
├── Dockerfile # Multi-stage build
├── docker-compose.yml # Docker deployment
└── .env.example # Environment template
In production, the backend serves the built frontend at /. For development, run them separately:
# Terminal 1 — Backend on port 80
cd backend
pip install -r requirements.txt
uvicorn app.main:app --reload --host 0.0.0.0 --port 80
# Terminal 2 — Frontend on port 5173
cd frontend
npm install
npm run devThe Vite dev server proxies /api/* requests to localhost:80 (configured in vite.config.ts).
# All tests
cd backend
python -m unittest discover -s tests -p 'test_*.py'
# Single test file
python -m unittest tests.test_anime_naming
# Specific test
python -m unittest tests.test_scanner_tmdbid.TestSomething.test_method# Frontend build
cd frontend && npm run build
# Backend syntax check
python -m compileall backend/app
# Docker build (multi-arch)
docker buildx build \
--platform linux/amd64,linux/arm64 \
-t mediatree:dev .-
Single-file router: All API routes in
main.py(~1580 lines). No separate router modules. -
Auth middleware:
AuthMiddlewareguards/api/*routes with Basic/Bearer auth. Whitelisted paths bypass auth. - Lifespan hooks: DB init, Jellyfin startup, initial scan, and file watcher all managed in FastAPI lifespan.
- SQLite WAL mode: Enabled for better concurrent read performance.
- API cache: 120s TTL with automatic invalidation on mutations (re-scrape, delete, edit)
-
Glassmorphism components: CSS utility classes in
index.csslayer — useglass-panel,glass-card, etc. -
Portal rendering: Modals and lightbox render to
document.bodyto avoid z-index stacking issues.
| Decision | Rationale |
|---|---|
| SQLite over PostgreSQL | Zero-config, single-file backup, WAL mode sufficient for single-user workloads |
| Single-file main.py | Simpler to maintain for this project scale; no circular import issues |
| Client-side subtitle rendering | Avoids server ffmpeg transcoding; enables ASS effects via libass-wasm |
| DirectPlay by default | Modern clients support most codecs; avoids server CPU load |
| File watcher over polling | Real-time updates with minimal overhead via watchfiles
|
- Add route in
main.py - Add CRUD function in
database.pyif needed - Add typed method in
frontend/src/api.ts - Use in page/component
- Create
backend/app/scrapers/name_scraper.py - Subclass
BaseScraper, implementsearch()andget_detail() - Register in
registry.py - The
autofallback chain handles the rest
- Create in
frontend/src/components/ - Use TailwindCSS utility classes with glassmorphism component classes
- Use React Portal for modals/overlays
- Add route in
App.tsxif it's a new page
- Backend: Standard Python conventions. Type hints on function signatures.
- Frontend: Functional components with hooks. TypeScript strict mode.
-
CSS: Tailwind utility classes. Custom components via
@layer componentsinindex.css. - Naming: English identifiers (functions, variables, classes). Chinese documentation and comments.