# jahidul2018/laravel-nextjs-breeze-api architecture

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

- Interactive diagram: https://gitdiagram.com/jahidul2018/laravel-nextjs-breeze-api
- Repository: https://github.com/jahidul2018/laravel-nextjs-breeze-api

## Overview

##### Main Components

A. Frontend Layer (Next.js):
- Authentication Pages (Login, Register)
- Protected Routes
- API Integration Layer

B. Backend Layer (Laravel):
- API Controllers (Auth Controllers)
- Middleware Layer
- Service Providers
- Models
- Database Layer

**[Client Browser]**
- ↕
**[Next.js Frontend (Port 3000)]**
- ↕
- [Sanctum]
- ↕
**[Laravel Backend (Port 8000)]**
- ↕
**[Database (MySQL)]**

##### Component Details

Frontend (Next.js):
- Sub-components:
- Authentication Pages
- API Client
- State Management
- Protected Routes

API Layer:
- CORS middleware
- API endpoints:
- /api/auth/*
- /api/user
- Other protected routes

Backend (Laravel):
- HTTP Kernel (Middleware Pipeline)
- Auth Controllers
- Models (User)
- Service Providers
- Database Layer

##### Important Flows to Highlight

Authentication Flow:
**Client → Login Request → Sanctum → Laravel Auth → Database**
**↑                                                    ↓**
**Token Response ←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←**

Protected Route Flow:
**Client → Protected Request + Token → Sanctum Verification → Resource**

##### Additional Elements

- Configuration files locations:
- .env files (both frontend and backend)
- config/*.php files
- middleware configurations

- Storage components:
- Session storage
- Cache storage
- File storage

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        Browser["Web Browser"]
    end

    subgraph NextJS["Next.js Frontend (Port 3000)"]
        direction TB
        AuthPages["Authentication Pages"]:::frontend
        APIClient["API Client"]:::frontend
        StateManagement["State Management"]:::frontend
        ProtectedRoutes["Protected Routes"]:::frontend
    end

    subgraph Security["Security Layer"]
        direction TB
        Sanctum["Laravel Sanctum"]:::security
        CORS["CORS Middleware"]:::security
        click CORS "https://github.com/jahidul2018/laravel-nextjs-breeze-api/blob/main/config/cors.php"
        click Sanctum "https://github.com/jahidul2018/laravel-nextjs-breeze-api/blob/main/config/sanctum.php"
    end

    subgraph Laravel["Laravel Backend (Port 8000)"]
        direction TB
        HTTPKernel["HTTP Kernel"]:::backend

        subgraph Controllers["Controllers Layer"]
            direction TB
            AuthControllers["Auth Controllers"]:::backend
            click AuthControllers "https://github.com/jahidul2018/laravel-nextjs-breeze-api/tree/main/app/Http/Controllers/Auth/"
        end

        subgraph Middleware["Middleware Layer"]
            direction TB
            AuthMiddleware["Authentication"]:::backend
            CSRFMiddleware["CSRF Protection"]:::backend
            EmailVerification["Email Verification"]:::backend
            click AuthMiddleware "https://github.com/jahidul2018/laravel-nextjs-breeze-api/blob/main/app/Http/Middleware/Authenticate.php"
            click CSRFMiddleware "https://github.com/jahidul2018/laravel-nextjs-breeze-api/blob/main/app/Http/Middleware/VerifyCsrfToken.php"
            click EmailVerification "https://github.com/jahidul2018/laravel-nextjs-breeze-api/blob/main/app/Http/Middleware/EnsureEmailIsVerified.php"
        end

        subgraph Providers["Service Providers"]
            direction TB
            AuthProvider["Auth Provider"]:::backend
            RouteProvider["Route Provider"]:::backend
            click AuthProvider "https://github.com/jahidul2018/laravel-nextjs-breeze-api/blob/main/app/Providers/AuthServiceProvider.php"
            click RouteProvider "https://github.com/jahidul2018/laravel-nextjs-breeze-api/blob/main/app/Providers/RouteServiceProvider.php"
        end

        subgraph Models["Models Layer"]
            direction TB
            UserModel["User Model"]:::backend
            click UserModel "https://github.com/jahidul2018/laravel-nextjs-breeze-api/blob/main/app/Models/User.php"
        end

        subgraph Routes["Routes"]
            direction TB
            APIRoutes["API Routes"]:::backend
            AuthRoutes["Auth Routes"]:::backend
            click APIRoutes "https://github.com/jahidul2018/laravel-nextjs-breeze-api/blob/main/routes/api.php"
            click AuthRoutes "https://github.com/jahidul2018/laravel-nextjs-breeze-api/blob/main/routes/auth.php"
        end

        subgraph Storage["Storage"]
            direction TB
            SessionStorage["Session Storage"]:::storage
            CacheStorage["Cache Storage"]:::storage
            FileStorage["File Storage"]:::storage
            click SessionStorage "https://github.com/jahidul2018/laravel-nextjs-breeze-api/tree/main/storage/framework/sessions/"
            click CacheStorage "https://github.com/jahidul2018/laravel-nextjs-breeze-api/tree/main/storage/framework/cache/"
            click FileStorage "https://github.com/jahidul2018/laravel-nextjs-breeze-api/tree/main/storage/app/"
        end
    end

    subgraph Database["Database Layer"]
        direction TB
        MySQL[(MySQL)]:::database
        Migrations["Migrations"]:::database
        Seeders["Seeders"]:::database
        Factories["Factories"]:::database
        click Migrations "https://github.com/jahidul2018/laravel-nextjs-breeze-api/tree/main/database/migrations/"
        click Seeders "https://github.com/jahidul2018/laravel-nextjs-breeze-api/blob/main/database/seeders/DatabaseSeeder.php"
        click Factories "https://github.com/jahidul2018/laravel-nextjs-breeze-api/blob/main/database/factories/UserFactory.php"
    end

    %% Connections
    Browser <--> NextJS
    NextJS <--> Security
    Security <--> Laravel
    Laravel <--> Database

    %% Styles
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef security fill:#e74c3c,stroke:#c0392b,color:white
    classDef backend fill:#f39c12,stroke:#d35400,color:white
    classDef database fill:#9b59b6,stroke:#8e44ad,color:white
    classDef storage fill:#1abc9c,stroke:#16a085,color:white

    %% Legend
    subgraph Legend
        Frontend["Frontend Component"]:::frontend
        SecurityComponent["Security Component"]:::security
        BackendComponent["Backend Component"]:::backend
        DatabaseComponent["Database Component"]:::database
        StorageComponent["Storage Component"]:::storage
    end
```
