# duh-git/php architecture

> Architecture diagram of the GitHub repository duh-git/php, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/duh-git/php
- Repository: https://github.com/duh-git/php

## Overview

##### Project Type Analysis
This is a custom PHP MVC framework with a focus on article management, user authentication, and commenting functionality. It follows classic MVC architectural patterns with additional services.

##### Main Components

A. Core Framework Layer:
- Three main sub-components:
- Controllers (AbstractController + specific controllers)
- Models (ActiveRecordEntity + domain models)
- View (View component)

B. Service Layer:
- Database Service (Db.php)
- Email Service (EmailSender.php)
- Authentication Services (UsersAuthService, UserActivationService)

C. Data Layer:
- A Database component
- Connection to ActiveRecordEntity

D. Presentation Layer:
- Templates container showing the template hierarchy
- Static assets (CSS)

##### Component Relationships

- HTTP Request → Front Controller (index.php)
- Front Controller → Router (routes.php)
- Router → Specific Controllers
- Controllers → Models
- Controllers → View
- View → Templates
- Models → Database Service
- Services → External Systems (Email)

##### Detailed Component Breakdown

A. Controllers Section:
- Controllers
- AbstractController
- ArticlesController
- CommentsController
- MainController
- UsersController

B. Models Section:
- Models
- ActiveRecordEntity
- Articles
- Comments
- Users

C. Services Section:
- Services
- Db
- EmailSender
- User Services

##### Additional Elements

Specific elements:
- Exception handling flow (DbException, NotFoundException, etc.)
- User authentication flow
- Template rendering pipeline
- Database interaction pattern through ActiveRecordEntity

##### Key Architectural Patterns to Highlight

- Active Record pattern for database interactions
- Template method pattern in AbstractController
- Service layer pattern for cross-cutting concerns
- Front Controller pattern (index.php)

##### Important Notes

- Notes about the PHP 7.2+ requirement
- Database configuration location (settings.php)
- Relationship between .htaccess and request routing

Remember to include version information and any relevant notes about the local web server requirements mentioned in the README.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Entry Points"
        HTTP[HTTP Request]
        FC[Front Controller]:::entry
        Router[Router]:::entry
    end

    subgraph "MVC Core Framework"
        subgraph "Controllers"
            AC[Abstract Controller]:::controller
            ArtC[Articles Controller]:::controller
            ComC[Comments Controller]:::controller
            MainC[Main Controller]:::controller
            UsersC[Users Controller]:::controller
        end

        subgraph "Models"
            ARE[Active Record Entity]:::model
            Art[Articles]:::model
            Com[Comments]:::model
            Users[Users]:::model
        end

        View[View Component]:::view
    end

    subgraph "Service Layer"
        DB[Database Service]:::service
        Email[Email Service]:::service
        Auth[Authentication Service]:::service
        UserAct[User Activation Service]:::service
    end

    subgraph "Data Layer"
        Database[(Database)]:::database
        DBConfig[Database Config]:::config
    end

    subgraph "Presentation Layer"
        Templates[Templates]:::ui
        CSS[Static Assets]:::ui
    end

    subgraph "Exception Handling"
        DBEx[Database Exception]:::error
        NotFound[Not Found Exception]:::error
        InvalidArg[Invalid Argument Exception]:::error
    end

    %% Relationships
    HTTP --> FC
    FC --> Router
    Router --> AC
    AC --> |Extends| ArtC
    AC --> |Extends| ComC
    AC --> |Extends| MainC
    AC --> |Extends| UsersC
    AC --> View
    View --> Templates
    Templates --> CSS
    ARE --> DB
    DB --> Database
    DB --> DBConfig
    Auth --> Email
    UserAct --> Email
    ArtC & ComC & MainC & UsersC --> ARE
    ARE --> Art & Com & Users
    AC --> |Throws| DBEx & NotFound & InvalidArg

    %% Styles
    classDef entry fill:#e1f5fe,stroke:#01579b
    classDef controller fill:#bbdefb,stroke:#1976d2
    classDef model fill:#c8e6c9,stroke:#388e3c
    classDef view fill:#fff9c4,stroke:#fbc02d
    classDef service fill:#d1c4e9,stroke:#512da8
    classDef database fill:#ffccbc,stroke:#e64a19
    classDef config fill:#cfd8dc,stroke:#455a64
    classDef ui fill:#f8bbd0,stroke:#c2185b
    classDef error fill:#ffcdd2,stroke:#c62828

    %% Click Events
    click FC "https://github.com/duh-git/php/blob/main/www/index.php"
    click Router "https://github.com/duh-git/php/blob/main/src/routes.php"
    click AC "https://github.com/duh-git/php/tree/main/src/MyProject/Controllers/"
    click ARE "https://github.com/duh-git/php/blob/main/src/MyProject/Models/ActiveRecordEntity.php"
    click View "https://github.com/duh-git/php/blob/main/src/MyProject/View/View.php"
    click DB "https://github.com/duh-git/php/blob/main/src/MyProject/Services/Db.php"
    click Email "https://github.com/duh-git/php/blob/main/src/MyProject/Services/EmailSender.php"
    click Auth "https://github.com/duh-git/php/blob/main/src/MyProject/Models/Users/UsersAuthService.php"
    click UserAct "https://github.com/duh-git/php/blob/main/src/MyProject/Models/Users/UserActivationService.php"
    click DBConfig "https://github.com/duh-git/php/blob/main/src/settings.php"
    click Templates "https://github.com/duh-git/php/tree/main/templates/"
    click CSS "https://github.com/duh-git/php/blob/main/styles/styles.css"
    click DBEx "https://github.com/duh-git/php/blob/main/src/MyProject/Exceptions/DbException.php"
    click NotFound "https://github.com/duh-git/php/blob/main/src/MyProject/Exceptions/NotFoundException.php"
    click InvalidArg "https://github.com/duh-git/php/blob/main/src/MyProject/Exceptions/InvalidArgumentException.php"
```
