How breaksmodded/mi_catalogo_backend works
Project Type and Purpose
• This is the backend service of a full-stack application (“Mi Catálogo”) that provides a RESTful API for movie/series catalog management.
• Core features: media CRUD, advanced search, intelligent translations, dynamic posters, hybrid caching (Redis + in-memory), PostgreSQL storage, external TMDb integration.
High-Level Components
a. Frontend (React) – external client that consumes the API
b. API Gateway (FastAPI) – entry point; hosts all endpoints (main.py)
c. Router/Controller Layer – Pydantic-validated endpoints defined across modules (schemas.py, main.py)
d. Service Layer
• CRUD Service (crud.py) – media, lists, tags, favorites
• Translation Service (translation_service.py) – TMDb translation calls + DB cache
• Poster Service (poster_cache.py) – hybrid Redis+memory cache + TMDb poster selection
e. Data Access Layer
• Database (database.py, SQLAlchemy models in models.py with optimized indexes)
• Caches: Redis instance (optional) + in-memory fallback
f. External Services
• TMDb API – for metadata, translations, poster images
• Supabase/PostgreSQL – primary persistence
Relationships and Data Flows
• Frontend → FastAPI HTTP requests → Controller
• Controller → Service Layer (translation, poster, CRUD)
• Service Layer →
• Check in-memory cache → Redis → Database → TMDb (for misses) → backfill caches
• Direct DB queries for CRUD & search (with optimized indexes)
• FastAPI returns JSON responses to frontend
Architectural Patterns and Principles
• Layered Architecture: Controllers → Services → Repositories/ORM
• Single source of truth in PostgreSQL; caches for performance
• Circuit-breaker style fallback: Redis → in-memory → DB → TMDb
• Bulk/batch operations for posters & translations
• Dependency injection via FastAPI’s Depends
• Clear separation: media management vs. translation vs. poster logic
Technologies and Frameworks
• FastAPI (ASGI framework)
• Pydantic (request/response validation)
• SQLAlchemy 2.0 (ORM, DB models in models.py)
• PostgreSQL (Supabase) with custom indexes
• Redis (cache) + Python dict (fallback)
• Requests + BeautifulSoup4 (external API & scraping)
• python-dotenv (environment config)
Detailed Component Breakdown
• Controller Layer:
• main.py – entry point, mounts routers
• schemas.py – request/response models
• Service Layer:
• crud.py – generic CRUD operations
• translation_service.py – translation logic + DB cache interactions
• poster_cache.py – poster selection + hybrid cache logic
• Data Layer:
• database.py – engine, session management, index definitions
• models.py – SQLAlchemy table definitions (media, content_translations, lists, tags)
• External:
• TMDb API – translation & poster metadata
• Redis – optional for high-speed caching
• Supabase/PostgreSQL – primary data store