# ehmenzala/biblioweb-php architecture

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

- Interactive diagram: https://gitdiagram.com/ehmenzala/biblioweb-php
- Repository: https://github.com/ehmenzala/biblioweb-php

## Overview

##### Project type and purpose
- This is a monolithic, full-stack PHP web application named “Biblioweb,” built on Apache/PHP 8.0. It provides a virtual library interface with an admin dashboard, book search, personal uploads, and a custom REST-style API.

##### File structure
- Top-level PHP entrypoints: index.php and Router.php dispatch all incoming requests.
- “public” directory holds static assets (CSS, JS, images) served directly by Apache.
- “src” directory follows an MVC-like structure:
- api/ApiRouter.php – handles JSON API routes
- controllers/ – HTTP controllers for pages and API
- services/ – business logic layer
- repository/ – data access layer (CRUD with models)
- models/ – data structures/entities
- views/ – HTML templates for each page
- utilities/Authenticator.php – authentication helper
- “db” contains SQL scripts for schema and seed data.

##### README for additional insights
- Confirms features (admin dashboard, search, uploads, custom API) and tech stack (PHP/Apache).

a. Main components
- Client (Browser)
- Web Server (Apache + .htaccess)
- PHP Front Controller (index.php → Router.php)
- MVC Layers:
– Controllers (HTTP and API)
– Services (AuthorService, BookService, etc.)
– Repository (AuthorRepository, BookRepository, etc.)
– Models (Author, Book, Genre, User)
- Views (HTML templates)
- Public Assets (CSS, JS, images)
- Database (MySQL scripts in db/)
- Utilities (Authenticator)
b. Relationships and interactions
- Browser sends HTTP/HTTPS requests → Apache
- Apache routes to index.php (front controller)
- Router dispatches to either ApiRouter (for API) or appropriate Controller
- Controller calls Service layer for business logic
- Service calls Repository to read/write Models to the Database
- Controller renders a View (HTML) or returns JSON (API)
- Static assets bypass PHP and are served directly from public/
c. Architectural patterns and principles
- Front Controller pattern (index.php + Router.php)
- Layered (n-tier) architecture: Presentation (views), Application (controllers), Business (services), Data (repository)
- MVC-inspired separation of concerns
- Repository pattern for DB access
- Single codebase monolith, no microservices
d. Key technologies/frameworks
- PHP 8.0.x
- Apache HTTP Server, .htaccess for URL rewriting
- MySQL (SQL scripts in db/)
- Vanilla JS for dashboard interactivity
- CSS for styling, organized per page in public/css/

