# kishan0725/ajax-movie-recommendation-system-with-sentiment-analysis architecture

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

- Interactive diagram: https://gitdiagram.com/kishan0725/ajax-movie-recommendation-system-with-sentiment-analysis
- Repository: https://github.com/kishan0725/ajax-movie-recommendation-system-with-sentiment-analysis

## Overview

##### Project Type and Purpose
- This is a full-stack, single-page style web application built with Python/Flask on the backend and plain HTML/CSS/JavaScript on the frontend.
- Purpose: Provide content-based movie recommendations enriched with sentiment analysis of user-provided movie reviews. It fetches movie metadata from the TMDB API, scrapes user reviews from IMDB, runs a sentiment model on those reviews, and returns both recommendations and sentiment scores to the user via AJAX.

##### Main Components
a. Client Browser & UI
- HTML templates (templates/home.html, templates/recommend.html)
- Static assets: CSS (static/style.css), JavaScript controllers (static/autocomplete.js for live search, static/recommend.js for recommendation/AJAX calls)
b. Flask Backend (main.py)
- HTTP endpoints:
- GET “/” serves the home page
- POST or AJAX endpoint “/recommend” that takes a movie title and returns JSON with recommendations + sentiment
- Controller logic for orchestrating calls to:
- TMDB REST API (external)
- IMDb scraping routine (BeautifulSoup inside main.py)
- Local ML models (nlp_model.pkl, tranform.pkl)
c. Data & Model Artifacts
- Raw and processed CSVs under datasets/ and main_data.csv – used to build the content-based recommender (CountVectorizer matrix, cosine similarity)
- Pickled transformer (tranform.pkl) and trained sentiment model (nlp_model.pkl)
d. External Services
- TMDB API for movie metadata (poster URLs, genres, runtime, ratings, etc.)
- IMDB site (web scraped for user reviews)
e. Deployment/Runtime
- Procfile indicates Heroku (or similar PaaS) deployment
- requirements.txt lists Python dependencies: Flask, requests, BeautifulSoup4, scikit-learn, pandas, etc.

