# delight-im/php-auth architecture

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

- Interactive diagram: https://gitdiagram.com/delight-im/php-auth
- Repository: https://github.com/delight-im/php-auth

## Overview

a. Registration Flow
- Input validation
- Password hashing (bcrypt)
- Email verification system
- Database storage

b. Login Flow
- Credential verification
- Session management
- Remember-me functionality
- Rate limiting/throttling

c. Password Reset Flow
- Request initiation
- Token generation
- Verification process
- Password update

##### Security Features (Use distinctive markers)

- Session management
- Cookie handling
- Rate limiting
- Password hashing
- Email verification
- Role-based access control

##### Integration Points (Use interface symbols)

- PDO database connection
- Session interface
- Cookie management
- External email service integration

Design Guidelines:

##### Key Elements to Highlight
- Session management flow
- Role-based access control system
- Password reset mechanism
- Email verification system
- Remember-me functionality
- Rate limiting/throttling system

##### Additional Details
- Supported database types
- PHP version requirements
- Security-critical paths
- Error handling flows

##### Security-First Design
- Multiple security layers
- Encryption/hashing points
- Authentication checkpoints

##### Modularity
- Clear separation of concerns
- Independent components
- Pluggable database support

##### Scalability
- Database abstraction layer
- Throttling mechanism
- Session management

##### Integration Flexibility
- Framework-agnostic design
- External service hooks
- Custom implementation points

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Core["Main Authentication Layer"]
        Auth["Auth Controller"]
        UserMgr["User Operations Handler"]
        Admin["Admin Operations Handler"]
        RoleMgr["Role Management"]
        StatusMgr["Status Management"]
    end

    subgraph Security["Security Features"]
        Session["Session Management"]
        Cookie["Cookie Handling"]
        RateLimit["Rate Limiting"]
        PwdHash["Password Hashing"]
        EmailVerif["Email Verification"]
        RBAC["Role-Based Access"]
    end

    subgraph DB["Database Layer"]
        PDO["PDO Interface"]
        MySQL["MySQL/MariaDB"]
        PostgreSQL["PostgreSQL"]
        SQLite["SQLite"]
        
        subgraph Tables["Database Tables"]
            Users["users"]
            UsersRemembered["users_remembered"]
            UsersResets["users_resets"]
            UsersThrottling["users_throttling"]
        end
    end

    subgraph Exceptions["Exception Handling Layer"]
        AuthExc["Authentication Exceptions"]
        AuthErr["Authentication Errors"]
        DBErr["Database Errors"]
        RateLimitExc["Rate Limiting Exceptions"]
        TwoFactorExc["2FA Exceptions"]
        UserMgmtExc["User Management Exceptions"]
        PwdExc["Password Exceptions"]
        EmailExc["Email Exceptions"]
    end

    Auth --> UserMgr
    Auth --> Admin
    Auth --> RoleMgr
    Auth --> StatusMgr
    Auth --> Security
    UserMgr --> Security
    Admin --> Security

    Security --> PDO
    PDO --> MySQL
    PDO --> PostgreSQL
    PDO --> SQLite

    MySQL --> Tables
    PostgreSQL --> Tables
    SQLite --> Tables

    Auth -.-> Exceptions
    UserMgr -.-> Exceptions
    Admin -.-> Exceptions
    Security -.-> Exceptions

    %% Click events for component mapping
    click Auth "https://github.com/delight-im/PHP-Auth/blob/master/src/Auth.php"
    click UserMgr "https://github.com/delight-im/PHP-Auth/blob/master/src/UserManager.php"
    click Admin "https://github.com/delight-im/PHP-Auth/blob/master/src/Administration.php"
    click RoleMgr "https://github.com/delight-im/PHP-Auth/blob/master/src/Role.php"
    click StatusMgr "https://github.com/delight-im/PHP-Auth/blob/master/src/Status.php"
    click MySQL "https://github.com/delight-im/PHP-Auth/blob/master/Database/MySQL.sql"
    click PostgreSQL "https://github.com/delight-im/PHP-Auth/blob/master/Database/PostgreSQL.sql"
    click SQLite "https://github.com/delight-im/PHP-Auth/blob/master/Database/SQLite.sql"
    click AuthExc "https://github.com/delight-im/PHP-Auth/blob/master/src/AuthException.php"
    click AuthErr "https://github.com/delight-im/PHP-Auth/blob/master/src/AuthError.php"
    click DBErr "https://github.com/delight-im/PHP-Auth/blob/master/src/DatabaseError.php"
    click RateLimitExc "https://github.com/delight-im/PHP-Auth/blob/master/src/TooManyRequestsException.php"
    click PwdExc "https://github.com/delight-im/PHP-Auth/blob/master/src/InvalidPasswordException.php"
    click EmailExc "https://github.com/delight-im/PHP-Auth/blob/master/src/InvalidEmailException.php"

    classDef core fill:#a8d1ff,stroke:#333,stroke-width:2px
    classDef security fill:#ffb3b3,stroke:#333,stroke-width:2px
    classDef database fill:#90EE90,stroke:#333,stroke-width:2px
    classDef exception fill:#FFE4B5,stroke:#333,stroke-width:2px
    
    class Auth,UserMgr,Admin,RoleMgr,StatusMgr core
    class Session,Cookie,RateLimit,PwdHash,EmailVerif,RBAC security
    class PDO,MySQL,PostgreSQL,SQLite,Tables,Users,UsersRemembered,UsersResets,UsersThrottling database
    class AuthExc,AuthErr,DBErr,RateLimitExc,TwoFactorExc,UserMgmtExc,PwdExc,EmailExc exception
```
