# goutampatel18/fastapi-social-media architecture

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

- Interactive diagram: https://gitdiagram.com/goutampatel18/fastapi-social-media
- Repository: https://github.com/goutampatel18/fastapi-social-media

## Overview

This is a FastAPI social-media REST API. Clients register or look up users, log in for a bearer token, then use protected post and voting endpoints; post responses include vote counts. The routers own request handling, while shared auth, password, schema, and database layers support them. PostgreSQL stores users, posts, and votes. The README documents interactive API docs and migrations; migrations are operational tooling rather than a runtime product component. Relationships are limited to those visible in excerpts or explicitly documented.

Main entry points: [`app/database.py`](https://github.com/goutampatel18/fastapi-social-media/blob/main/app/database.py) (SQLAlchemy sessions), [`app/main.py`](https://github.com/goutampatel18/fastapi-social-media/blob/main/app/main.py) (FastAPI application), [`app/models.py`](https://github.com/goutampatel18/fastapi-social-media/blob/main/app/models.py) (User, post, vote models), [`app/routers/auth.py`](https://github.com/goutampatel18/fastapi-social-media/blob/main/app/routers/auth.py) (Login endpoint)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API surface"]
  node_app["FastAPI application<br/>[main.py]"]
  node_docs["Interactive API docs<br/>[main.py]"]
end

subgraph group_identity["Identity"]
  node_users["User endpoints<br/>[user.py]"]
  node_login["Login endpoint<br/>[auth.py]"]
  node_tokens["JWT authentication<br/>[oauth2.py]"]
  node_passwords["Password hashing<br/>[utils.py]"]
end

subgraph group_content["Posts and votes"]
  node_posts["Post endpoints<br/>[post.py]"]
  node_votes["Voting endpoint<br/>[vote.py]"]
end

subgraph group_shared["Shared runtime"]
  node_schemas["Request and response schemas<br/>[schemas.py]"]
  node_models["User, post, vote models<br/>[models.py]"]
  node_database["SQLAlchemy sessions<br/>[database.py]"]
  node_settings["Runtime settings<br/>[config.py]"]
end

node_client(("API client"))
node_postgres[("PostgreSQL")]
node_environment["Environment variables"]

node_client -->|"sends requests"| node_app
node_app -->|"registers router"| node_users
node_app -->|"registers router"| node_posts
node_app -->|"registers router"| node_login
node_app -->|"registers router"| node_votes
node_app -->|"creates tables"| node_models
node_app -->|"binds engine"| node_database
node_client -->|"explores API"| node_docs
node_users -->|"hashes passwords"| node_passwords
node_login -->|"verifies passwords"| node_passwords
node_login -->|"creates token"| node_tokens
node_posts -->|"checks identity"| node_tokens
node_votes -->|"checks identity"| node_tokens
node_tokens -->|"gets session"| node_database
node_tokens -->|"loads user"| node_models
node_tokens -->|"reads JWT settings"| node_settings
node_users -->|"gets session"| node_database
node_users -->|"queries users"| node_models
node_posts -->|"gets session"| node_database
node_posts -->|"queries posts and votes"| node_models
node_votes -->|"gets session"| node_database
node_votes -->|"queries vote records"| node_models
node_login -->|"gets session"| node_database
node_login -->|"queries user"| node_models
node_users -->|"validates and formats"| node_schemas
node_login -->|"formats token response"| node_schemas
node_posts -->|"validates and formats"| node_schemas
node_votes -->|"validates vote input"| node_schemas
node_models -->|"uses declarative base"| node_database
node_database -->|"reads connection settings"| node_settings
node_database -->|"connects to"| node_postgres
node_environment -->|"supplies values"| node_settings

click node_app "https://github.com/goutampatel18/fastapi-social-media/blob/main/app/main.py"
click node_docs "https://github.com/goutampatel18/fastapi-social-media/blob/main/app/main.py"
click node_users "https://github.com/goutampatel18/fastapi-social-media/blob/main/app/routers/user.py"
click node_login "https://github.com/goutampatel18/fastapi-social-media/blob/main/app/routers/auth.py"
click node_tokens "https://github.com/goutampatel18/fastapi-social-media/blob/main/app/oauth2.py"
click node_passwords "https://github.com/goutampatel18/fastapi-social-media/blob/main/app/utils.py"
click node_posts "https://github.com/goutampatel18/fastapi-social-media/blob/main/app/routers/post.py"
click node_votes "https://github.com/goutampatel18/fastapi-social-media/blob/main/app/routers/vote.py"
click node_schemas "https://github.com/goutampatel18/fastapi-social-media/blob/main/app/schemas.py"
click node_models "https://github.com/goutampatel18/fastapi-social-media/blob/main/app/models.py"
click node_database "https://github.com/goutampatel18/fastapi-social-media/blob/main/app/database.py"
click node_settings "https://github.com/goutampatel18/fastapi-social-media/blob/main/app/config.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_app,node_docs,node_client toneBlue
class node_users,node_login,node_tokens,node_passwords,node_postgres toneAmber
class node_posts,node_votes toneMint
class node_schemas,node_models,node_database,node_settings toneRose
class node_environment toneIndigo
```

## Components

### API surface

- [FastAPI application](https://github.com/goutampatel18/fastapi-social-media/blob/main/app/main.py): `app/main.py`
- [Interactive API docs](https://github.com/goutampatel18/fastapi-social-media/blob/main/app/main.py): `app/main.py`

### Identity

- [User endpoints](https://github.com/goutampatel18/fastapi-social-media/blob/main/app/routers/user.py): `app/routers/user.py`
- [Login endpoint](https://github.com/goutampatel18/fastapi-social-media/blob/main/app/routers/auth.py): `app/routers/auth.py`
- [JWT authentication](https://github.com/goutampatel18/fastapi-social-media/blob/main/app/oauth2.py): `app/oauth2.py`
- [Password hashing](https://github.com/goutampatel18/fastapi-social-media/blob/main/app/utils.py): `app/utils.py`

### Posts and votes

- [Post endpoints](https://github.com/goutampatel18/fastapi-social-media/blob/main/app/routers/post.py): `app/routers/post.py`
- [Voting endpoint](https://github.com/goutampatel18/fastapi-social-media/blob/main/app/routers/vote.py): `app/routers/vote.py`

### Shared runtime

- [Request and response schemas](https://github.com/goutampatel18/fastapi-social-media/blob/main/app/schemas.py): `app/schemas.py`
- [User, post, vote models](https://github.com/goutampatel18/fastapi-social-media/blob/main/app/models.py): `app/models.py`
- [SQLAlchemy sessions](https://github.com/goutampatel18/fastapi-social-media/blob/main/app/database.py): `app/database.py`
- [Runtime settings](https://github.com/goutampatel18/fastapi-social-media/blob/main/app/config.py): `app/config.py`

### Other components

- **API client**
- **PostgreSQL**
- **Environment variables**

## Connections

- API client → FastAPI application: sends requests (evidence: `README.md`)
- FastAPI application → User endpoints: registers router (evidence: `app/main.py`)
- FastAPI application → Post endpoints: registers router (evidence: `app/main.py`)
- FastAPI application → Login endpoint: registers router (evidence: `app/main.py`)
- FastAPI application → Voting endpoint: registers router (evidence: `app/main.py`)
- FastAPI application → User, post, vote models: creates tables (evidence: `app/main.py`)
- FastAPI application → SQLAlchemy sessions: binds engine (evidence: `app/main.py`)
- API client → Interactive API docs: explores API (evidence: `README.md`)
- User endpoints → Password hashing: hashes passwords (evidence: `app/routers/user.py`)
- Login endpoint → Password hashing: verifies passwords (evidence: `app/routers/auth.py`)
- Login endpoint → JWT authentication: creates token (evidence: `app/routers/auth.py`)
- Post endpoints → JWT authentication: checks identity (evidence: `app/routers/post.py`)
- Voting endpoint → JWT authentication: checks identity (evidence: `app/routers/vote.py`)
- JWT authentication → SQLAlchemy sessions: gets session (evidence: `app/oauth2.py`)
- JWT authentication → User, post, vote models: loads user (evidence: `app/oauth2.py`)
- JWT authentication → Runtime settings: reads JWT settings (evidence: `app/oauth2.py`)
- User endpoints → SQLAlchemy sessions: gets session (evidence: `app/routers/user.py`)
- User endpoints → User, post, vote models: queries users (evidence: `app/routers/user.py`)
- Post endpoints → SQLAlchemy sessions: gets session (evidence: `app/routers/post.py`)
- Post endpoints → User, post, vote models: queries posts and votes (evidence: `app/routers/post.py`)
- Voting endpoint → SQLAlchemy sessions: gets session (evidence: `app/routers/vote.py`)
- Voting endpoint → User, post, vote models: queries vote records (evidence: `app/routers/vote.py`)
- Login endpoint → SQLAlchemy sessions: gets session (evidence: `app/routers/auth.py`)
- Login endpoint → User, post, vote models: queries user (evidence: `app/routers/auth.py`)
- User endpoints → Request and response schemas: validates and formats (evidence: `app/routers/user.py`)
- Login endpoint → Request and response schemas: formats token response (evidence: `app/routers/auth.py`)
- Post endpoints → Request and response schemas: validates and formats (evidence: `app/routers/post.py`)
- Voting endpoint → Request and response schemas: validates vote input (evidence: `app/routers/vote.py`)
- User, post, vote models → SQLAlchemy sessions: uses declarative base (evidence: `app/models.py`)
- SQLAlchemy sessions → Runtime settings: reads connection settings (evidence: `app/database.py`)
- SQLAlchemy sessions → PostgreSQL: connects to (evidence: `app/database.py`)
- Environment variables → Runtime settings: supplies values (evidence: `app/config.py`)
