# gowthamchandu307/userauth-api architecture

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

- Interactive diagram: https://gitdiagram.com/gowthamchandu307/userauth-api
- Repository: https://github.com/gowthamchandu307/userauth-api

## Overview

##### Main Components

a) Client Layer:
- External clients/applications that consume the API
- Swagger UI interface (running on /docs)

b) API Layer (FastAPI Application):
- Authentication endpoints (from routers/token.py)
- User management endpoints (from routers/user.py)
- Middleware for JWT validation

c) Service Layer:
- CRUD operations (from crud.py)
- Token generation and validation services

d) Data Layer:
- MySQL Database
- SQLAlchemy ORM (models.py)

**[Client Layer]**
- ↓↑
**[API Gateway/FastAPI]**
- ↓↑
**[Service Layer]**
- ↓↑
**[Data Layer]**

##### Component Details

For each component, include these specific elements:

Client Layer:
- HTTP/REST clients
- Swagger UI documentation interface
- Supported HTTP methods (POST, GET)

API Layer:
- FastAPI application container
- Route handlers:
- /auth/token (JWT authentication)
- /users (user management)
- Authentication middleware

Service Layer:
- User service (CRUD operations)
- Token service (JWT generation/validation)
- Password hashing service (bcrypt)

Data Layer:
- MySQL container
- User table schema
- SQLAlchemy ORM

##### Interactions and Flows

- Client → API: HTTP requests with JWT tokens
- API → Service: Internal method calls
- Service → Database: SQL queries via SQLAlchemy
- Database → Service: Query results
- Service → API: Processed data
- API → Client: HTTP responses

##### Container Architecture

A separate section showing Docker container architecture:
- FastAPI container
- MySQL container
- Docker network
- Exposed ports (8000 for API)

##### Security Layers

Security implementations:
- JWT token flow
- Password hashing
- Authentication middleware
- Database security

##### Additional Notes

Annotations for:
- Environment variables configuration
- Database connection details
- API documentation endpoints
- Security measures

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        CLI[HTTP/REST Clients]
        SWG[Swagger UI /docs]
    end

    subgraph API
        FA[FastAPI Application]:::fastapi
        click FA "https://github.com/Gowthamchandu307/userauth-api/blob/main/app/main.py"
        
        subgraph Routes
            AT["/auth/token"]:::route
            click AT "https://github.com/Gowthamchandu307/userauth-api/blob/main/app/routers/token.py"
            UR["/users"]:::route
            click UR "https://github.com/Gowthamchandu307/userauth-api/blob/main/app/routers/user.py"
        end
        
        AM[Auth Middleware]
        CF[Config]:::config
        click CF "https://github.com/Gowthamchandu307/userauth-api/blob/main/app/config.py"
        ENV[Environment]:::config
        click ENV "https://github.com/Gowthamchandu307/userauth-api/blob/main/app/.env"
    end

    subgraph Services
        US[User Service]:::service
        click US "https://github.com/Gowthamchandu307/userauth-api/blob/main/app/crud.py"
        TS[Token Service]:::service
        PS[Password Service]:::service
    end

    subgraph Data
        DB[(MySQL Database)]
        ORM[SQLAlchemy ORM]:::orm
        click ORM "https://github.com/Gowthamchandu307/userauth-api/blob/main/app/models.py"
        DBC[Database Config]:::config
        click DBC "https://github.com/Gowthamchandu307/userauth-api/blob/main/app/database.py"
    end

    subgraph Containers
        DC[Docker Compose]:::container
        click DC "https://github.com/Gowthamchandu307/userauth-api/blob/main/docker-compose.yml"
        DF[Dockerfile]:::container
        click DF "https://github.com/Gowthamchandu307/userauth-api/tree/main/Dockerfile"
    end

    %% Client Layer Connections
    CLI --> FA
    SWG --> FA

    %% API Layer Connections
    FA --> AT & UR
    AT & UR --> AM
    AM --> US
    CF --> FA
    ENV --> FA

    %% Service Layer Connections
    US --> TS
    US --> PS
    US --> ORM

    %% Data Layer Connections
    ORM --> DB
    DBC --> DB

    %% Container Connections
    DC --> FA
    DC --> DB
    DF --> FA

    %% Styling
    classDef default fill:#f9f9f9,stroke:#333,stroke-width:2px
    classDef fastapi fill:#06b6d4,stroke:#333,color:white
    classDef route fill:#22c55e,stroke:#333,color:white
    classDef service fill:#8b5cf6,stroke:#333,color:white
    classDef orm fill:#f97316,stroke:#333,color:white
    classDef config fill:#eab308,stroke:#333,color:white
    classDef container fill:#ec4899,stroke:#333,color:white

    %% Legend
    subgraph Legend
        L1[FastAPI]:::fastapi
        L2[Routes]:::route
        L3[Services]:::service
        L4[ORM]:::orm
        L5[Config]:::config
        L6[Containers]:::container
    end
```
