# teyalite/reddit-clone architecture

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

- Interactive diagram: https://gitdiagram.com/teyalite/reddit-clone
- Repository: https://github.com/teyalite/reddit-clone

## Overview

Reddit Clone is a FastAPI backend for account creation and login, authenticated post management, and voting. Users call the API routes; route handlers validate request/response data, apply domain rules, and read or mutate PostgreSQL through SQLAlchemy. Authentication issues and verifies JWT bearer tokens, while password utilities hash and check credentials. The README also identifies database migrations as part of operating the application, though migration internals are not sampled. Relationships below follow the shown imports and calls; migration-to-model wiring is not asserted.

Main entry points: [`app/database.py`](https://github.com/teyalite/reddit-clone/blob/main/app/database.py) (Database sessions), [`app/routers/auth.py`](https://github.com/teyalite/reddit-clone/blob/main/app/routers/auth.py) (Authentication routes), [`app/oauth2.py`](https://github.com/teyalite/reddit-clone/blob/main/app/oauth2.py) (JWT authentication), [`app/models.py`](https://github.com/teyalite/reddit-clone/blob/main/app/models.py) (ORM domain models)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API entry and routes"]
  node_entry["FastAPI application<br/>[main.py]"]
  node_user_routes["User routes<br/>[user.py]"]
  node_schemas["Request and response schemas<br/>[schemas.py]"]
end

subgraph group_identity["Identity and access"]
  node_auth_routes["Authentication routes<br/>[auth.py]"]
  node_tokens["JWT authentication<br/>[oauth2.py]"]
  node_passwords["Password hashing<br/>[utils.py]"]
end

subgraph group_domain["Posts and votes"]
  node_post_routes["Post routes<br/>[post.py]"]
  node_vote_routes["Vote routes<br/>[vote.py]"]
end

subgraph group_persistence["Data persistence"]
  node_models["ORM domain models<br/>[models.py]"]
  node_database["Database sessions<br/>[database.py]"]
  node_postgres[("PostgreSQL")]
  node_settings["Application settings<br/>[config.py]"]
end

node_client(("API client"))

node_client -->|"sends requests"| node_entry
node_entry -->|"registers routes"| node_auth_routes
node_entry -->|"registers routes"| node_user_routes
node_entry -->|"registers routes"| node_post_routes
node_entry -->|"registers routes"| node_vote_routes
node_user_routes -->|"validates and shapes"| node_schemas
node_auth_routes -->|"validates and shapes"| node_schemas
node_post_routes -->|"validates and shapes"| node_schemas
node_vote_routes -->|"validates"| node_schemas
node_user_routes -->|"hashes passwords"| node_passwords
node_auth_routes -->|"checks passwords"| node_passwords
node_auth_routes -->|"creates tokens"| node_tokens
node_post_routes -->|"requires current user"| node_tokens
node_vote_routes -->|"requires current user"| node_tokens
node_tokens -->|"loads user"| node_models
node_tokens -->|"opens session"| node_database
node_user_routes -->|"queries and creates"| node_models
node_auth_routes -->|"queries user"| node_models
node_post_routes -->|"queries and mutates"| node_models
node_vote_routes -->|"queries and mutates"| node_models
node_user_routes -->|"opens session"| node_database
node_auth_routes -->|"opens session"| node_database
node_post_routes -->|"opens session"| node_database
node_vote_routes -->|"opens session"| node_database
node_models -->|"uses declarative base"| node_database
node_database -->|"connects and queries"| node_postgres
node_database -->|"reads connection settings"| node_settings
node_tokens -->|"reads JWT settings"| node_settings

click node_entry "https://github.com/teyalite/reddit-clone/blob/main/app/main.py"
click node_user_routes "https://github.com/teyalite/reddit-clone/blob/main/app/routers/user.py"
click node_auth_routes "https://github.com/teyalite/reddit-clone/blob/main/app/routers/auth.py"
click node_post_routes "https://github.com/teyalite/reddit-clone/blob/main/app/routers/post.py"
click node_vote_routes "https://github.com/teyalite/reddit-clone/blob/main/app/routers/vote.py"
click node_schemas "https://github.com/teyalite/reddit-clone/blob/main/app/schemas.py"
click node_tokens "https://github.com/teyalite/reddit-clone/blob/main/app/oauth2.py"
click node_passwords "https://github.com/teyalite/reddit-clone/blob/main/app/utils.py"
click node_models "https://github.com/teyalite/reddit-clone/blob/main/app/models.py"
click node_database "https://github.com/teyalite/reddit-clone/blob/main/app/database.py"
click node_settings "https://github.com/teyalite/reddit-clone/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_entry,node_user_routes,node_schemas,node_client toneBlue
class node_auth_routes,node_tokens,node_passwords toneAmber
class node_post_routes,node_vote_routes toneMint
class node_models,node_database,node_postgres,node_settings toneRose
```

## Components

### API entry and routes

- [FastAPI application](https://github.com/teyalite/reddit-clone/blob/main/app/main.py): `app/main.py`
- [User routes](https://github.com/teyalite/reddit-clone/blob/main/app/routers/user.py): `app/routers/user.py`
- [Request and response schemas](https://github.com/teyalite/reddit-clone/blob/main/app/schemas.py): `app/schemas.py`

### Identity and access

- [Authentication routes](https://github.com/teyalite/reddit-clone/blob/main/app/routers/auth.py): `app/routers/auth.py`
- [JWT authentication](https://github.com/teyalite/reddit-clone/blob/main/app/oauth2.py): `app/oauth2.py`
- [Password hashing](https://github.com/teyalite/reddit-clone/blob/main/app/utils.py): `app/utils.py`

### Posts and votes

- [Post routes](https://github.com/teyalite/reddit-clone/blob/main/app/routers/post.py): `app/routers/post.py`
- [Vote routes](https://github.com/teyalite/reddit-clone/blob/main/app/routers/vote.py): `app/routers/vote.py`

### Data persistence

- [ORM domain models](https://github.com/teyalite/reddit-clone/blob/main/app/models.py): `app/models.py`
- [Database sessions](https://github.com/teyalite/reddit-clone/blob/main/app/database.py): `app/database.py`
- **PostgreSQL**
- [Application settings](https://github.com/teyalite/reddit-clone/blob/main/app/config.py): `app/config.py`

### Other components

- **API client**

## Connections

- API client → FastAPI application: sends requests (evidence: `app/main.py`)
- FastAPI application → Authentication routes: registers routes (evidence: `app/main.py`)
- FastAPI application → User routes: registers routes (evidence: `app/main.py`)
- FastAPI application → Post routes: registers routes (evidence: `app/main.py`)
- FastAPI application → Vote routes: registers routes (evidence: `app/main.py`)
- User routes → Request and response schemas: validates and shapes (evidence: `app/routers/user.py`)
- Authentication routes → Request and response schemas: validates and shapes (evidence: `app/routers/auth.py`)
- Post routes → Request and response schemas: validates and shapes (evidence: `app/routers/post.py`)
- Vote routes → Request and response schemas: validates (evidence: `app/routers/vote.py`)
- User routes → Password hashing: hashes passwords (evidence: `app/routers/user.py`)
- Authentication routes → Password hashing: checks passwords (evidence: `app/routers/auth.py`)
- Authentication routes → JWT authentication: creates tokens (evidence: `app/routers/auth.py`)
- Post routes → JWT authentication: requires current user (evidence: `app/routers/post.py`)
- Vote routes → JWT authentication: requires current user (evidence: `app/routers/vote.py`)
- JWT authentication → ORM domain models: loads user (evidence: `app/oauth2.py`)
- JWT authentication → Database sessions: opens session (evidence: `app/oauth2.py`)
- User routes → ORM domain models: queries and creates (evidence: `app/routers/user.py`)
- Authentication routes → ORM domain models: queries user (evidence: `app/routers/auth.py`)
- Post routes → ORM domain models: queries and mutates (evidence: `app/routers/post.py`)
- Vote routes → ORM domain models: queries and mutates (evidence: `app/routers/vote.py`)
- User routes → Database sessions: opens session (evidence: `app/routers/user.py`)
- Authentication routes → Database sessions: opens session (evidence: `app/routers/auth.py`)
- Post routes → Database sessions: opens session (evidence: `app/routers/post.py`)
- Vote routes → Database sessions: opens session (evidence: `app/routers/vote.py`)
- ORM domain models → Database sessions: uses declarative base (evidence: `app/models.py`)
- Database sessions → PostgreSQL: connects and queries (evidence: `app/database.py`)
- Database sessions → Application settings: reads connection settings (evidence: `app/database.py`)
- JWT authentication → Application settings: reads JWT settings (evidence: `app/oauth2.py`)
