# chentim1011/dbms-final-backend architecture

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

- Interactive diagram: https://gitdiagram.com/chentim1011/dbms-final-backend
- Repository: https://github.com/chentim1011/dbms-final-backend

## Overview

##### Project Type and Purpose
- This is a monolithic full-stack Book Management System.
- Purpose: Let users add, view, search, and annotate books and authors; track reading history and plans; manage notes and favorites; store and view PDFs.

##### File Structure
- Top‐level folders:
- backend/ – Flask application code, route handlers, configuration, database modules, uploads.
- frontend/ – Static HTML pages (index.html, notes.html).
- PDF/ – Design documents (DB schema, ER model, system spec).
- backend/app.py: Entry point for Flask server.
- backend/config.py: Flask and database configuration.
- backend/database.py: SQLite connection and helper methods.
- backend/routes/*.py: One module per resource (books, authors, notes, etc.).
- backend/uploads/: File storage for uploaded PDFs.
- SQLite database file: backend/library.db.

##### README
- Confirms Flask + SQLite stack.
- Lists tables (Book, ReadingHistory, ReadingPlan, Note, FavoriteList, Author) and indexes.
- Describes each backend feature and CRUD endpoints.

##### Components
a. Frontend (Client Browser)
- Static HTML (index.html, notes.html), JavaScript (if any), CSS.
- User actions: search books, view/add notes, upload PDFs, etc.
b. Backend (Flask Application)
- app.py (Flask app)
- config.py (settings)
- database.py (DB connection)
- routes/ (REST endpoints for books, authors, history, plans, notes, favorites, search)
c. Database (SQLite)
- Tables: Book, Author, ReadingHistory, ReadingPlan, Note, FavoriteList
- Indexes for performance
d. File Storage
- uploads/ directory containing PDF files
e. External Clients/Services
- Web browser only (no third-party APIs in current scope)

##### Relationships and Data Flows
- In Backend:
- Routes modules handle HTTP and call database.py for SQL operations.
- config.py provides DB path and upload folder.
- Backend → SQLite: SQL queries (CRUD) to tables; index usage speeds lookups.
- Backend ↔ File Storage: Read/write PDF files on upload/view.
- Backend returns JSON or file streams to frontend.
- Frontend renders data and PDF embeds.

##### Architectural Patterns & Design Principles
- Monolithic MVC-style layering:
- Routes = Controllers
- database.py + SQL scripts = Model
- frontend HTML = View
- Single process Flask server, no microservices.
- Separation of concerns: config, database access, route logic, file storage.

##### Relevant Technologies & Libraries
- Flask (Python)
- SQLite (embedded DB)
- Jinja2 or static HTML for views
- Standard Python modules for file I/O

## Diagram (Mermaid)

```mermaid
graph TD
    %% Frontend Layer
    subgraph "Frontend (Client Browser)"
        direction TB
        UI_Index["index.html"]:::frontend
        UI_Notes["notes.html"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend (Flask App)"
        direction TB
        App["app.py"]:::backend
        Config["config.py"]:::backend
        DBConn["database.py"]:::backend

        subgraph "Routes (Controllers)"
            direction TB
            AuthorRoute["author.py"]:::backend
            BooksRoute["books.py"]:::backend
            FavoritesRoute["favorites.py"]:::backend
            NotesRoute["notes.py"]:::backend
            HistoryRoute["reading_history.py"]:::backend
            PlanRoute["reading_plan.py"]:::backend
            SearchRoute["search.py"]:::backend
        end

        subgraph "SQL Initialization Scripts"
            direction TB
            InitAuthor["insert_author.sql"]:::backend
            InitBook["insert_book.sql"]:::backend
        end
    end

    %% Data Stores Layer
    subgraph "Data Stores"
        direction TB
        SQLiteDB["SQLite Database\n(library.db)"]:::storage
        Uploads["uploads/"]:::storage
        subgraph "Design Documents"
            direction TB
            DBDoc["DB Schema.pdf"]:::storage
            ERDoc["ER-Model.pdf"]:::storage
            SpecDoc["System.pdf"]:::storage
        end
    end

    %% Connections
    UI_Index -->|"HTTP GET/POST"| App
    UI_Notes -->|"HTTP GET/POST"| App

    App -->|uses| Config
    App -->|connects| DBConn
    App -->|routes to| AuthorRoute
    App -->|routes to| BooksRoute
    App -->|routes to| FavoritesRoute
    App -->|routes to| NotesRoute
    App -->|routes to| HistoryRoute
    App -->|routes to| PlanRoute
    App -->|routes to| SearchRoute

    DBConn -->|executes SQL| SQLiteDB
    DBConn -->|initializes via| InitAuthor
    DBConn -->|initializes via| InitBook

    App -->|read/write| Uploads
    Uploads -->|serves PDF| App

    App -->|returns JSON/file| UI_Index
    App -->|returns JSON/file| UI_Notes

    %% Click Events
    click UI_Index "https://github.com/chentim1011/dbms-final-backend/blob/main/frontend/index.html"
    click UI_Notes "https://github.com/chentim1011/dbms-final-backend/blob/main/frontend/notes.html"
    click App "https://github.com/chentim1011/dbms-final-backend/blob/main/backend/app.py"
    click Config "https://github.com/chentim1011/dbms-final-backend/blob/main/backend/config.py"
    click DBConn "https://github.com/chentim1011/dbms-final-backend/blob/main/backend/database.py"
    click InitAuthor "https://github.com/chentim1011/dbms-final-backend/blob/main/backend/insert_author.sql"
    click InitBook "https://github.com/chentim1011/dbms-final-backend/blob/main/backend/insert_book.sql"
    click SQLiteDB "https://github.com/chentim1011/dbms-final-backend/blob/main/backend/library.db"
    click AuthorRoute "https://github.com/chentim1011/dbms-final-backend/blob/main/backend/routes/author.py"
    click BooksRoute "https://github.com/chentim1011/dbms-final-backend/blob/main/backend/routes/books.py"
    click FavoritesRoute "https://github.com/chentim1011/dbms-final-backend/blob/main/backend/routes/favorites.py"
    click NotesRoute "https://github.com/chentim1011/dbms-final-backend/blob/main/backend/routes/notes.py"
    click HistoryRoute "https://github.com/chentim1011/dbms-final-backend/blob/main/backend/routes/reading_history.py"
    click PlanRoute "https://github.com/chentim1011/dbms-final-backend/blob/main/backend/routes/reading_plan.py"
    click SearchRoute "https://github.com/chentim1011/dbms-final-backend/blob/main/backend/routes/search.py"
    click Uploads "https://github.com/chentim1011/dbms-final-backend/tree/main/backend/uploads/"
    click DBDoc "https://github.com/chentim1011/dbms-final-backend/blob/main/PDF/DB Schema.pdf"
    click ERDoc "https://github.com/chentim1011/dbms-final-backend/blob/main/PDF/ER-Model.pdf"
    click SpecDoc "https://github.com/chentim1011/dbms-final-backend/blob/main/PDF/System.pdf"

    %% Styles
    classDef frontend fill:#e0f7da,stroke:#2d7a2d,stroke-width:1px
    classDef backend fill:#d0e7f9,stroke:#1f5fa6,stroke-width:1px
    classDef storage fill:#ffe5b4,stroke:#cc7a00,stroke-width:1px
```
