# eamirgh/laravel-rest-auth-example architecture

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

- Interactive diagram: https://gitdiagram.com/eamirgh/laravel-rest-auth-example
- Repository: https://github.com/eamirgh/laravel-rest-auth-example

## Overview

##### Project type and purpose
- This is a full-stack Laravel web application implementing user registration, login with one-time passwords (OTPs), and device management.
- Key features: RESTful API endpoints (routes/api.php), email-based OTP delivery, Eloquent models for User, Otp, Device, event/listener architecture for post-login actions, Blade templates for views, and asset compilation via webpack.mix.js.

##### File structure
- app/
– Http/Controllers: AuthController handles register, login, OTP verification.
– Models: User, Otp, Device represent your domain.
– Events & Listeners: LoggedIn event triggers NotifyOtp mailer.
– Middleware: authentication, CSRF, maintenance, etc.
- routes/
– api.php: JSON endpoints for mobile or SPA clients.
– web.php: Blade view routes.
- resources/
– views/: Blade email template and welcome page.
– js/, css/: front-end assets compiled by Laravel Mix.
- database/
– migrations: schema for users, otps, devices, jobs, tokens.
– factories & seeders: test data.
- config/: mail, queue, database, session drivers.
- public/: entry point (index.php), static assets, .htaccess.

