# arjayads/php-simple-auth architecture

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

- Interactive diagram: https://gitdiagram.com/arjayads/php-simple-auth
- Repository: https://github.com/arjayads/php-simple-auth

## Overview

##### Project type and purpose
- This is a monolithic full-stack PHP web application demonstrating simple user authentication (sign-up, account activation, sign-in, password reset, “remember me”).
- It includes a set of PHP “Test” pages as the UI/controllers, a User model, configuration files, helper classes, an email template, and a cron-driven mailer.

##### File structure
- Top-level directories:
- Config – environment and database/email settings
- Cron – MailerCron.php (scheduled job to send queued emails)
- Helper – database wrapper, session manager, string utilities, emailer class + embedded SwiftMailer library
- Template – EmailTemplate.php (HTML/text email views)
- Test – PHP pages acting as controllers/views and static assets (CSS, JS, SASS, images, fonts)
- Other entries:
- User.php – domain model representing the user table
- README.md – high-level description, schema for MySQL user table
- Architectural clues:
- Monolith, no separate frontend build step beyond SASS/CSS, no microservices
- Cron-based job for outbound email
- Direct DB calls via Helper/Database.php

##### README for additional insights
- Confirms LAMP stack, MySQL user table
- SwiftMailer is used for sending mail (templating and SMTP via Helper/Emailer.php)

