# pellizzetti/php-todo architecture

> Architecture diagram of the GitHub repository pellizzetti/php-todo, 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/pellizzetti/php-todo
- Repository: https://github.com/pellizzetti/php-todo

## Overview

##### Main Components
- Front Controller: Represented by index.php, which acts as the entry point of the application.
- Routing Layer: Found in the routes directory (Router.php and routes.php). This layer is responsible for intercepting incoming HTTP requests and directing them to the appropriate controllers.
- Controllers: The controllers directory contains TaskController.php and TaskListController.php. These handle incoming requests, orchestrate business logic, and interact with models.
- Models: Located in the models directory (Task.php and TaskList.php). They represent the core data entities with their properties corresponding to the database tables.
- Database Layer: The database directory holds classes for database connection (Connection.php) and query building (QueryBuilder.php) along with the SQL schema (sql/phptodo.sql). This layer manages data persistence.
- Views: The views directory and its subdirectories (including assets) contain PHP files for presenting the UI (e.g., add.view.php, edit.view.php, index.view.php) along with supporting CSS, JavaScript, and fonts.

##### Relationships and Data Flow
- That index.php invokes the Router (from routes/Router.php) which matches specific routes defined in routes/routes.php.
- Models utilize the Database layer (Connection, QueryBuilder) to query or update the SQL database (represented by the phptodo.sql schema).
- After data handling, controllers select the proper view (from the views directory) to render the final UI, which is returned to the user.

##### Architectural Patterns & Design Principles
- That the MVC architectural pattern is central by separating concerns:
- Controllers manage business logic.
- Models encapsulate data and database interaction.
- Views handle the user interface.
- Additional annotations highlighting the Front Controller design pattern (using index.php).
- That the Routing layer abstracts the request handling mechanism.

##### Relevant Technologies, Frameworks, or Libraries
- PHP is used as the server-side language.
- The SQL database (presumably MySQL or similar) is used for data storage (schema defined in phptodo.sql).
- Custom-built QueryBuilder and Connection classes imply that the project does not use a ready-made ORM, so point out the custom data abstraction layer.
- Frontend assets (CSS, JS, fonts) are used to enhance UI rendering.

## Diagram (Mermaid)

```mermaid
graph TD
    A("User's Browser"):::external

    subgraph "Front Controller Layer"
        IDX("index.php (Front Controller)"):::front
    end

    subgraph "Routing Layer"
        R1("Router.php"):::router
        R2("routes.php"):::router
    end

    subgraph "Controllers Layer"
        C1("TaskController"):::controller
        C2("TaskListController"):::controller
    end

    subgraph "Models Layer"
        M1("Task Model"):::model
        M2("TaskList Model"):::model
    end

    subgraph "Database Layer"
        DB1("Connection"):::database
        DB2("Query Builder"):::database
        DB3("SQL Schema"):::database
    end

    subgraph "Views Layer"
        V1("Add View"):::view
        V2("Edit View"):::view
        V3("Index View"):::view
        V4("Assets"):::view
    end

    %% Flow Connections
    A --> IDX
    IDX --> R1
    R1 --> R2
    R2 --> C1
    R2 --> C2
    C1 --> M1
    C2 --> M2
    M1 --> DB1
    M1 --> DB2
    M2 --> DB1
    M2 --> DB2
    DB1 --> DB3
    DB2 --> DB3
    C1 <--> V3
    C2 <--> V3

    %% Click Events
    click IDX "https://github.com/pellizzetti/php-todo/blob/master/index.php"
    click R1 "https://github.com/pellizzetti/php-todo/blob/master/routes/Router.php"
    click R2 "https://github.com/pellizzetti/php-todo/blob/master/routes/routes.php"
    click C1 "https://github.com/pellizzetti/php-todo/blob/master/controllers/TaskController.php"
    click C2 "https://github.com/pellizzetti/php-todo/blob/master/controllers/TaskListController.php"
    click M1 "https://github.com/pellizzetti/php-todo/blob/master/models/Task.php"
    click M2 "https://github.com/pellizzetti/php-todo/blob/master/models/TaskList.php"
    click DB1 "https://github.com/pellizzetti/php-todo/blob/master/database/Connection.php"
    click DB2 "https://github.com/pellizzetti/php-todo/blob/master/database/QueryBuilder.php"
    click DB3 "https://github.com/pellizzetti/php-todo/blob/master/database/sql/phptodo.sql"
    click V1 "https://github.com/pellizzetti/php-todo/blob/master/views/add.view.php"
    click V2 "https://github.com/pellizzetti/php-todo/blob/master/views/edit.view.php"
    click V3 "https://github.com/pellizzetti/php-todo/blob/master/views/index.view.php"
    click V4 "https://github.com/pellizzetti/php-todo/tree/master/views/assets"

    %% Styles
    classDef front fill:#cce5ff,stroke:#b8daff,stroke-width:2px,color:#004085;
    classDef router fill:#fff3cd,stroke:#ffeeba,stroke-width:2px,color:#856404;
    classDef controller fill:#d4edda,stroke:#c3e6cb,stroke-width:2px,color:#155724;
    classDef model fill:#f8d7da,stroke:#f5c6cb,stroke-width:2px,color:#721c24;
    classDef database fill:#d1ecf1,stroke:#bee5eb,stroke-width:2px,color:#0c5460;
    classDef view fill:#e2e3e5,stroke:#d6d8db,stroke-width:2px,color:#6c757d;
    classDef external fill:#f0f0f0,stroke:#d0d0d0,stroke-width:2px,color:#000;
```
