# giyn/doubanmovierecommendationsystem architecture

> Architecture diagram of the GitHub repository giyn/doubanmovierecommendationsystem, 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/giyn/doubanmovierecommendationsystem
- Repository: https://github.com/giyn/doubanmovierecommendationsystem

## Overview

##### Project Type and Purpose
- This is a standalone desktop recommendation tool (Python 3.7) with three sub-systems:
- Spider module for crawling & ETL
- Recommendation Engine module (Item-based CF)
- PyQt5 GUI module for user interaction
- Data is persisted in CSV files and/or a MySQL database.

##### File Structure
- Top-level directories:
- Spider/: crawlers for movies & users
- Data/: raw CSVs + save_to_MySQL script
- Algorithm/: itemCF recommendation + user-record scripts
- GUI/: PyQt5 entry points and window classes
- Other artifacts: MoviePosters/ (assets), requirements.txt, README.md, LICENSE.

##### README for Extra Insights
- Confirms three modules (crawl, recommend, GUI)
- Uses requests, json, MySQL, pandas, PyQt5
- Data flow: crawl → store → recommend → GUI.

##### Main Components & Their Relationships
a. Components:
1) External Web (Douban site)
2) Spider module (Spider/*.py)
3) Data persistence layer (Data/*.csv + MySQL via save_to_MySQL.py)
4) Algorithm module (Algorithm/recommendation.py, record_users.py)
5) GUI module (GUI/*.py)
6) Asset store (MoviePosters/)
b. Interactions / Data Flow:
- Spider fetches JSON/HTML from Douban → parses → writes raw CSV (Data/) and/or pushes into MySQL.
- Algorithm reads user–movie interaction data from CSV or MySQL → computes similarity matrix → produces top-N recommendations per user → may cache or return results in memory.
- GUI at runtime:
- On login → reads users_info.csv or queries MySQL for credential check.
- On “Recommend” → calls recommendation module → displays results.
- On “Search” or “Detail” → queries Data CSV/DB → fetches metadata (director, summary) and poster path (MoviePosters/) → displays.
- On new user registration → appends to CSV/DB and triggers cold-start questionnaire → feeds initial preferences into recommendation input.
c. Architectural Patterns & Principles:
- Layered architecture (Data Access Layer, Business Logic Layer, Presentation Layer)
- Single Responsibility per module
- MVC-style separation inside GUI (windows as Views, recommendation.py as Controller, CSV/DB as Model)
d. Key Technologies:
- Python 3.7.7
- requests, json, BeautifulSoup or lxml (Spider)
- pandas, MySQL connector (Data & Algorithm)
- PyQt5 (GUI)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Services
    subgraph "External Services"
        direction TB
        DoubanWeb["Douban.com"]:::external
    end

    %% Data Ingestion Layer
    subgraph "Data Ingestion (Spider)" 
        direction TB
        CrawlMovies["crawl_dbmovies.py"]:::ingestion
        CrawlUsers["crawl_douban_users.py"]:::ingestion
        SupplementMovie["supplement_movie.py"]:::ingestion
    end

    %% Data Storage & Algorithm Layer
    subgraph "Data Storage & Recommendation Engine"
        direction TB
        subgraph "CSV Data Stores"
            direction TB
            MoviesCSV["douban_movies.csv"]:::datastore
            UsersCSV["douban_users.csv"]:::datastore
            UsersInfoCSV["users_info.csv"]:::datastore
            DatasetDesc["DatasetsDescription.txt"]:::datastore
        end
        SaveMySQL["save_to_MySQL.py"]:::ingestion
        MySQLDB["MySQL Database"]:::datastore
        subgraph "Recommendation Engine"
            direction TB
            RecommendModule["recommendation.py"]:::algorithm
            RecordUsers["record_users.py"]:::algorithm
        end
    end

    %% Presentation Layer
    subgraph "Presentation (PyQt5 GUI)"
        direction TB
        subgraph "Controllers"
            direction TB
            MainApp["main.py"]:::gui
            LoginCtrl["login.py"]:::gui
            SignCtrl["sign.py"]:::gui
        end
        subgraph "Views/Windows"
            direction TB
            MainWindow["main_window.py"]:::gui
            SearchWindow["search_window.py"]:::gui
            MovieDetailSearch["movie_detailed_search.py"]:::gui
            MovieDetail["movie_detailed.py"]:::gui
            NewUserCtrl["new_user.py"]:::gui
            NewUserWindow["new_user_window.py"]:::gui
            UserCenter["user_center.py"]:::gui
            RecView["recommendation.py"]:::gui
        end
        Assets["MoviePosters/"]:::asset
    end

    %% Connections: Spider to Data Stores
    DoubanWeb -->|HTTP GET| CrawlMovies
    DoubanWeb -->|HTTP GET| CrawlUsers
    DoubanWeb -->|HTTP GET| SupplementMovie
    CrawlMovies -->|writes CSV| MoviesCSV
    CrawlUsers -->|writes CSV| UsersCSV
    SupplementMovie -->|updates CSV| MoviesCSV
    CrawlMovies -->|push to DB| SaveMySQL
    CrawlUsers -->|push to DB| SaveMySQL
    SaveMySQL -->|loads data| MySQLDB

    %% Connections: Data to Algorithm
    MoviesCSV -->|reads data| RecommendModule
    UsersCSV -->|reads data| RecommendModule
    UsersInfoCSV -->|reads data| RecommendModule
    MySQLDB -->|reads data| RecommendModule
    RecommendModule -->|updates| MySQLDB
    RecommendModule -->|logs new| RecordUsers
    RecordUsers -->|writes| UsersInfoCSV
    RecordUsers -->|writes| MySQLDB

    %% Connections: GUI to Controllers and Modules
    MainApp -->|launches| LoginCtrl
    LoginCtrl -->|queries| UsersInfoCSV
    LoginCtrl -->|queries| MySQLDB
    LoginCtrl -->|on success| MainWindow
    SignCtrl -->|registers| NewUserWindow
    NewUserWindow -->|collects prefs| RecordUsers
    MainWindow -->|Recommend action| RecView
    RecView -->|calls| RecommendModule
    MainWindow -->|Search action| SearchWindow
    SearchWindow -->|queries| MoviesCSV
    SearchWindow -->|queries| MySQLDB
    MainWindow -->|Detail action| MovieDetailSearch
    MovieDetailSearch -->|fetches| MovieDetail
    MovieDetail -->|loads poster| Assets

    %% Click Events
    click CrawlMovies "https://github.com/giyn/doubanmovierecommendationsystem/blob/master/Spider/crawl_dbmovies.py"
    click CrawlUsers "https://github.com/giyn/doubanmovierecommendationsystem/blob/master/Spider/crawl_douban_users.py"
    click SupplementMovie "https://github.com/giyn/doubanmovierecommendationsystem/blob/master/Spider/supplement_movie.py"
    click MoviesCSV "https://github.com/giyn/doubanmovierecommendationsystem/blob/master/Data/douban_movies.csv"
    click UsersCSV "https://github.com/giyn/doubanmovierecommendationsystem/blob/master/Data/douban_users.csv"
    click UsersInfoCSV "https://github.com/giyn/doubanmovierecommendationsystem/blob/master/Data/users_info.csv"
    click DatasetDesc "https://github.com/giyn/doubanmovierecommendationsystem/blob/master/Data/DatasetsDescription.txt"
    click SaveMySQL "https://github.com/giyn/doubanmovierecommendationsystem/blob/master/Data/save_to_MySQL.py"
    click RecommendModule "https://github.com/giyn/doubanmovierecommendationsystem/blob/master/Algorithm/recommendation.py"
    click RecordUsers "https://github.com/giyn/doubanmovierecommendationsystem/blob/master/Algorithm/record_users.py"
    click MainApp "https://github.com/giyn/doubanmovierecommendationsystem/blob/master/GUI/main.py"
    click LoginCtrl "https://github.com/giyn/doubanmovierecommendationsystem/blob/master/GUI/login.py"
    click SignCtrl "https://github.com/giyn/doubanmovierecommendationsystem/blob/master/GUI/sign.py"
    click MainWindow "https://github.com/giyn/doubanmovierecommendationsystem/blob/master/GUI/main_window.py"
    click SearchWindow "https://github.com/giyn/doubanmovierecommendationsystem/blob/master/GUI/search_window.py"
    click MovieDetailSearch "https://github.com/giyn/doubanmovierecommendationsystem/blob/master/GUI/movie_detailed_search.py"
    click MovieDetail "https://github.com/giyn/doubanmovierecommendationsystem/blob/master/GUI/movie_detailed.py"
    click NewUserCtrl "https://github.com/giyn/doubanmovierecommendationsystem/blob/master/GUI/new_user.py"
    click NewUserWindow "https://github.com/giyn/doubanmovierecommendationsystem/blob/master/GUI/new_user_window.py"
    click UserCenter "https://github.com/giyn/doubanmovierecommendationsystem/blob/master/GUI/user_center.py"
    click RecView "https://github.com/giyn/doubanmovierecommendationsystem/blob/master/GUI/recommendation.py"
    click Assets "https://github.com/giyn/doubanmovierecommendationsystem/tree/master/MoviePosters/"

    %% Styles
    classDef external fill:#D3D3D3,stroke:#000
    classDef ingestion fill:#FFEEAA,stroke:#000
    classDef datastore fill:#BBEFFF,stroke:#000
    classDef algorithm fill:#FFCC99,stroke:#000
    classDef gui fill:#CCFFCC,stroke:#000
    classDef asset fill:#E5E5E5,stroke:#000
```
