# swathigithubrit/fastapi-authentication-system architecture

> Architecture diagram of the GitHub repository swathigithubrit/fastapi-authentication-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/swathigithubrit/fastapi-authentication-system
- Repository: https://github.com/swathigithubrit/fastapi-authentication-system

## Overview

This is a compact FastAPI authentication backend. A client registers with credentials, logs in to receive a bearer JWT, then supplies that token to access the profile endpoint. The route layer owns registration and login actions; authentication helpers handle password hashing and token operations, while dependencies validate tokens and load the current user. Database startup and PostgreSQL persistence are shown as separate runtime responsibilities. Edges reflect the supplied source excerpts or README; database table registration details are documented but not fully visible in the excerpts.

Main entry points: [`app/routes/user_routes.py`](https://github.com/swathigithubrit/fastapi-authentication-system/blob/main/app/routes/user_routes.py) (User endpoints), [`app/dependencies.py`](https://github.com/swathigithubrit/fastapi-authentication-system/blob/main/app/dependencies.py) (Session and user dependencies), [`app/database.py`](https://github.com/swathigithubrit/fastapi-authentication-system/blob/main/app/database.py) (Database session provider), [`app/main.py`](https://github.com/swathigithubrit/fastapi-authentication-system/blob/main/app/main.py) (FastAPI application)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API workflow"]
  node_application["FastAPI application<br/>[main.py]"]
  node_user_api["User endpoints<br/>[user_routes.py]"]
  node_user_schemas["Request and token schemas<br/>[user_schemas.py]"]
end

subgraph group_security["Authentication"]
  node_security_helpers["Password and JWT helpers<br/>[auth.py]"]
  node_auth_dependencies["Session and user dependencies<br/>[dependencies.py]"]
end

subgraph group_persistence["Persistence"]
  node_session_provider["Database session provider<br/>[database.py]"]
  node_user_model["User model<br/>[user_model.py]"]
end

node_client(("API client"))
node_postgres[("PostgreSQL database")]

node_client -->|"registers, logs in, requests profile"| node_user_api
node_application -->|"creates tables at startup"| node_session_provider
node_application -->|"includes router"| node_user_api
node_user_api -->|"uses request and token schemas"| node_user_schemas
node_user_api -->|"injects session and current user"| node_auth_dependencies
node_user_api -->|"queries and creates users"| node_user_model
node_user_api -->|"hashes, verifies, and issues tokens"| node_security_helpers
node_auth_dependencies -->|"gets database session"| node_session_provider
node_auth_dependencies -->|"validates JWT"| node_security_helpers
node_auth_dependencies -->|"loads user by email"| node_user_model
node_session_provider -->|"connects and creates tables"| node_postgres

click node_application "https://github.com/swathigithubrit/fastapi-authentication-system/blob/main/app/main.py"
click node_user_api "https://github.com/swathigithubrit/fastapi-authentication-system/blob/main/app/routes/user_routes.py"
click node_user_schemas "https://github.com/swathigithubrit/fastapi-authentication-system/blob/main/app/schemas/user_schemas.py"
click node_security_helpers "https://github.com/swathigithubrit/fastapi-authentication-system/blob/main/app/auth.py"
click node_auth_dependencies "https://github.com/swathigithubrit/fastapi-authentication-system/blob/main/app/dependencies.py"
click node_session_provider "https://github.com/swathigithubrit/fastapi-authentication-system/blob/main/app/database.py"
click node_user_model "https://github.com/swathigithubrit/fastapi-authentication-system/blob/main/app/models/user_model.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_application,node_user_api,node_user_schemas,node_client toneBlue
class node_security_helpers,node_auth_dependencies,node_postgres toneAmber
class node_session_provider,node_user_model toneMint
```

## Components

### API workflow

- [FastAPI application](https://github.com/swathigithubrit/fastapi-authentication-system/blob/main/app/main.py): `app/main.py`
- [User endpoints](https://github.com/swathigithubrit/fastapi-authentication-system/blob/main/app/routes/user_routes.py): `app/routes/user_routes.py`
- [Request and token schemas](https://github.com/swathigithubrit/fastapi-authentication-system/blob/main/app/schemas/user_schemas.py): `app/schemas/user_schemas.py`

### Authentication

- [Password and JWT helpers](https://github.com/swathigithubrit/fastapi-authentication-system/blob/main/app/auth.py): `app/auth.py`
- [Session and user dependencies](https://github.com/swathigithubrit/fastapi-authentication-system/blob/main/app/dependencies.py): `app/dependencies.py`

### Persistence

- [Database session provider](https://github.com/swathigithubrit/fastapi-authentication-system/blob/main/app/database.py): `app/database.py`
- [User model](https://github.com/swathigithubrit/fastapi-authentication-system/blob/main/app/models/user_model.py): `app/models/user_model.py`

### Other components

- **API client**
- **PostgreSQL database**

## Connections

- API client → User endpoints: registers, logs in, requests profile (evidence: `README.md`)
- FastAPI application → Database session provider: creates tables at startup (evidence: `app/main.py`)
- FastAPI application → User endpoints: includes router (evidence: `app/main.py`)
- User endpoints → Request and token schemas: uses request and token schemas (evidence: `app/routes/user_routes.py`)
- User endpoints → Session and user dependencies: injects session and current user (evidence: `app/routes/user_routes.py`)
- User endpoints → User model: queries and creates users (evidence: `app/routes/user_routes.py`)
- User endpoints → Password and JWT helpers: hashes, verifies, and issues tokens (evidence: `app/routes/user_routes.py`)
- Session and user dependencies → Database session provider: gets database session (evidence: `app/dependencies.py`)
- Session and user dependencies → Password and JWT helpers: validates JWT (evidence: `app/dependencies.py`)
- Session and user dependencies → User model: loads user by email (evidence: `app/dependencies.py`)
- Database session provider → PostgreSQL database: connects and creates tables (evidence: `README.md`)
