# fatibelkoudia/gestion-des-livres architecture

> Architecture diagram of the GitHub repository fatibelkoudia/gestion-des-livres, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-10-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/fatibelkoudia/gestion-des-livres
- Repository: https://github.com/fatibelkoudia/gestion-des-livres

## Overview

##### Project Type and Purpose
- This is a full-stack Java web application for managing a library’s books and authors.
- It follows an MVC pattern using Servlets, JSPs, a Filter for authentication, and Hibernate for persistence.
- A MySQL database (schema in gr1Tp1Db.sql) stores users, roles, authors, books, genres, editors.

##### Key Components from File Structure
- Presentation Layer (src/main/webapp)
- JSPs under WEB-INF/views: forms and lists for “auteur” and “livre”
- Static resources (CSS) under /resources
- web.xml: servlet and filter declarations
- Controller Layer (src/main/java/com/tima/tp1/controller)
- LoginServlet, LogoutServlet
- Subpackages “auteur” and “livre” each with servlets for List, New, Add, Edit, Update, Delete
- Filter (src/main/java/com/tima/tp1/filter/AuthenticationFilter.java)
- Intercepts requests to enforce Admin vs Visiteur roles
- Business/Data Access Layer (src/main/java/com/tima/tp1/dao)
- Generic interface IGenericDao
- AuteurDao, LivreDao, UserDao implementing CRUD via Hibernate
- Model Layer (src/main/java/com/tima/tp1/model)
- Entity classes: User, Role, Auteur, Livre, Genre, Editeur
- Persistence Utility (src/main/java/com/tima/tp1/utils/HibernateUtil.java)
- Builds SessionFactory, manages Hibernate sessions
- Database (MySQL)
- Schema and initial data in gr1Tp1Db.sql
- Runtime Environment
- Servlet container (e.g., Tomcat)
- Hibernate 5.x, JPA, MySQL Connector, Jakarta APIs

##### Relationships and Data Flows
- Browser → HTTP requests → AuthenticationFilter → Servlet controllers
- Controller → calls appropriate DAO → HibernateUtil → MySQL DB
- Controller → selects JSP view → HTTP response back to browser
- LoginServlet uses UserDao to validate credentials and assign session roles