##### README for additional insights
- The README is the stock Laravel overview.
- Confirms use of core Laravel systems: routing, DI container, Eloquent ORM, background jobs, broadcasting.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        Browser["Browser"]:::infra
        MobileApp["Mobile App"]:::infra
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        WebServer["Web Server (NGINX/Apache)"]:::infra
        FileStorage["File Storage (sessions, cache, logs)"]:::infra
    end

    %% Laravel Application
    subgraph "Laravel Application"        
        %% Presentation Layer
        subgraph "Presentation Layer"
            Kernel["HTTP Kernel"]:::core
            Middleware["Middleware Stack"]:::core
            Router["Router"]:::core
            routeAPI["API Routes"]:::core
            routeWEB["Web Routes"]:::core
            click routeAPI "https://github.com/eamirgh/laravel-rest-auth-example/blob/master/routes/api.php"
            click routeWEB "https://github.com/eamirgh/laravel-rest-auth-example/blob/master/routes/web.php"
            
            subgraph Controllers
                AuthController["AuthController"]:::core
                click AuthController "https://github.com/eamirgh/laravel-rest-auth-example/blob/master/app/Http/Controllers/AuthController.php"
            end
            
            subgraph Validation
                URR["UserRegisterRequest"]:::core
                click URR "https://github.com/eamirgh/laravel-rest-auth-example/blob/master/app/Http/Requests/UserRegisterRequest.php"
                ULR["UserLoginRequest"]:::core
                click ULR "https://github.com/eamirgh/laravel-rest-auth-example/blob/master/app/Http/Requests/UserLoginRequest.php"
                UOR["UserOtpRequest"]:::core
                click UOR "https://github.com/eamirgh/laravel-rest-auth-example/blob/master/app/Http/Requests/UserOtpRequest.php"
            end
            
            subgraph Views
                WelcomePage["Welcome Page"]:::core
                click WelcomePage "https://github.com/eamirgh/laravel-rest-auth-example/blob/master/resources/views/welcome.blade.php"
                OtpEmailTemplate["OTP Email Template"]:::core
                click OtpEmailTemplate "https://github.com/eamirgh/laravel-rest-auth-example/blob/master/resources/views/emails/otp/notify.blade.php"
            end
        end

        %% Application Layer
        subgraph "Application Layer"
            OTPService["OTPService"]:::core
            DeviceService["DeviceService"]:::core
            EventDispatcher["Event Dispatcher"]:::core
        end

        %% Domain Layer
        subgraph "Domain Layer"
            UserModel["User Model"]:::core
            click UserModel "https://github.com/eamirgh/laravel-rest-auth-example/blob/master/app/Models/User.php"
            OtpModel["Otp Model"]:::core
            click OtpModel "https://github.com/eamirgh/laravel-rest-auth-example/blob/master/app/Models/Otp.php"
            DeviceModel["Device Model"]:::core
            click DeviceModel "https://github.com/eamirgh/laravel-rest-auth-example/blob/master/app/Models/Device.php"
        end

        %% Event & Queue
        subgraph "Event & Queue"
            LoggedInEvent["LoggedIn Event"]:::core
            click LoggedInEvent "https://github.com/eamirgh/laravel-rest-auth-example/blob/master/app/Events/LoggedIn.php"
            LoggedInListener["LoggedInListener"]:::core
            click LoggedInListener "https://github.com/eamirgh/laravel-rest-auth-example/blob/master/app/Listeners/LoggedInListener.php"
            NotifyOtpMailer["NotifyOtp Mailer"]:::core
            click NotifyOtpMailer "https://github.com/eamirgh/laravel-rest-auth-example/blob/master/app/Mail/NotifyOtp.php"
            QueueWorker["Queue Worker"]:::infra
        end

        %% Service Provider & Config
        EventServiceProvider["EventServiceProvider"]:::core
        click EventServiceProvider "https://github.com/eamirgh/laravel-rest-auth-example/blob/master/app/Providers/EventServiceProvider.php"
        QueueConfig["Queue Config"]:::core
        click QueueConfig "https://github.com/eamirgh/laravel-rest-auth-example/blob/master/config/queue.php"
        MailConfig["Mail Config"]:::core
        click MailConfig "https://github.com/eamirgh/laravel-rest-auth-example/blob/master/config/mail.php"
        MixConfig["Laravel Mix"]:::infra
        click MixConfig "https://github.com/eamirgh/laravel-rest-auth-example/blob/master/webpack.mix.js"
    end

    %% Data Layer
    subgraph "Data Layer"
        Database["Relational Database"]:::data
        OtpsMigration["OTPs Table Migration"]:::data
        click OtpsMigration "https://github.com/eamirgh/laravel-rest-auth-example/blob/master/database/migrations/2021_11_07_074034_create_otps_table.php"
        DevicesMigration["Devices Table Migration"]:::data
        click DevicesMigration "https://github.com/eamirgh/laravel-rest-auth-example/blob/master/database/migrations/2021_11_07_074123_create_devices_table.php"
    end

    %% External Services
    subgraph "External Services"
        SMTP["SMTP Server"]:::ext
        Redis["Redis (Queue Back-end)"]:::ext
    end

    %% Connections
    Browser --> WebServer
    MobileApp --> WebServer

    WebServer --> Kernel
    Kernel --> Middleware
    Middleware --> Router
    Router --> routeAPI
    Router --> routeWEB
    routeAPI --> AuthController
    routeWEB --> WelcomePage

    AuthController --> URR
    AuthController --> ULR
    AuthController --> UOR
    AuthController --> OTPService
    AuthController --> DeviceService
    AuthController --> UserModel
    AuthController --> OtpModel
    AuthController --> DeviceModel
    AuthController --> LoggedInEvent

    OTPService --> UserModel
    OTPService --> OtpModel
    DeviceService --> DeviceModel

    LoggedInEvent --> EventDispatcher
    EventDispatcher --> LoggedInListener
    LoggedInListener --> NotifyOtpMailer
    NotifyOtpMailer --> QueueWorker

    QueueWorker --> SMTP
    QueueWorker --> Redis

    UserModel --> Database
    OtpModel --> Database
    DeviceModel --> Database

    OtpsMigration --> Database
    DevicesMigration --> Database

    FileStorage --> Kernel

    MixConfig --> FileStorage

    %% Styles
    classDef core fill:#D6E4FF,stroke:#1E40AF
    classDef data fill:#DCFCE7,stroke:#166534
    classDef ext fill:#FFE7BA,stroke:#D97706
    classDef infra fill:#E5E7EB,stroke:#6B7280
```
