# chiefbibek/movie-recommendation-system architecture

> Architecture diagram of the GitHub repository chiefbibek/movie-recommendation-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/chiefbibek/movie-recommendation-system
- Repository: https://github.com/chiefbibek/movie-recommendation-system

## Overview

##### Project type and purpose
- This is a full-stack web application with a data-science component.
- Frontend: a React/Vite single-page app for collecting user input and displaying movie recommendations.
- Backend: a Node.js/Express API that exposes recommendation endpoints.
- Machine-learning service: Python scripts and pickled models (TF-IDF matrix and model) served by a Flask microservice (movie_api.py).
- No persistent database; the “data layer” consists of precomputed pickles and in-memory data structures.

##### File structure
- Top-level folders & files:
- “Frontend And Backend/app”: React application (Vite config, package.json, src/Components, Context)
- “Frontend And Backend/server”: Node/Express service (index.js, routes/routes.js, controller/appController.js)
- Root: Python files (movie_api.py, movie_recommender.py), Jupyter notebook, TF-IDF artifacts (.pkl), requirements.txt
- Key patterns:
- Frontend/Backend separation under a monorepo.
- Microservice pattern: Express app and Flask app co-exist.
- Data-science artifacts stored as pickles to decouple model training from inference.

##### README for additional insights
- The README:
- Emphasizes running a Jupyter notebook to prep data.
- Lists Python and Node/JS prerequisites.
- Instructs starting both the React frontend and the Node backend; although Flask prerequisites are listed, the Node app likely proxies to or invokes the Python microservice.

