# prayesh13/book-recommendation-system architecture

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

- Interactive diagram: https://gitdiagram.com/prayesh13/book-recommendation-system
- Repository: https://github.com/prayesh13/book-recommendation-system

## Overview

##### Project Type & Purpose
- The project is a full-stack web application (backend and web UI) that uses a precomputed collaborative filtering model to recommend books.
- Its primary purpose is to display popular books and provide book recommendations based on user input by leveraging CSV-based datasets and pre-trained models (stored as joblib files).

##### Key Components
a. User Interface:
- Web browser or client interacting with the system.
- The UI is built with HTML templates (found in the “templates” directory) and styled with Bootstrap.

b. Flask Application Backend:
- This is the central component represented by “app.py”.
- It handles user requests, processes inputs, and serves the web pages.
- It interacts with the data/model components to fetch recommendations.

c. Data & Model Layer:
- Data sources, specifically:
- The “book-recommendation-dataset” directory containing CSV files (Books.csv, Ratings.csv, and Users.csv). These files hold raw data about books and user ratings.
- The “model” directory housing precomputed model files (books.joblib, popular.joblib, pt.joblib, similarity_scores.joblib) used to perform the collaborative filtering and similarity calculations.
- “books_data.py” script which likely encapsulates data access or processing logic that bridges raw CSV data and the recommendation process.

d. Static Assets:
- “static” directory (with subdirectories like “images”) used to serve static resources (CSS, images, JS) for the web interface.

##### Relationships & Data Flow
- Within the backend:
- That “app.py” communicates with the Data & Model Layer (via “books_data.py” and the model’s joblib files) to retrieve relevant data and computed similarity scores.
- That the backend uses data from the CSV dataset and the pre-trained models to execute the recommendation algorithm.

##### Architectural Patterns & Design Principles
- The architecture follows an MVC-like pattern:
- The “Templates” (View) provide the front-end UI.
- The “Flask Application” (Controller) handles requests and business logic.
- The “Data & Model Layer” (Model) manages the recommendation logic and data persistence.
- The separation of concerns is clear between the presentation layer, application logic, and data processing layer.
- That the precomputed similarity scores and joblib models enable fast and efficient recommendation retrieval, reducing runtime computation.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Presentation Layer"
        UI["User Interface (Browser)"]:::frontend
        Templates["HTML Templates"]:::frontend
        Static["Static Assets"]:::frontend
    end

    subgraph "Business Logic"
        Flask["Flask Web Server (app.py)"]:::backend
        DataProc["Data Processing Module (books_data.py)"]:::backend
    end

    subgraph "Data & Model Layer"
        Datasets["Datasets (CSV Files)"]:::data
        Models["Pre-trained Models (Joblib Files)"]:::data
    end

    UI -->|"SendsHTTPrequest"| Flask
    Flask -->|"DelegatesRequest"| DataProc
    DataProc -->|"ReadsCSVdata"| Datasets
    DataProc -->|"LoadsModels"| Models
    DataProc -->|"ReturnsRecommendations"| Flask
    Flask -->|"RendersUsing"| Templates
    Flask -->|"LoadsAssets"| Static
    Templates -->|"RendersPageTo"| UI

    classDef frontend fill:#add8e6,stroke:#000,stroke-width:2px;
    classDef backend fill:#90ee90,stroke:#000,stroke-width:2px;
    classDef data fill:#ffcc99,stroke:#000,stroke-width:2px;

    click Templates "https://github.com/prayesh13/book-recommendation-system/tree/master/templates/"
    click Static "https://github.com/prayesh13/book-recommendation-system/tree/master/static/"
    click Flask "https://github.com/prayesh13/book-recommendation-system/blob/master/app.py"
    click DataProc "https://github.com/prayesh13/book-recommendation-system/blob/master/books_data.py"
    click Datasets "https://github.com/prayesh13/book-recommendation-system/tree/master/book-recommendation-dataset/"
    click Models "https://github.com/prayesh13/book-recommendation-system/tree/master/model/"
```