##### Relationships and Data Flows
1. User enters a movie title → autocomplete.js queries backend for matching titles (AJAX GET).
2. User selects or submits a title → recommend.js POSTs title to Flask endpoint.
3. Backend receives title →
a. Calls TMDB API (external) to fetch movie metadata.
b. Scrapes IMDB for user reviews (BeautifulSoup).
c. Runs sentiment analysis: reviews → transform.pkl → nlp_model.pkl → sentiment score.
d. Runs content-based recommender: lookup in main_data.csv/datasets/*.csv, compute similarity via precomputed cosine matrix or compute on the fly.
4. Backend packages: top N similar movies + sentiment summary → returns JSON to frontend.
5. Frontend (JavaScript) receives JSON → dynamically updates the UI with movie cards and sentiment metrics.

##### Architectural Patterns & Design Principles
- MVC-light:
- Model = CSV datasets + pickled ML artifacts
- View = HTML/CSS templates
- Controller = Flask routes (main.py)
- Single-page feel via AJAX: decouples UI rendering from full-page reload.
- Separation of concerns: scraping, API integration, recommendation logic, and sentiment analysis each encapsulated in dedicated code blocks (in main.py or separate notebooks for preprocessing).
- Reusable/pre-trained assets: pickled models and precomputed similarity matrices stored locally and loaded at startup.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Client/UI Layer"
        Browser["Client Browser"]:::client
        Home["templates/home.html"]:::client
        RecT["templates/recommend.html"]:::client
        CSS["static/style.css"]:::client
        AC["static/autocomplete.js"]:::client
        RJ["static/recommend.js"]:::client
    end

    subgraph "Backend (Flask App)"
        Main["main.py"]:::backend
        Proc["Procfile"]:::backend
        Req["requirements.txt"]:::backend
        Reco["Recommender Engine"]:::backend
        SentProc["Sentiment Analysis Pipeline"]:::backend
    end

    subgraph "Data & Models"
        DS1["datasets/data.csv"]:::data
        DS2["datasets/final_data.csv"]:::data
        DS3["datasets/main_data.csv"]:::data
        DS4["datasets/movie_metadata.csv"]:::data
        DS5["datasets/new_data.csv"]:::data
        DS6["datasets/reviews.txt"]:::data
        MD["main_data.csv"]:::data
        Transform["tranform.pkl"]:::data
        NLP["nlp_model.pkl"]:::data
    end

    subgraph "Preprocessing Notebooks"
        IP1[".ipynb_checkpoints/preprocessing 1.ipynb"]:::data
        IP2[".ipynb_checkpoints/preprocessing 2.ipynb"]:::data
        IP3[".ipynb_checkpoints/preprocessing 3.ipynb"]:::data
        IP4[".ipynb_checkpoints/preprocessing_4.ipynb"]:::data
        IP5[".ipynb_checkpoints/sentiment.ipynb"]:::data
    end

    subgraph "External Services"
        TMDB["TMDB API"]:::external
        IMDB["IMDB Scraper (IMDB)"]:::external
    end

    Browser -->|"GET /autocomplete (AJAX)"| Main
    AC -->|"GET /autocomplete (AJAX)"| Main
    RJ -->|"POST /recommend (AJAX)"| Main

    Main --> Reco
    Main --> SentProc

    Reco -->|"read CSVs, compute cosine similarity"| DS3
    Reco -->|"read CSVs, compute cosine similarity"| DS1
    Reco -->|"read CSVs, compute cosine similarity"| DS2
    Reco -->|"read CSVs, compute cosine similarity"| DS4
    Reco -->|"read CSVs, compute cosine similarity"| DS5

    IMDB -->|"HTML reviews"| SentProc
    SentProc --> Transform
    SentProc --> NLP
    SentProc -->|"compute sentiment score"| Main

    Main -->|"TMDB API call"| TMDB
    Main -->|"Scrape IMDB reviews"| IMDB

    Reco -->|"recommendations JSON"| Main
    Main -->|"JSON response"| Browser

    classDef client fill:#c8f7c5,stroke:#2d862d;
    classDef backend fill:#9fc5e8,stroke:#2d5a7f;
    classDef data fill:#f9cb9c,stroke:#a57a00;
    classDef external fill:#f4b183,stroke:#a86915;

    click Home "https://github.com/kishan0725/ajax-movie-recommendation-system-with-sentiment-analysis/blob/master/templates/home.html"
    click RecT "https://github.com/kishan0725/ajax-movie-recommendation-system-with-sentiment-analysis/blob/master/templates/recommend.html"
    click CSS "https://github.com/kishan0725/ajax-movie-recommendation-system-with-sentiment-analysis/blob/master/static/style.css"
    click AC "https://github.com/kishan0725/ajax-movie-recommendation-system-with-sentiment-analysis/blob/master/static/autocomplete.js"
    click RJ "https://github.com/kishan0725/ajax-movie-recommendation-system-with-sentiment-analysis/blob/master/static/recommend.js"
    click Main "https://github.com/kishan0725/ajax-movie-recommendation-system-with-sentiment-analysis/blob/master/main.py"
    click Proc "https://github.com/kishan0725/ajax-movie-recommendation-system-with-sentiment-analysis/tree/master/Procfile"
    click Req "https://github.com/kishan0725/ajax-movie-recommendation-system-with-sentiment-analysis/blob/master/requirements.txt"
    click DS1 "https://github.com/kishan0725/ajax-movie-recommendation-system-with-sentiment-analysis/blob/master/datasets/data.csv"
    click DS2 "https://github.com/kishan0725/ajax-movie-recommendation-system-with-sentiment-analysis/blob/master/datasets/final_data.csv"
    click DS3 "https://github.com/kishan0725/ajax-movie-recommendation-system-with-sentiment-analysis/blob/master/datasets/main_data.csv"
    click DS4 "https://github.com/kishan0725/ajax-movie-recommendation-system-with-sentiment-analysis/blob/master/datasets/movie_metadata.csv"
    click DS5 "https://github.com/kishan0725/ajax-movie-recommendation-system-with-sentiment-analysis/blob/master/datasets/new_data.csv"
    click DS6 "https://github.com/kishan0725/ajax-movie-recommendation-system-with-sentiment-analysis/blob/master/datasets/reviews.txt"
    click MD "https://github.com/kishan0725/ajax-movie-recommendation-system-with-sentiment-analysis/blob/master/main_data.csv"
    click Transform "https://github.com/kishan0725/ajax-movie-recommendation-system-with-sentiment-analysis/blob/master/tranform.pkl"
    click NLP "https://github.com/kishan0725/ajax-movie-recommendation-system-with-sentiment-analysis/blob/master/nlp_model.pkl"
    click IP1 "https://github.com/kishan0725/ajax-movie-recommendation-system-with-sentiment-analysis/blob/master/.ipynb_checkpoints/preprocessing 1.ipynb"
    click IP2 "https://github.com/kishan0725/ajax-movie-recommendation-system-with-sentiment-analysis/blob/master/.ipynb_checkpoints/preprocessing 2.ipynb"
    click IP3 "https://github.com/kishan0725/ajax-movie-recommendation-system-with-sentiment-analysis/blob/master/.ipynb_checkpoints/preprocessing 3.ipynb"
    click IP4 "https://github.com/kishan0725/ajax-movie-recommendation-system-with-sentiment-analysis/blob/master/.ipynb_checkpoints/preprocessing_4.ipynb"
    click IP5 "https://github.com/kishan0725/ajax-movie-recommendation-system-with-sentiment-analysis/blob/master/.ipynb_checkpoints/sentiment.ipynb"
```
