# juansierra02/login_otp architecture

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

- Interactive diagram: https://gitdiagram.com/juansierra02/login_otp
- Repository: https://github.com/juansierra02/login_otp

## Overview

##### Main components
- User Interface / Client: Represented by the web pages (e.g., login.php, verify.php) that the user interacts with.
- Authentication Flow Components:
- login.php: The entry point where the user submits their email.
- send_otp.php: Initiates the process of generating and emailing the OTP.
- verify_otp.php & verify.php: Handle the OTP verification process.
- Configuration and Dependency Management:
- config.php: Contains configuration settings for database and SMTP (email) connection.
- composer.json and vendor/ folder: Represent dependency management (including PHPMailer).
- Database:
- database.sql: Script to create the necessary MySQL database/schema for storing OTPs and possibly user data.

##### Relationships and interactions
- The user starts at login.php and inputs their email.
- login.php communicates with send_otp.php, which is responsible for generating a random 6-digit OTP and then utilizing PHPMailer (as part of the vendor libraries) to send the email via SMTP.
- The OTP, along with relevant data such as its expiration time (configured to 5 minutes by default), is stored in the MySQL database as defined in database.sql.
- The user then accesses verify.php where they input the received OTP.
- verify_otp.php processes the input, checks against the stored OTP in the database (and validates expiration) and then completes the authentication loop.

##### Architectural patterns and design principles
- Separation of Concerns: Different PHP files manage distinct aspects of the authentication process (login, OTP sending, and OTP verification).
- Security Focus: OTP expiration, absence of storing user passwords, and reliance on external SMTP for email delivery.
- Simple and modular structure: Though the project is straightforward, it clearly separates configuration, business logic, and dependency management.

##### Relevant technologies
- PHP 7.4 as the runtime environment.
- PHPMailer for sending OTP emails.
- MySQL for database operations.
- Composer as the dependency manager.

##### Additional detailed elements
- A note on how PHPMailer is used (via Composer autoloading in the vendor directory), showing its integration.
- Data flow including essential security aspects like “OTP expiration” and “Credentials configuration.”

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "User Interface"
        UI_login["login.php (Login Page)"] 
        UI_verify["verify.php (OTP Verification Form)"]
    end

    subgraph "Authentication Flow"
        OTP_service["send_otp.php (OTP Generation & Email Service)"]
        OTP_verify["verify_otp.php (OTP Verification Processor)"]
    end

    subgraph "Configuration & Dependencies"
        Config["config.php (Configuration)"]
        Dependency["composer.json & vendor/ (Dependency Management)"]
    end

    subgraph "Database"
        DB["database.sql (MySQL Schema)"]
    end

    %% Data Flow
    UI_login -->|"submitEmail"| OTP_service
    OTP_service -->|"storeOTP"| DB
    UI_verify  -->|"submitOTP"| OTP_verify
    OTP_verify -->|"validateOTP"| DB
    OTP_service -->|"useConfigSMTP"| Config
    OTP_verify -->|"useConfigDB"| Config
    Dependency -->|"providePHPMailer"| OTP_service

    %% Styling
    classDef ui fill:#FFCCFF,stroke:#333,stroke-width:2px;
    classDef auth fill:#CCE5FF,stroke:#333,stroke-width:2px;
    classDef config fill:#CCFFCC,stroke:#333,stroke-width:2px;
    classDef db fill:#FFD699,stroke:#333,stroke-width:2px;

    class UI_login,UI_verify ui;
    class OTP_service,OTP_verify auth;
    class Config,Dependency config;
    class DB db;

    %% Click Events
    click UI_login "https://github.com/juansierra02/login_otp/blob/main/login.php"
    click UI_verify "https://github.com/juansierra02/login_otp/blob/main/verify.php"
    click OTP_service "https://github.com/juansierra02/login_otp/blob/main/send_otp.php"
    click OTP_verify "https://github.com/juansierra02/login_otp/blob/main/verify_otp.php"
    click Config "https://github.com/juansierra02/login_otp/blob/main/config.php"
    click DB "https://github.com/juansierra02/login_otp/blob/main/database.sql"
```
