How dm-160105/mindmovieai works
1. Overall shape
This repo is a decoupled full-stack application: a Next.js frontend in frontend/ talks to a FastAPI backend in backend/, while local/ contains offline data-seeding, model-training, and artifact-generation scripts. The architecture is designed around separating UI, API/auth, and ML inference/artifact preparation.
2. Frontend boundary
The frontend is a Next.js App Router app with routes for onboarding and discovery flows such as login, register, explore, favorites, watchlist, profile, wizard, mood, vibe, and movie detail pages. This side is responsible for navigation, state orchestration, responsive UI, and calling backend APIs through src/lib/api.ts.
3. Frontend state and UX orchestration
Shared client state lives in src/context/:
- AuthContext for user/session state
- MoodContext and VibeContext for recommendation inputs and results
- ThemeContext and DeviceContext for UI behavior
The ProtectedRoute component implies route-level gating for authenticated pages, so the frontend enforces basic access control in addition to backend auth.
4. Backend API boundary
backend/api.py is the main HTTP surface. The README’s endpoint list shows the backend exposes authentication and recommendation endpoints such as /token, /auth/google, /recommend, /predict-preferences, and /sentiment-predict. This is the integration point for all frontend feature flows.
5. Backend core services
The backend is split into a few clear concerns:
- auth.py for JWT/session/Google auth handling
- database.py for MongoDB connectivity
- models.py for request/response and persistence structures
- mailer.py for OTP/email delivery
This indicates the backend owns identity, persistence, and notification concerns, rather than delegating them to the frontend.
6. ML and recommendation subsystem
The backend/ml/ directory is the main intelligence layer. It contains separate modules for:
- sentiment analysis (sentiment.py, sentiment_tf.py, sentiment_torch.py, train_sentiment.py)
- recommendation logic (dl_recommender.py, deep_learning.py, context_recommender.py, user_preference.py)
- mood/emotional arc modeling (mood_arc.py)
- popularity-based prediction (popularity_prediction.py)
This suggests the recommendation engine is hybrid: it combines content/context signals, learned user preferences, and sentiment-derived signals.
7. Offline artifact preparation
The local/ folder is a separate operational lane from the live API. Scripts like seed_arc.py, seed_vibes.py, train_sentiment.py, generate_artifacts.py, and fix_seed.py prepare the data and model artifacts used at runtime. This means the system depends on precomputed assets, not just live inference.
8. External artifact/data sync
backend/hf_utils.py and backend/ml/hf_sync.py show a Hugging Face integration for syncing datasets or model artifacts. That creates an important boundary: large or generated ML assets are kept outside the main code path and pulled in when needed, keeping the runtime repo lighter.
9. Data storage and persistence
MongoDB is the main persistent store, used for app data such as users, preferences, watchlists/favorites, and likely seeded mood/vibe metadata. The architecture keeps operational data in the database, while model weights/indexes and recommendation artifacts are managed separately through local generation and HF sync.
10. Feature flows
The main user journeys map to backend-supported flows:
- authentication: register/login/Google/OTP
- discovery: explore, movie detail, save/favorite/watchlist
- personalized recommendations: wizard, mood, vibe, and results pages
- profile feedback loops: history and preference updates feeding ML signals
This forms a feedback cycle where user behavior influences future recommendations.
11. Deployment and runtime
The repo is set up for split deployment: frontend/ is intended for Vercel, and backend/ for Render (render.yaml, Dockerfile, start.sh). That deployment model reinforces the architectural separation between stateless UI hosting and the Python API/ML service.
12. What to draw in an architecture diagram
The key diagram boundaries should be:
- Browser/client → Next.js frontend
- Frontend → FastAPI backend over HTTP
- FastAPI backend → MongoDB
- FastAPI backend → ML/recommendation modules and precomputed artifacts
- Backend → email/Google/TMDB/Hugging Face integrations
- Local scripts → seed/train/generate artifacts feeding the backend ML layer
Those are the main system edges and data flows that define this repository.
Main entry points: api.py API server · ml Recommender · app Next app · api.ts API client
Components 20
Frontend
Next.js client app and shared UI state
- Next app · Next.js App Router UI and page composition
frontend/src/app - UI components · Shared widgets, route guards, and reusable movie UI
frontend/src/components - Client state · Auth, theme, device, mood, and vibe context state
frontend/src/context - API client · Frontend backend integration layer
frontend/src/lib/api.ts
Backend
FastAPI service, auth, persistence, and ML runtime
- API server · FastAPI HTTP surface for auth and recommendations
backend/api.py - Auth · JWT, Google auth, and session handling
backend/auth.py - MongoDB · Primary application data store
backend/database.py - Models · Request, response, and persistence structures
backend/models.py - Mailer · OTP and email delivery
backend/mailer.py - Recommender · Hybrid recommendation and preference pipeline
backend/ml - Sentiment · Text sentiment analysis components
backend/ml/sentiment.py - Preference · User preference and context modeling
backend/ml/user_preference.py - Mood arc · Mood and emotional arc scoring
backend/ml/mood_arc.py - Popularity · Popularity-based prediction and ranking
backend/ml/popularity_prediction.py - HF sync · Hugging Face dataset and artifact synchronization
backend/ml/hf_sync.py
Local Ops
Offline data seeding, training, and artifact generation
- Artifacts · Seed, train, and generate runtime assets
local/generate_artifacts.py - Seed/train · Offline data seeding and sentiment training scripts
local/seed_arc.py
External Services
Third-party APIs and hosted storage
- TMDB · Movie metadata and discovery source
- Hugging Face · Hosted datasets and model artifacts
Other components
- Browser · User-facing web entry point
Connections 21
- Browser → Next app: uses · Users interact with the UI through the Next.js app
- Next app → UI components: renders · Pages compose shared layout and movie widgets
- Next app → Client state: orchestrates · Routes and interactions update shared client state
- Next app → API client: calls · Client pages use the API wrapper for backend requests
- UI components → API client: triggers · Interactive controls submit actions through the API layer
- API client → API server: HTTP · Frontend communicates with the FastAPI service
- API server → Auth: delegates · Authentication and token flows are handled separately
- API server → MongoDB: reads/writes · User and application data persist in MongoDB
- API server → Models: uses · API routes share typed request and response structures
- API server → Mailer: sends · OTP and email notifications are sent from the backend
- API server → Recommender: invokes · Recommendation endpoints call into the ML layer
- Recommender → Sentiment: uses · Sentiment signals feed ranking and classification
- Recommender → Preference: uses · User and context preferences shape recommendations
- Recommender → Mood arc: uses · Mood-based scoring contributes to recommendation outputs
- Recommender → Popularity: uses · Popularity heuristics provide fallback ranking
- Recommender → HF sync: syncs · Artifacts and datasets can be pulled from hosted storage
- Artifacts → Seed/train: prepares · Offline scripts seed data and train supporting models
- Seed/train → HF sync: publishes · Generated assets are synchronized for runtime consumption
- HF sync → Hugging Face: connects · Hosted artifacts live in Hugging Face storage
- API server → TMDB: fetches · Movie discovery and details rely on external metadata
- Next app → API server: auth/reco flows · Login, explore, mood, and vibe flows depend on backend endpoints