# shahnewaz-labib/auth-be-wildin architecture

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

- Interactive diagram: https://gitdiagram.com/shahnewaz-labib/auth-be-wildin
- Repository: https://github.com/shahnewaz-labib/auth-be-wildin

## Overview

##### Main Components

A. Server Layer:
- HTTP Server (main.go) handling incoming requests on port 9000
- Route handlers for /register, /login, /me, and /logout endpoints

B. Authentication Layer (auth/auth.go):
- Authentication service handling user verification
- Session management
- Password hashing and verification

C. Database Layer (db/db.go):
- User storage and retrieval
- Session storage

**┌─────────────────────────────────────┐**
- Client Requests           │
- (Browser/API Client with Cookies)  │
- ┘
- ↕ HTTP
**┌─────────────────────────────────────┐**
- HTTP Server (main.go)       │
- POST /register                 │
- POST /login                    │
- GET /me                        │
- POST /logout                   │
- ┘
- ↕ Internal Calls
**┌─────────────────────────────────────┐**
- Auth Service (auth/auth.go)     │
- User Authentication Logic      │
- Session Management            │
- Password Handling             │
- ┘
- ↕ Data Access
**┌─────────────────────────────────────┐**
- Database Layer (db/db.go)      │
- User Storage                   │
- Session Storage                │
- ┘

##### Important Details to Capture

- Session Management:
- Cookie-based authentication flow
- Session storage and retrieval
- Session validation points

- Authentication Flow:
- Registration process
- Login process
- Session verification for protected routes
- Logout and session cleanup

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef client fill:#a8d1f0,stroke:#000
    classDef server fill:#90EE90,stroke:#000
    classDef auth fill:#98FB98,stroke:#000
    classDef database fill:#FFE4B5,stroke:#000
    classDef endpoint fill:#F0F8FF,stroke:#000
    
    %% Client Layer
    Client["Client Browser/API Client\n(with Cookies)"]:::client
    
    %% Server Layer
    subgraph Server["HTTP Server Layer"]
        MainServer["HTTP Server\n(Port 9000)"]:::server
        Register["POST /register"]:::endpoint
        Login["POST /login"]:::endpoint
        Me["GET /me"]:::endpoint
        Logout["POST /logout"]:::endpoint
    end
    
    %% Auth Layer
    subgraph Auth["Authentication Layer"]
        AuthService["Authentication Service"]:::auth
        SessionMgmt["Session Management"]:::auth
        PasswordHash["Password Handling"]:::auth
    end
    
    %% Database Layer
    subgraph DB["Database Layer"]
        UserDB[("User Storage")]:::database
        SessionDB[("Session Storage")]:::database
    end
    
    %% Connections
    Client <--> MainServer
    MainServer --> Register
    MainServer --> Login
    MainServer --> Me
    MainServer --> Logout
    
    Register --> AuthService
    Login --> AuthService
    Me --> AuthService
    Logout --> AuthService
    
    AuthService --> SessionMgmt
    AuthService --> PasswordHash
    
    SessionMgmt --> SessionDB
    AuthService --> UserDB
    
    %% Click Events
    click MainServer "https://github.com/shahnewaz-labib/auth-be-wildin/blob/master/main.go"
    click AuthService "https://github.com/shahnewaz-labib/auth-be-wildin/blob/master/auth/auth.go"
    click UserDB "https://github.com/shahnewaz-labib/auth-be-wildin/blob/master/db/db.go"
    click SessionDB "https://github.com/shahnewaz-labib/auth-be-wildin/blob/master/db/db.go"
    
    %% Legend
    subgraph Legend
        L1["Client Interface"]:::client
        L2["Server Components"]:::server
        L3["Auth Components"]:::auth
        L4["Database Storage"]:::database
        L5["API Endpoints"]:::endpoint
    end
```