##### Main components & interactions
a. Components
1. Client Browser (React SPA)
2. React Frontend (Vite dev server)
3. Node.js/Express Backend
4. Python/Flask Recommendation Service
5. TF-IDF Model & Matrix (Pickle files)
6. Jupyter Notebook (development artifact)
b. Relationships & data flow
- The browser issues HTTP requests to the React dev server (port e.g. 3000).
- React sends REST calls (fetch/Axios) to Node/Express (e.g. GET /api/recommendations).
- Express controller (appController.js) forwards requests (via HTTP) to the Flask service (movie_api.py) or spawns a child‐process to run movie_recommender.py.
- Flask service loads TF-IDF artifacts from disk, constructs recommendations, and returns JSON.
- Express relays JSON to the React client.
- The client updates its GlobalState context and renders results.
c. Architectural patterns & design principles
- Separation of concerns: UI vs API vs ML logic
- Microservices: independent Flask service for ML inference
- Context API in React for state management
- Pickle serialization to decouple training from serving
d. Key technologies & frameworks
- Frontend: React, Vite, Tailwind CSS, Context API
- Backend: Node.js, Express, CORS
- ML Service: Python 3.x, Flask, scikit-learn, pandas, NumPy, pickle
- Dev/test: Jupyter Notebook, ESLint, PostCSS

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI Layer
    subgraph "UI Layer"
        direction TB
        Browser["Client Browser"]:::ui
        ReactDev["React SPA (Vite Dev Server)"]:::ui
        ViteConfig["vite.config.js"]:::ui
        TailwindConfig["tailwind.config.js"]:::ui
        MainJSX["src/main.jsx"]:::ui
        AppJSX["src/App.jsx"]:::ui
        ComponentsDir["src/Components/"]:::ui
        ContextDir["src/Context/GlobalState.jsx"]:::ui
    end

    %% API Layer
    subgraph "API Layer"
        direction TB
        Express["Express API (Node.js, port 5000)"]:::api
        IndexJS["index.js"]:::api
        RoutesJS["routes/routes.js"]:::api
        ControllerJS["controller/appController.js"]:::api
    end

    %% ML Service Layer
    subgraph "ML Service"
        direction TB
        Flask["Flask Service (movie_api.py)"]:::ml
        Recommender["movie_recommender.py"]:::ml
        ModelStorage["Model Storage"]:::ml
        TFIDFModel["tfidf_model.pkl"]:::ml
        TFIDFMatrix["tfidf_matrix.pkl"]:::ml
        Requirements["requirements.txt"]:::ml
    end

    %% Data Prep
    subgraph "Data Preparation"
        direction TB
        Notebook["notebook.ipynb"]:::dp
    end

    %% Data Flows
    Browser -->|"HTTP GET/POST"| ReactDev
    ReactDev -->|"GET /api/recommendations"| Express
    Express -->|"HTTP request"| Flask
    Express -->|"spawn child process"| Recommender
    Flask -->|"Load Pickle from disk"| TFIDFModel
    Flask -->|"Load Pickle from disk"| TFIDFMatrix
    Recommender -->|"Load Pickle from disk"| TFIDFModel
    Recommender -->|"Load Pickle from disk"| TFIDFMatrix
    Flask -->|"JSON Response"| Express
    Recommender -->|"JSON Response"| Express
    Express -->|"JSON Response"| ReactDev
    ReactDev -->|"Render Recommendations"| Browser
    Notebook -->|"Generate Pickles"| TFIDFModel
    Notebook -->|"Generate Pickles"| TFIDFMatrix

    %% Click Events - UI
    click ReactDev "https://github.com/chiefbibek/movie-recommendation-system/tree/main/Frontend And Backend/app/"
    click ViteConfig "https://github.com/chiefbibek/movie-recommendation-system/blob/main/Frontend And Backend/app/vite.config.js"
    click TailwindConfig "https://github.com/chiefbibek/movie-recommendation-system/blob/main/Frontend And Backend/app/tailwind.config.js"
    click MainJSX "https://github.com/chiefbibek/movie-recommendation-system/blob/main/Frontend And Backend/app/src/main.jsx"
    click AppJSX "https://github.com/chiefbibek/movie-recommendation-system/blob/main/Frontend And Backend/app/src/App.jsx"
    click ComponentsDir "https://github.com/chiefbibek/movie-recommendation-system/tree/main/Frontend And Backend/app/src/Components/"
    click ContextDir "https://github.com/chiefbibek/movie-recommendation-system/blob/main/Frontend And Backend/app/src/Context/GlobalState.jsx"

    %% Click Events - API
    click Express "https://github.com/chiefbibek/movie-recommendation-system/tree/main/Frontend And Backend/server/"
    click IndexJS "https://github.com/chiefbibek/movie-recommendation-system/blob/main/Frontend And Backend/server/index.js"
    click RoutesJS "https://github.com/chiefbibek/movie-recommendation-system/blob/main/Frontend And Backend/server/routes/routes.js"
    click ControllerJS "https://github.com/chiefbibek/movie-recommendation-system/blob/main/Frontend And Backend/server/controller/appController.js"

    %% Click Events - ML
    click Flask "https://github.com/chiefbibek/movie-recommendation-system/blob/main/movie_api.py"
    click Recommender "https://github.com/chiefbibek/movie-recommendation-system/blob/main/movie_recommender.py"
    click TFIDFModel "https://github.com/chiefbibek/movie-recommendation-system/blob/main/tfidf_model.pkl"
    click TFIDFMatrix "https://github.com/chiefbibek/movie-recommendation-system/blob/main/tfidf_matrix.pkl"
    click Requirements "https://github.com/chiefbibek/movie-recommendation-system/blob/main/requirements.txt"
    click Notebook "https://github.com/chiefbibek/movie-recommendation-system/blob/main/notebook.ipynb"

    %% Styling
    classDef ui fill:#D0E8FF,stroke:#0366D6,color:#0366D6;
    classDef api fill:#E0F5E9,stroke:#2E7D32,color:#2E7D32;
    classDef ml fill:#FFF4E5,stroke:#EF6C00,color:#E65100;
    classDef dp fill:#F3E5F5,stroke:#6A1B9A,color:#6A1B9A;
```