##### Architectural Patterns & Principles
- MVC separation:
- Model (entities + DAOs)
- View (JSPs, CSS)
- Controller (Servlets)
- Filter pattern for cross-cutting authentication logic
- DAO pattern for data access
- Utility class for singleton SessionFactory (HibernateUtil)
- Role-based access control (Admin vs Visiteur)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    Browser["Web Browser"]:::client
    Browser -->|HTTP Request| Filter["AuthenticationFilter\n(Servlet 3.0)"]:::server

    %% Controller Layer
    subgraph "Controller Layer"
        Login["LoginServlet\n(Servlet 3.0)"]:::server
        Logout["LogoutServlet\n(Servlet 3.0)"]:::server
        subgraph "Auteur Controllers"
            LA["ListAuteurServlet"]:::server
            FNA["FormNewAuteurServlet"]:::server
            AUA["AddAuteurServlet"]:::server
            FEA["FormEditAuteurServlet"]:::server
            UPA["UpdateAuteurServlet"]:::server
            DEA["DeleteAuteurServlet"]:::server
        end
        subgraph "Livre Controllers"
            LL["ListLivreServlet"]:::server
            FNL["FormNewLivreServlet"]:::server
            AUL["AddLivreServlet"]:::server
            FEL["FormEditLivreServlet"]:::server
            UPL["UpdateLivreServlet"]:::server
            DEL["DeleteLivreServlet"]:::server
        end
    end

    Filter -->|forwards to| Login
    Filter -->|forwards to| Logout
    Filter -->|forwards to| LA
    Filter -->|forwards to| FNA
    Filter -->|forwards to| AUA
    Filter -->|forwards to| FEA
    Filter -->|forwards to| UPA
    Filter -->|forwards to| DEA
    Filter -->|forwards to| LL
    Filter -->|forwards to| FNL
    Filter -->|forwards to| AUL
    Filter -->|forwards to| FEL
    Filter -->|forwards to| UPL
    Filter -->|forwards to| DEL

    %% Presentation Layer
    subgraph "Presentation Layer"
        JSP1["auteur-list.jsp"]:::view
        JSP2["auteur-form.jsp"]:::view
        JSP3["livre-list.jsp"]:::view
        JSP4["livre-form.jsp"]:::view
        CSS1["style.css"]:::static
        CSS2["icon.css"]:::static
        XML["web.xml"]:::server
    end

    Login -->|forward to| JSP1
    Login -->|forward to| JSP2
    Login -->|forward to| JSP3
    Login -->|forward to| JSP4
    JSP1 -->|HTTP Response| Browser
    JSP2 -->|HTTP Response| Browser
    JSP3 -->|HTTP Response| Browser
    JSP4 -->|HTTP Response| Browser

    %% DAO Layer
    subgraph "DAO Layer"
        IGen["IGenericDao<T>"]:::server
        AD["AuteurDao\n(Hibernate)"]:::server
        LD["LivreDao\n(Hibernate)"]:::server
        UD["UserDao\n(Hibernate)"]:::server
    end

    LA -->|calls DAO| AD
    FNA -->|calls DAO| AD
    AUA -->|calls DAO| AD
    FEA -->|calls DAO| AD
    UPA -->|calls DAO| AD
    DEA -->|calls DAO| AD

    LL -->|calls DAO| LD
    FNL -->|calls DAO| LD
    AUL -->|calls DAO| LD
    FEL -->|calls DAO| LD
    UPL -->|calls DAO| LD
    DEL -->|calls DAO| LD

    Login -->|calls DAO| UD
    Logout -->|calls DAO| UD

    AD -->|implements| IGen
    LD -->|implements| IGen
    UD -->|implements| IGen

    %% Persistence Utility
    subgraph "Persistence Utility"
        HU["HibernateUtil\n(Singleton)"]:::server
    end

    IGen -->|uses| HU

    %% Database
    subgraph "Database"
        DB["MySQL Database\n(MySQL 8.x)"]:::db
    end

    HU -->|Hibernate Session| DB

    %% Click Events
    click JSP1 "https://github.com/fatibelkoudia/gestion-des-livres/blob/main/src/main/webapp/WEB-INF/views/auteur-list.jsp"
    click JSP2 "https://github.com/fatibelkoudia/gestion-des-livres/blob/main/src/main/webapp/WEB-INF/views/auteur-form.jsp"
    click JSP3 "https://github.com/fatibelkoudia/gestion-des-livres/blob/main/src/main/webapp/WEB-INF/views/livre-list.jsp"
    click JSP4 "https://github.com/fatibelkoudia/gestion-des-livres/blob/main/src/main/webapp/WEB-INF/views/livre-form.jsp"
    click CSS1 "https://github.com/fatibelkoudia/gestion-des-livres/blob/main/src/main/webapp/resources/style.css"
    click CSS2 "https://github.com/fatibelkoudia/gestion-des-livres/blob/main/src/main/webapp/resources/icon.css"
    click XML "https://github.com/fatibelkoudia/gestion-des-livres/blob/main/src/main/webapp/WEB-INF/web.xml"
    click Login "https://github.com/fatibelkoudia/gestion-des-livres/blob/main/src/main/java/com/tima/tp1/controller/LoginServlet.java"
    click Logout "https://github.com/fatibelkoudia/gestion-des-livres/blob/main/src/main/java/com/tima/tp1/controller/LogoutServlet.java"
    click LA "https://github.com/fatibelkoudia/gestion-des-livres/blob/main/src/main/java/com/tima/tp1/controller/auteur/ListAuteurServlet.java"
    click FNA "https://github.com/fatibelkoudia/gestion-des-livres/blob/main/src/main/java/com/tima/tp1/controller/auteur/FormNewAuteurServlet.java"
    click AUA "https://github.com/fatibelkoudia/gestion-des-livres/blob/main/src/main/java/com/tima/tp1/controller/auteur/AddAuteurServlet.java"
    click FEA "https://github.com/fatibelkoudia/gestion-des-livres/blob/main/src/main/java/com/tima/tp1/controller/auteur/FormEditAuteurServlet.java"
    click UPA "https://github.com/fatibelkoudia/gestion-des-livres/blob/main/src/main/java/com/tima/tp1/controller/auteur/UpdateAuteurServlet.java"
    click DEA "https://github.com/fatibelkoudia/gestion-des-livres/blob/main/src/main/java/com/tima/tp1/controller/auteur/DeleteAuteurServlet.java"
    click LL "https://github.com/fatibelkoudia/gestion-des-livres/blob/main/src/main/java/com/tima/tp1/controller/livre/ListLivreServlet.java"
    click FNL "https://github.com/fatibelkoudia/gestion-des-livres/blob/main/src/main/java/com/tima/tp1/controller/livre/FormNewLivreServlet.java"
    click AUL "https://github.com/fatibelkoudia/gestion-des-livres/blob/main/src/main/java/com/tima/tp1/controller/livre/AddLivreServlet.java"
    click FEL "https://github.com/fatibelkoudia/gestion-des-livres/blob/main/src/main/java/com/tima/tp1/controller/livre/FormEditLivreServlet.java"
    click UPL "https://github.com/fatibelkoudia/gestion-des-livres/blob/main/src/main/java/com/tima/tp1/controller/livre/UpdateLivreServlet.java"
    click DEL "https://github.com/fatibelkoudia/gestion-des-livres/blob/main/src/main/java/com/tima/tp1/controller/livre/DeleteLivreServlet.java"
    click Filter "https://github.com/fatibelkoudia/gestion-des-livres/blob/main/src/main/java/com/tima/tp1/filter/AuthenticationFilter.java"
    click IGen "https://github.com/fatibelkoudia/gestion-des-livres/blob/main/src/main/java/com/tima/tp1/dao/IGenericDao.java"
    click AD "https://github.com/fatibelkoudia/gestion-des-livres/blob/main/src/main/java/com/tima/tp1/dao/AuteurDao.java"
    click LD "https://github.com/fatibelkoudia/gestion-des-livres/blob/main/src/main/java/com/tima/tp1/dao/LivreDao.java"
    click UD "https://github.com/fatibelkoudia/gestion-des-livres/blob/main/src/main/java/com/tima/tp1/dao/UserDao.java"
    click HU "https://github.com/fatibelkoudia/gestion-des-livres/blob/main/src/main/java/com/tima/tp1/utils/HibernateUtil.java"

    %% Styles
    classDef client fill:#cccccc,stroke:#333,stroke-width:1px
    classDef server fill:#b3d9ff,stroke:#333,stroke-width:1px
    classDef view fill:#ffd699,stroke:#333,stroke-width:1px
    classDef static fill:#ffe0b3,stroke:#333,stroke-width:1px
    classDef db fill:#ccffcc,stroke:#333,stroke-width:1px
```
