# jahidul2018/laravel-rest-api-with-passport architecture

> Architecture diagram of the GitHub repository jahidul2018/laravel-rest-api-with-passport, 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-rest-api-with-passport
- Repository: https://github.com/jahidul2018/laravel-rest-api-with-passport

## Overview

##### Main Components Identification

a. Client Layer
- External API Consumers
- Authentication Endpoints
- Resource Endpoints

b. Application Layer
- API Controllers
- Middleware
- Resources (API Resources)
- Authentication Services

c. Data Layer
- Models
- Database
- Migrations

**[Client Layer]**

- ▼
**[API Gateway Layer]**

- ▼
**[Application Layer]**

- ▼
**[Data Layer]**

##### Detailed Component Breakdown

a. Client Layer (Top):
- HTTP/HTTPS connection

b. API Gateway Layer:
- Split into two main route groups:
- Public Routes (login, register)
- Protected Routes (posts CRUD) with auth:api middleware

c. Application Layer (Middle):
- Controllers Section:
- LoginController (auth operations)
- PostController (CRUD operations)
- Middleware Section:
- Passport Authentication
- Other middleware (CSRF, encryption)
- Resources Section:
- PostResource (API response formatting)

d. Data Layer (Bottom):
- Models:
- User Model (with HasApiTokens trait)
- Post Model
- Database Tables:
- users
- posts
- passport tables

##### Additional Elements

Include:
- Version information (Laravel 8, Passport version)
- Security notes (Bearer token requirement)
- Response format specification

##### Technical Details to Highlight

- Passport OAuth2 implementation
- API versioning (v1)
- Resource transformation layer
- Error handling structure
- Database relationships

Remember to include:
- All major endpoints (/login, /register, /posts)
- Authentication flow with Passport
- Request/Response transformation process
- Error handling pathways
- Database interaction patterns

This will create a comprehensive yet clear representation of the Laravel REST API system with Passport authentication, suitable for both technical documentation and team communication.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        API_CLIENTS["External API Clients"]
        POSTMAN["Postman Collection"]:::docs
    end

    subgraph Gateway
        API_ROUTES["API Routes"]:::routes
        PUBLIC_ROUTES["Public Routes"]
        PROTECTED_ROUTES["Protected Routes"]
    end

    subgraph Application
        direction TB
        subgraph Controllers
            BASE_CTRL["Base Controller"]:::controller
            AUTH_CTRL["Register Controller"]:::controller
            PRODUCT_CTRL["Product Controller"]:::controller
        end

        subgraph Middleware
            AUTH_MW["Authentication"]:::middleware
            CORS["CORS Handler"]:::config
        end

        subgraph Resources
            PRODUCT_RES["Product Resource"]:::resource
        end

        subgraph Config
            AUTH_CONFIG["Auth Config"]:::config
            DB_CONFIG["Database Config"]:::config
        end

        AUTH_PROVIDER["Auth Service Provider"]:::provider
    end

    subgraph Data
        direction TB
        subgraph Models
            USER_MODEL["User Model"]:::model
            PRODUCT_MODEL["Product Model"]:::model
        end

        subgraph Storage
            DB[("Database")]
            MIGRATIONS["Migrations"]:::data
        end
    end

    %% Connections
    API_CLIENTS --> API_ROUTES
    POSTMAN --> API_ROUTES
    API_ROUTES --> PUBLIC_ROUTES & PROTECTED_ROUTES
    PUBLIC_ROUTES --> AUTH_CTRL
    PROTECTED_ROUTES --> PRODUCT_CTRL
    AUTH_CTRL & PRODUCT_CTRL --> BASE_CTRL
    PROTECTED_ROUTES --> AUTH_MW
    AUTH_MW --> AUTH_PROVIDER
    AUTH_PROVIDER --> AUTH_CONFIG
    PRODUCT_CTRL --> PRODUCT_RES
    PRODUCT_CTRL --> PRODUCT_MODEL
    AUTH_CTRL --> USER_MODEL
    USER_MODEL & PRODUCT_MODEL --> DB
    MIGRATIONS --> DB

    %% Styling
    classDef controller fill:#f9f,stroke:#333
    classDef middleware fill:#fc9,stroke:#333
    classDef resource fill:#9cf,stroke:#333
    classDef model fill:#cfc,stroke:#333
    classDef config fill:#fff,stroke:#333
    classDef provider fill:#f96,stroke:#333
    classDef routes fill:#99f,stroke:#333
    classDef data fill:#ccc,stroke:#333
    classDef docs fill:#ff9,stroke:#333

    %% Click Events
    click API_ROUTES "https://github.com/jahidul2018/laravel-rest-api-with-passport/blob/main/routes/api.php"
    click AUTH_CTRL "https://github.com/jahidul2018/laravel-rest-api-with-passport/blob/main/app/Http/Controllers/API/RegisterController.php"
    click PRODUCT_CTRL "https://github.com/jahidul2018/laravel-rest-api-with-passport/blob/main/app/Http/Controllers/API/ProductController.php"
    click BASE_CTRL "https://github.com/jahidul2018/laravel-rest-api-with-passport/blob/main/app/Http/Controllers/API/BaseController.php"
    click AUTH_MW "https://github.com/jahidul2018/laravel-rest-api-with-passport/blob/main/app/Http/Middleware/Authenticate.php"
    click PRODUCT_RES "https://github.com/jahidul2018/laravel-rest-api-with-passport/blob/main/app/Http/Resources/Product.php"
    click USER_MODEL "https://github.com/jahidul2018/laravel-rest-api-with-passport/blob/main/app/Models/User.php"
    click PRODUCT_MODEL "https://github.com/jahidul2018/laravel-rest-api-with-passport/blob/main/app/Models/Product.php"
    click MIGRATIONS "https://github.com/jahidul2018/laravel-rest-api-with-passport/tree/main/database/migrations"
    click AUTH_CONFIG "https://github.com/jahidul2018/laravel-rest-api-with-passport/blob/main/config/auth.php"
    click AUTH_PROVIDER "https://github.com/jahidul2018/laravel-rest-api-with-passport/blob/main/app/Providers/AuthServiceProvider.php"
    click POSTMAN "https://github.com/jahidul2018/laravel-rest-api-with-passport/blob/main/laravel-passport-rest-api.postman_collection.json"
    click DB_CONFIG "https://github.com/jahidul2018/laravel-rest-api-with-passport/blob/main/config/database.php"
    click CORS "https://github.com/jahidul2018/laravel-rest-api-with-passport/blob/main/config/cors.php"
```
