# hamzaavvan/library-management-system architecture

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

- Interactive diagram: https://gitdiagram.com/hamzaavvan/library-management-system
- Repository: https://github.com/hamzaavvan/library-management-system

## Overview

##### Project type and purpose
- This is a **full‑stack web application** built in Python/Flask for library management (users, books, admin).
- It follows an **MVC/DAO pattern**:
– Models (data access) live under `Models/`
– Controllers (business logic) live under `Controllers/`
– Views (HTML) live under `templates/` with Jinja2 rendering

##### File structure
Top‑level components:
- `app.py` – Flask entry point, registers routes/blueprints
- `routes/` – Defines HTTP endpoints per domain (admin, book, user)
- `Controllers/` – Implements managers: `AdminManager`, `BookManager`, `UserManager`
- `App/` – Domain entities or service classes (`Actor.py`, `Books.py`, etc.)
- `Models/` – DAO layer: generic `DAO.py`, `DB.py`, `AdminDAO.py`, `BookDAO.py`, `UserDAO.py`
- `static/` & `templates/` – Frontend assets and Jinja2 templates
- `db/` – SQL schema (`lms.sql`)
- `requirements.txt` – Flask, MySQL connector, and other dependencies

##### README for additional insights
- Confirms Flask + MySQL service
- No external microservices—entire stack lives in one process + a MySQL database
- Dev workflow: set environment variables, `flask run`

##### Main components
A. Client (Browser)
B. Flask Application Server
1. HTTP Router (Flask’s `routes/`)
2. Controller Layer (`Controllers/`)
3. Domain/Service Layer (`App/`)
4. Data Access Layer (`Models/` + `db/` schema)
5. Templating Engine (Jinja2 in `templates/`)
6. Static File Server (`static/`)
C. MySQL Database (external service)

##### Relationships and data flows
- Browser → HTTP Request → Flask Router (`routes/`)
- Router extracts URL, dispatches to corresponding Controller
- Controller calls Domain/Service classes in `App/` → applies business rules
- Service classes invoke DAO methods in `Models/` → run SQL against MySQL
- DAO returns records → back up through Service → Controller
- Controller passes data to Jinja2 Templates → rendered HTML
- Flask returns HTML/JSON → Browser
- Static assets (CSS/JS/Images) served directly by Flask’s static handler

##### Architectural patterns & design principles
- MVC with clear separation of concerns
- DAO pattern for database interaction
- Layered architecture: Presentation → Business → Data Access → Persistence
- Blueprints or modular routing (`routes/`) for domain separation

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Client
    Browser["Browser"]:::presentation

    %% Flask Application Container
    subgraph "Flask App Container"
        direction TB

        %% Entry Point
        EntryPoint["Flask Entry Point\napp.py"]:::config

        %% Presentation Layer
        subgraph "Presentation Layer"
            direction TB
            Router["HTTP Router\nroutes/"]:::presentation
            Templates["Jinja2 Templates\ntemplates/"]:::presentation
            StaticFiles["Static File Server\nstatic/"]:::presentation
        end

        %% Application Layer
        subgraph "Application Layer"
            direction TB
            Controllers["Controller Layer\nControllers/"]:::business
            Services["Domain/Service Layer\nApp/"]:::business
        end

        %% Data Access Layer
        subgraph "Data Access Layer"
            direction TB
            DAO["DAO Layer\nModels/"]:::dataaccess
            DBConn["DB Connection\nModels/DB.py"]:::dataaccess
        end
    end

    %% Persistence Layer
    MySQL["MySQL Database\ndb/lms.sql"]:::database

    %% Relationships
    Browser -->|HTTP Request| EntryPoint
    EntryPoint -->|registers routes| Router
    Router -->|dispatch to controller| Controllers
    Controllers -->|use services| Services
    Services -->|invoke DAO| DAO
    DAO -->|run SQL| MySQL
    MySQL -->|return data| DAO
    DAO -->|return records| Services
    Services -->|return to controller| Controllers
    Controllers -->|render_template| Templates
    Templates -->|HTML Response| Browser
    StaticFiles -->|serve assets| Browser

    %% Click Events
    click EntryPoint "https://github.com/hamzaavvan/library-management-system/blob/master/app.py"
    click Router "https://github.com/hamzaavvan/library-management-system/tree/master/routes/"
    click Templates "https://github.com/hamzaavvan/library-management-system/tree/master/templates/"
    click StaticFiles "https://github.com/hamzaavvan/library-management-system/tree/master/static/"
    click Controllers "https://github.com/hamzaavvan/library-management-system/tree/master/Controllers/"
    click Services "https://github.com/hamzaavvan/library-management-system/tree/master/App/"
    click DAO "https://github.com/hamzaavvan/library-management-system/tree/master/Models/"
    click DBConn "https://github.com/hamzaavvan/library-management-system/blob/master/Models/DB.py"
    click MySQL "https://github.com/hamzaavvan/library-management-system/blob/master/db/lms.sql"

    %% Styles
    classDef presentation fill:#B3E5FC,stroke:#0288D1,stroke-width:1px;
    classDef business fill:#C8E6C9,stroke:#2E7D32,stroke-width:1px;
    classDef dataaccess fill:#FFECB3,stroke:#FFB300,stroke-width:1px;
    classDef database fill:#FFCDD2,stroke:#C62828,stroke-width:1px;
    classDef config fill:#E0E0E0,stroke:#616161,stroke-width:1px;
```
