# dm-160105/mindmovieai architecture

> Architecture diagram of the GitHub repository dm-160105/mindmovieai, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dm-160105/mindmovieai
- Repository: https://github.com/dm-160105/mindmovieai

## Overview

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: [`backend/api.py`](https://github.com/dm-160105/mindmovieai/blob/main/backend/api.py) (API server), [`backend/ml`](https://github.com/dm-160105/mindmovieai/tree/main/backend/ml) (Recommender), [`frontend/src/app`](https://github.com/dm-160105/mindmovieai/tree/main/frontend/src/app) (Next app), [`frontend/src/lib/api.ts`](https://github.com/dm-160105/mindmovieai/blob/main/frontend/src/lib/api.ts) (API client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_nextjs_app["Next app<br/>frontend-shell"]
  node_ui_components["UI components<br/>presentation"]
  node_client_state["Client state"]
  node_api_client["API client<br/>http-client<br/>[api.ts]"]
end

subgraph group_backend["Backend"]
  node_backend_api["API server<br/>http-api<br/>[api.py]"]
  node_auth_service["Auth<br/>identity-service<br/>[auth.py]"]
  node_database[("MongoDB<br/>persistence<br/>[database.py]")]
  node_domain_models["Models<br/>schemas<br/>[models.py]"]
  node_mailer["Mailer<br/>notification<br/>[mailer.py]"]
  node_ml_core{{"Recommender<br/>ml-orchestrator"}}
  node_sentiment["Sentiment<br/>ml-inference<br/>[sentiment.py]"]
  node_preference["Preference<br/>ml-profile<br/>[user_preference.py]"]
  node_mood_model["Mood arc<br/>ml-feature<br/>[mood_arc.py]"]
  node_popularity["Popularity<br/>ml-scorer"]
  node_hf_sync["HF sync<br/>artifact-sync<br/>[hf_sync.py]"]
end

subgraph group_local["Local Ops"]
  node_artifact_tools["Artifacts<br/>offline-pipeline"]
  node_seed_train["Seed/train<br/>offline-pipeline<br/>[seed_arc.py]"]
end

subgraph group_external["External Services"]
  node_tmdb(("TMDB<br/>external-api"))
  node_huggingface(("Hugging Face<br/>external-storage"))
end

node_browser(("Browser<br/>client"))

node_browser -->|"uses"| node_nextjs_app
node_nextjs_app -->|"renders"| node_ui_components
node_nextjs_app -->|"orchestrates"| node_client_state
node_nextjs_app -->|"calls"| node_api_client
node_ui_components -.->|"triggers"| node_api_client
node_api_client -->|"HTTP"| node_backend_api
node_backend_api -->|"delegates"| node_auth_service
node_backend_api -->|"reads/writes"| node_database
node_backend_api -->|"uses"| node_domain_models
node_backend_api -->|"sends"| node_mailer
node_backend_api -->|"invokes"| node_ml_core
node_ml_core -->|"uses"| node_sentiment
node_ml_core -->|"uses"| node_preference
node_ml_core -->|"uses"| node_mood_model
node_ml_core -->|"uses"| node_popularity
node_ml_core -->|"syncs"| node_hf_sync
node_artifact_tools -->|"prepares"| node_seed_train
node_seed_train -->|"publishes"| node_hf_sync
node_hf_sync -->|"connects"| node_huggingface
node_backend_api -.->|"fetches"| node_tmdb
node_nextjs_app -.->|"auth/reco flows"| node_backend_api

click node_nextjs_app "https://github.com/dm-160105/mindmovieai/tree/main/frontend/src/app"
click node_ui_components "https://github.com/dm-160105/mindmovieai/tree/main/frontend/src/components"
click node_client_state "https://github.com/dm-160105/mindmovieai/tree/main/frontend/src/context"
click node_api_client "https://github.com/dm-160105/mindmovieai/blob/main/frontend/src/lib/api.ts"
click node_backend_api "https://github.com/dm-160105/mindmovieai/blob/main/backend/api.py"
click node_auth_service "https://github.com/dm-160105/mindmovieai/blob/main/backend/auth.py"
click node_database "https://github.com/dm-160105/mindmovieai/blob/main/backend/database.py"
click node_domain_models "https://github.com/dm-160105/mindmovieai/blob/main/backend/models.py"
click node_mailer "https://github.com/dm-160105/mindmovieai/blob/main/backend/mailer.py"
click node_ml_core "https://github.com/dm-160105/mindmovieai/tree/main/backend/ml"
click node_sentiment "https://github.com/dm-160105/mindmovieai/blob/main/backend/ml/sentiment.py"
click node_preference "https://github.com/dm-160105/mindmovieai/blob/main/backend/ml/user_preference.py"
click node_mood_model "https://github.com/dm-160105/mindmovieai/blob/main/backend/ml/mood_arc.py"
click node_popularity "https://github.com/dm-160105/mindmovieai/blob/main/backend/ml/popularity_prediction.py"
click node_hf_sync "https://github.com/dm-160105/mindmovieai/blob/main/backend/ml/hf_sync.py"
click node_artifact_tools "https://github.com/dm-160105/mindmovieai/blob/main/local/generate_artifacts.py"
click node_seed_train "https://github.com/dm-160105/mindmovieai/blob/main/local/seed_arc.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_nextjs_app,node_ui_components,node_client_state,node_api_client toneBlue
class node_backend_api,node_auth_service,node_database,node_domain_models,node_mailer,node_ml_core,node_sentiment,node_preference,node_mood_model,node_popularity,node_hf_sync toneAmber
class node_artifact_tools,node_seed_train toneMint
class node_tmdb,node_huggingface toneRose
class node_browser toneNeutral
```

## Components

### Frontend

Next.js client app and shared UI state

- [Next app](https://github.com/dm-160105/mindmovieai/tree/main/frontend/src/app): frontend-shell · Next.js App Router UI and page composition · `frontend/src/app`
- [UI components](https://github.com/dm-160105/mindmovieai/tree/main/frontend/src/components): presentation · Shared widgets, route guards, and reusable movie UI · `frontend/src/components`
- [Client state](https://github.com/dm-160105/mindmovieai/tree/main/frontend/src/context): state · Auth, theme, device, mood, and vibe context state · `frontend/src/context`
- [API client](https://github.com/dm-160105/mindmovieai/blob/main/frontend/src/lib/api.ts): http-client · Frontend backend integration layer · `frontend/src/lib/api.ts`

### Backend

FastAPI service, auth, persistence, and ML runtime

- [API server](https://github.com/dm-160105/mindmovieai/blob/main/backend/api.py): http-api · FastAPI HTTP surface for auth and recommendations · `backend/api.py`
- [Auth](https://github.com/dm-160105/mindmovieai/blob/main/backend/auth.py): identity-service · JWT, Google auth, and session handling · `backend/auth.py`
- [MongoDB](https://github.com/dm-160105/mindmovieai/blob/main/backend/database.py): persistence · Primary application data store · `backend/database.py`
- [Models](https://github.com/dm-160105/mindmovieai/blob/main/backend/models.py): schemas · Request, response, and persistence structures · `backend/models.py`
- [Mailer](https://github.com/dm-160105/mindmovieai/blob/main/backend/mailer.py): notification · OTP and email delivery · `backend/mailer.py`
- [Recommender](https://github.com/dm-160105/mindmovieai/tree/main/backend/ml): ml-orchestrator · Hybrid recommendation and preference pipeline · `backend/ml`
- [Sentiment](https://github.com/dm-160105/mindmovieai/blob/main/backend/ml/sentiment.py): ml-inference · Text sentiment analysis components · `backend/ml/sentiment.py`
- [Preference](https://github.com/dm-160105/mindmovieai/blob/main/backend/ml/user_preference.py): ml-profile · User preference and context modeling · `backend/ml/user_preference.py`
- [Mood arc](https://github.com/dm-160105/mindmovieai/blob/main/backend/ml/mood_arc.py): ml-feature · Mood and emotional arc scoring · `backend/ml/mood_arc.py`
- [Popularity](https://github.com/dm-160105/mindmovieai/blob/main/backend/ml/popularity_prediction.py): ml-scorer · Popularity-based prediction and ranking · `backend/ml/popularity_prediction.py`
- [HF sync](https://github.com/dm-160105/mindmovieai/blob/main/backend/ml/hf_sync.py): artifact-sync · Hugging Face dataset and artifact synchronization · `backend/ml/hf_sync.py`

### Local Ops

Offline data seeding, training, and artifact generation

- [Artifacts](https://github.com/dm-160105/mindmovieai/blob/main/local/generate_artifacts.py): offline-pipeline · Seed, train, and generate runtime assets · `local/generate_artifacts.py`
- [Seed/train](https://github.com/dm-160105/mindmovieai/blob/main/local/seed_arc.py): offline-pipeline · Offline data seeding and sentiment training scripts · `local/seed_arc.py`

### External Services

Third-party APIs and hosted storage

- **TMDB**: external-api · Movie metadata and discovery source
- **Hugging Face**: external-storage · Hosted datasets and model artifacts

### Other components

- **Browser**: client · User-facing web entry point

## Connections

- 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
