# 0xpuncker/go-jwt-auth-api architecture

> Architecture diagram of the GitHub repository 0xpuncker/go-jwt-auth-api, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/0xpuncker/go-jwt-auth-api
- Repository: https://github.com/0xpuncker/go-jwt-auth-api

## Overview

##### Main Components

a) Client Layer:
- External clients/applications that will consume the API
- HTTP/REST requests coming in

b) API Layer:
- Fiber Web Framework as the main HTTP server
- Routes layer (/routes)
- Controllers layer (/controllers)
- JWT Authentication middleware

c) Data Layer:
- Models layer (/models)
- Database layer (/database)
- PostgreSQL database

##### Component Relationships

**Client Requests → API Layer → Business Logic → Data Layer → Database**

##### Key Flows to Highlight

a) Authentication Flow:
1. Client sends credentials
2. JWT middleware validates
3. Token generation/validation
4. Protected route access

b) Data Flow:
1. HTTP request hits routes
2. Routes direct to controllers
3. Controllers interact with models
4. Models communicate with database through GORM

##### Technical Details

Labels for:
- Fiber Framework
- JWT Authentication
- GORM ORM
- PostgreSQL
- Key Go packages used

##### Additional Notes

- Version information for major components
- Error handling paths
- Secure vs non-secure endpoints

- How authentication flows through the system
- Where different types of requests are handled
- How the data moves between layers
- Where security is implemented
- How the database integration works

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and classes
    classDef client fill:#90EE90,stroke:#333,stroke-width:2px
    classDef api fill:#87CEEB,stroke:#333,stroke-width:2px
    classDef auth fill:#FFD700,stroke:#333,stroke-width:2px
    classDef data fill:#FFA500,stroke:#333,stroke-width:2px
    classDef db fill:#DEB887,stroke:#333,stroke-width:2px

    %% Client Layer
    Client[Client Applications]:::client

    %% API Layer
    subgraph AppLayer[Go Application]
        Entry["Main Entry Point"]:::api
        Routes["Routes Layer"]:::api
        Controllers["Controllers Layer"]:::api
        JWTMiddleware["JWT Authentication Middleware"]:::auth
        Models["Data Models Layer"]:::data
        DBConn["Database Connection Layer"]:::data
    end

    %% Database Layer
    subgraph DBLayer[Database Infrastructure]
        GORM["GORM ORM"]:::db
        PostgreSQL[(PostgreSQL Database)]:::db
    end

    %% Relationships
    Client -->|HTTP/REST Requests| Routes
    Routes --> Controllers
    Controllers --> JWTMiddleware
    JWTMiddleware --> Models
    Models --> DBConn
    DBConn --> GORM
    GORM --> PostgreSQL

    %% Click Events
    click Entry "https://github.com/0xPuncker/go-jwt-auth-api/blob/main/main.go"
    click Routes "https://github.com/0xPuncker/go-jwt-auth-api/blob/main/routes/routes.go"
    click Controllers "https://github.com/0xPuncker/go-jwt-auth-api/blob/main/controllers/controllers.go"
    click Models "https://github.com/0xPuncker/go-jwt-auth-api/blob/main/models/models.go"
    click DBConn "https://github.com/0xPuncker/go-jwt-auth-api/blob/main/database/dbconn.go"
    click PostgreSQL "https://github.com/0xPuncker/go-jwt-auth-api/blob/main/infra/postgres/docker-compose.yml"

    %% Legend
    subgraph Legend
        ClientLegend[Client Layer]:::client
        APILegend[API Components]:::api
        AuthLegend[Auth Components]:::auth
        DataLegend[Data Components]:::data
        DBLegend[Database Components]:::db
    end
```