##### Elements
- Labels: Browser, Apache, Front Controller, ApiRouter, Controllers, Services, Repositories, Models, Views, Static Assets, Database
- Browser → Apache → Front Controller → Router → Controller → Service → Repository → Database
- Controller → View → Browser
- Browser → Static Assets
- Browser ↔ API endpoints (JSON)
- Web layer (green): Browser, Apache, Front Controller, Router
- Application layer (blue): Controllers, Services, Repository, Models
- Data layer (orange): Database
- Assets layer (gray): CSS/JS/Images
- Utilities (purple): Authenticator

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Web Layer
    Browser["Browser"]:::web
    Apache["Apache HTTP Server"]:::web
    Browser --> Apache
    Apache --> index_php
    Apache --> static_assets

    index_php["index.php"]:::web
    Router["Router.php"]:::web
    index_php --> Router

    %% API Router
    ApiRouter["ApiRouter"]:::web
    Router --> ApiRouter

    %% Controllers Layer
    subgraph "Controllers" 
        direction TB
        AuthorCtrl["AuthorController"]:::app
        BookCtrl["BookController"]:::app
        BookDetailCtrl["BookDetailController"]:::app
        DashboardCtrl["DashboardController"]:::app
        FormCtrl["FormController"]:::app
        GenreCtrl["GenreController"]:::app
        LoginCtrl["LoginController"]:::app
        RatingBookCtrl["RatingBookController"]:::app
    end
    Router --> AuthorCtrl
    Router --> BookCtrl
    Router --> BookDetailCtrl
    Router --> DashboardCtrl
    Router --> FormCtrl
    Router --> GenreCtrl
    Router --> LoginCtrl
    Router --> RatingBookCtrl
    ApiRouter --> AuthorCtrl
    ApiRouter --> BookCtrl
    ApiRouter --> GenreCtrl
    ApiRouter --> RatingBookCtrl

    %% Utilities
    Authenticator["Authenticator"]:::util
    LoginCtrl --> Authenticator
    Authenticator --> DashboardCtrl

    %% Services Layer
    subgraph "Services"
        direction TB
        AuthorSvc["AuthorService"]:::app
        BookSvc["BookService"]:::app
        GenreSvc["GenreService"]:::app
        MainSvc["MainService"]:::app
        UserSvc["UserService"]:::app
    end
    AuthorCtrl --> AuthorSvc
    BookCtrl --> BookSvc
    BookDetailCtrl --> BookSvc
    GenreCtrl --> GenreSvc
    FormCtrl --> MainSvc
    RatingBookCtrl --> BookSvc
    LoginCtrl --> UserSvc
    DashboardCtrl --> MainSvc

    %% Repository Layer
    subgraph "Repositories"
        direction TB
        AuthorRepo["AuthorRepository"]:::app
        BookRepo["BookRepository"]:::app
        GenreRepo["GenreRepository"]:::app
        UserRepo["UserRepository"]:::app
    end
    AuthorSvc --> AuthorRepo
    BookSvc --> BookRepo
    GenreSvc --> GenreRepo
    UserSvc --> UserRepo
    MainSvc --> AuthorRepo
    MainSvc --> BookRepo
    MainSvc --> GenreRepo
    MainSvc --> UserRepo

    %% Models Layer
    subgraph "Models"
        direction TB
        AuthorModel["Author"]:::app
        BookModel["Book"]:::app
        GenreModel["Genre"]:::app
        LoginModel["LoginModel"]:::app
        UserModel["User"]:::app
    end
    AuthorRepo --> AuthorModel
    BookRepo --> BookModel
    GenreRepo --> GenreModel
    UserRepo --> UserModel

    %% Views Layer
    subgraph "Views"
        direction TB
        indexView["index.php"]:::app
        authorsView["authors.php"]:::app
        booksView["books.php"]:::app
        detailView["detalle-libro.php"]:::app
        dashboardView["dashboard.php"]:::app
        ratingView["rating.php"]:::app
        notFoundView["404.html"]:::app
    end
    AuthorCtrl --> authorsView
    BookCtrl --> booksView
    BookDetailCtrl --> detailView
    DashboardCtrl --> dashboardView
    RatingBookCtrl --> ratingView
    FormCtrl --> indexView
    Router --> notFoundView

    %% Static Assets
    subgraph "Public Assets"
        direction TB
        CSS["CSS Stylesheets"]:::assets
        JS["JavaScript"]:::assets
        Img["Images"]:::assets
        Fonts["Fonts"]:::assets
    end
    static_assets["Static Assets"]:::assets
    Browser --> CSS
    Browser --> JS
    Browser --> Img
    Browser --> Fonts

    %% Database Layer
    Database["MySQL Database"]:::data
    dbScripts["DB Scripts"]:::data
    AuthorRepo --> Database
    BookRepo --> Database
    GenreRepo --> Database
    UserRepo --> Database
    Database --> dbScripts

    %% Click Events
    click index_php "https://github.com/ehmenzala/biblioweb-php/blob/main/index.php"
    click Router "https://github.com/ehmenzala/biblioweb-php/blob/main/Router.php"
    click ApiRouter "https://github.com/ehmenzala/biblioweb-php/blob/main/src/api/ApiRouter.php"
    click AuthorCtrl "https://github.com/ehmenzala/biblioweb-php/blob/main/src/controllers/AuthorController.php"
    click BookCtrl "https://github.com/ehmenzala/biblioweb-php/blob/main/src/controllers/BookController.php"
    click BookDetailCtrl "https://github.com/ehmenzala/biblioweb-php/blob/main/src/controllers/BookDetailController.php"
    click DashboardCtrl "https://github.com/ehmenzala/biblioweb-php/blob/main/src/controllers/DashboardController.php"
    click FormCtrl "https://github.com/ehmenzala/biblioweb-php/blob/main/src/controllers/FormController.php"
    click GenreCtrl "https://github.com/ehmenzala/biblioweb-php/blob/main/src/controllers/GenreController.php"
    click LoginCtrl "https://github.com/ehmenzala/biblioweb-php/blob/main/src/controllers/LoginController.php"
    click RatingBookCtrl "https://github.com/ehmenzala/biblioweb-php/blob/main/src/controllers/RatingBookController.php"
    click AuthorSvc "https://github.com/ehmenzala/biblioweb-php/blob/main/src/services/AuthorService.php"
    click BookSvc "https://github.com/ehmenzala/biblioweb-php/blob/main/src/services/BookService.php"
    click GenreSvc "https://github.com/ehmenzala/biblioweb-php/blob/main/src/services/GenreService.php"
    click MainSvc "https://github.com/ehmenzala/biblioweb-php/blob/main/src/services/MainService.php"
    click UserSvc "https://github.com/ehmenzala/biblioweb-php/blob/main/src/services/UserService.php"
    click AuthorRepo "https://github.com/ehmenzala/biblioweb-php/blob/main/src/repository/AuthorRepository.php"
    click BookRepo "https://github.com/ehmenzala/biblioweb-php/blob/main/src/repository/BookRepository.php"
    click GenreRepo "https://github.com/ehmenzala/biblioweb-php/blob/main/src/repository/GenreRepository.php"
    click UserRepo "https://github.com/ehmenzala/biblioweb-php/blob/main/src/repository/UserRepository.php"
    click AuthorModel "https://github.com/ehmenzala/biblioweb-php/blob/main/src/models/Author.php"
    click BookModel "https://github.com/ehmenzala/biblioweb-php/blob/main/src/models/Book.php"
    click GenreModel "https://github.com/ehmenzala/biblioweb-php/blob/main/src/models/Genre.php"
    click LoginModel "https://github.com/ehmenzala/biblioweb-php/blob/main/src/models/LoginModel.php"
    click UserModel "https://github.com/ehmenzala/biblioweb-php/blob/main/src/models/User.php"
    click indexView "https://github.com/ehmenzala/biblioweb-php/blob/main/src/views/index.php"
    click authorsView "https://github.com/ehmenzala/biblioweb-php/blob/main/src/views/authors.php"
    click booksView "https://github.com/ehmenzala/biblioweb-php/blob/main/src/views/books.php"
    click detailView "https://github.com/ehmenzala/biblioweb-php/blob/main/src/views/detalle-libro.php"
    click dashboardView "https://github.com/ehmenzala/biblioweb-php/blob/main/src/views/dashboard.php"
    click ratingView "https://github.com/ehmenzala/biblioweb-php/blob/main/src/views/rating.php"
    click notFoundView "https://github.com/ehmenzala/biblioweb-php/blob/main/src/views/404.html"
    click Authenticator "https://github.com/ehmenzala/biblioweb-php/blob/main/src/utilities/Authenticator.php"
    click CSS "https://github.com/ehmenzala/biblioweb-php/tree/main/public/css/"
    click JS "https://github.com/ehmenzala/biblioweb-php/tree/main/public/js/"
    click Img "https://github.com/ehmenzala/biblioweb-php/tree/main/public/assets/img/"
    click Fonts "https://github.com/ehmenzala/biblioweb-php/tree/main/public/assets/fonts/"
    click dbScripts "https://github.com/ehmenzala/biblioweb-php/tree/main/db/"

    %% Styles
    classDef web fill:#a2f2a2,stroke:#333,stroke-width:1px
    classDef app fill:#a2d2f2,stroke:#333,stroke-width:1px
    classDef data fill:#f2b479,stroke:#333,stroke-width:1px
    classDef assets fill:#d3d3d3,stroke:#333,stroke-width:1px
    classDef util fill:#dca3ff,stroke:#333,stroke-width:1px
```