##### Main components and interactions (to include
a. Web Client (Browser)
b. Web Server (Apache/Nginx + PHP-FPM)
c. Application Code
- Config Loader
- Controllers/Views (Test/*.php)
- Model (User.php)
- Helpers – Database, Session, Str, Utils
- Emailer Helper + SwiftMailer library
- Email Templates
d. Database Server (MySQL)
e. Cron Scheduler + MailerCron.php
f. External SMTP Server (via SwiftMailer)

Relationships:
- Browser → HTTP Request → Web Server
- Web Server loads Config → routes to Test pages → invokes Helpers/Model → queries MySQL → renders HTML/CSS/JS → HTTP Response → Browser
- Certain actions enqueue emails (activation, reset) via Helper/Emailer → email spool (file or DB)
- Cron Scheduler triggers MailerCron.php → uses SwiftMailer to send queued emails → connects to External SMTP
- Session Helper ↔ Browser (cookies)
- Utils/Str helpers used internally for token generation, hashing, URL building

##### Architectural patterns and principles
- Monolithic MVC-like layering (controllers/views in Test, model in User.php, helpers for cross-cutting concerns)
- Single codebase, no microservices
- Separation of concerns: Config vs. Business Logic vs. Helpers vs. Templates vs. Third-party lib
- Cron-based asynchronous processing of outbound email

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Web Client
    Browser["Web Client (Browser)"]:::external
    StaticAssets["Static Assets"]:::web
    click StaticAssets "https://github.com/arjayads/php-simple-auth/tree/master/Test/assets/"

    %% Web Server
    WebServer["Web Server<br/>(Apache/Nginx + PHP-FPM)"]:::web
    EntryPoint["Front Controller<br/>Test/index.php"]:::web
    click EntryPoint "https://github.com/arjayads/php-simple-auth/blob/master/Test/index.php"

    %% PHP Application
    subgraph "PHP Application"
        direction TB
        %% Config Loader
        subgraph "Config Loader"
            direction TB
            ConfigGen["General Config"]:::config
            click ConfigGen "https://github.com/arjayads/php-simple-auth/blob/master/Config/Config.php"
            AppConfig["App Settings"]:::config
            click AppConfig "https://github.com/arjayads/php-simple-auth/blob/master/Config/AppConfig.php"
            DbConfig["Database Settings"]:::config
            click DbConfig "https://github.com/arjayads/php-simple-auth/blob/master/Config/DbConfig.php"
            EmailConfig["Email Settings"]:::config
            click EmailConfig "https://github.com/arjayads/php-simple-auth/blob/master/Config/EmailConfig.php"
        end

        %% Controllers and Views
        subgraph "Controllers / Views"
            direction TB
            EntryPoint2["Entry Point<br/>Test/index.php"]:::web
            click EntryPoint2 "https://github.com/arjayads/php-simple-auth/blob/master/Test/index.php"
            UIpages["UI Pages<br/>Test/*.php"]:::web
            click UIpages "https://github.com/arjayads/php-simple-auth/tree/master/Test/"
        end

        %% Model
        subgraph "Domain Model"
            UserModel["User.php"]:::model
            click UserModel "https://github.com/arjayads/php-simple-auth/blob/master/User.php"
        end

        %% Helpers
        subgraph "Helpers"
            direction TB
            DBHelper["Database Wrapper"]:::helper
            click DBHelper "https://github.com/arjayads/php-simple-auth/blob/master/Helper/Database.php"
            SessionHelper["Session Manager"]:::helper
            click SessionHelper "https://github.com/arjayads/php-simple-auth/blob/master/Helper/Session.php"
            StrHelper["String Utilities"]:::helper
            click StrHelper "https://github.com/arjayads/php-simple-auth/blob/master/Helper/Str.php"
            UtilsHelper["Misc Utilities"]:::helper
            click UtilsHelper "https://github.com/arjayads/php-simple-auth/blob/master/Helper/Utils.php"
            Emailer["Emailer Helper"]:::helper
            click Emailer "https://github.com/arjayads/php-simple-auth/blob/master/Helper/Emailer.php"
        end

        %% Third-party Library
        subgraph "Third-party Library"
            SwiftMailer["SwiftMailer"]:::library
            click SwiftMailer "https://github.com/arjayads/php-simple-auth/tree/master/Helper/swiftmailer/"
        end

        %% Email Templates
        EmailTemplate["Email Templates"]:::template
        click EmailTemplate "https://github.com/arjayads/php-simple-auth/blob/master/Template/EmailTemplate.php"
    end

    %% Database and External SMTP
    Database[(MySQL Database)]:::database
    SMTP[(External SMTP Server)]:::external

    %% Cron Scheduler
    Cron["Cron Scheduler"]:::cron
    click Cron "https://github.com/arjayads/php-simple-auth/blob/master/Cron/MailerCron.php"

    %% Synchronous Flows
    Browser -->|HTTP Request| WebServer
    WebServer -->|load configuration| ConfigGen
    WebServer --> EntryPoint
    EntryPoint -->|route request| UIpages
    UIpages -->|invoke model/helper| UserModel
    UIpages -->|invoke helper| DBHelper
    DBHelper -->|read/write user record| Database
    UIpages -->|invoke helper| SessionHelper
    UIpages -->|invoke helper| StrHelper
    UIpages -->|invoke helper| UtilsHelper
    UIpages -->|invoke helper| Emailer
    Emailer --> EmailTemplate
    Emailer -->|enqueue email| Database

    Database -->|store session| SessionHelper

    Database -->|store tokens| StrHelper

    UIpages -->|render views/assets| Browser

    %% Asynchronous Email Flow
    Database -.->|queued emails| Cron
    Cron -->|execute MailerCron.php| SwiftMailer
    SwiftMailer -->|send email via SMTP| SMTP

    %% Styles
    classDef external fill:#D3D3D3,stroke:#333,stroke-width:1px
    classDef web fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef config fill:#E6E6FA,stroke:#333,stroke-width:1px
    classDef model fill:#FFD700,stroke:#333,stroke-width:1px
    classDef helper fill:#FFA500,stroke:#333,stroke-width:1px
    classDef library fill:#FFDAB9,stroke:#333,stroke-width:1px
    classDef template fill:#FFEFD5,stroke:#333,stroke-width:1px
    classDef database fill:#98FB98,stroke:#333,stroke-width:1px
    classDef cron fill:#F0E68C,stroke:#333,stroke-width:1px
```
