# thrigunchandra/c4_shortroute architecture

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

- Interactive diagram: https://gitdiagram.com/thrigunchandra/c4_shortroute
- Repository: https://github.com/thrigunchandra/c4_shortroute

## Overview

This is a FastAPI URL-shortening service. Visitors create short links and follow short-code or username/custom-slug redirects; registered users can manage links, while authentication provides session-based access and premium custom slugs. Redirect resolution checks Redis, falls back to PostgreSQL, validates expiry, and counts clicks for owned links. The graph also includes link-management, rate limiting, and session cleanup. Relationships for unsampled route handlers rely on the SOURCE INDEX; the README is empty, so undocumented capabilities and connections are omitted.

Main entry points: [`app/database/database.py`](https://github.com/thrigunchandra/c4_shortroute/blob/main/app/database/database.py) (Database access), [`app/routes/links/create.py`](https://github.com/thrigunchandra/c4_shortroute/blob/main/app/routes/links/create.py) (Link creation), [`app/routes/auth`](https://github.com/thrigunchandra/c4_shortroute/tree/main/app/routes/auth) (Auth handlers), [`app/dependencies/auth.py`](https://github.com/thrigunchandra/c4_shortroute/blob/main/app/dependencies/auth.py) (Session authentication)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["API entry and routes"]
  node_app["FastAPI app<br/>[main.py]"]
  node_auth_routes["Authentication routes"]
  node_link_routes["Link management routes"]
  node_redirect_routes["Redirect routes"]
end

subgraph group_identity["Identity and access"]
  node_auth_guard["Session authentication<br/>[auth.py]"]
  node_rate_guard["Creation rate limit<br/>[rate_limit.py]"]
  node_auth_logic["Auth handlers"]
  node_session_model["Login sessions<br/>[session.py]"]
  node_user_model["Users<br/>[user.py]"]
  node_cleanup["Session cleanup"]
end

subgraph group_links["Link lifecycle"]
  node_link_create["Link creation<br/>[create.py]"]
  node_link_manage["Link management"]
  node_redirect_logic["Redirect resolution<br/>[link_redirect.py]"]
  node_link_model["Short links<br/>[link.py]"]
  node_schemas["Request and response schemas<br/>[all_schemas.py]"]
end

subgraph group_runtime["Services and persistence"]
  node_shared_services["Token and password utilities<br/>[all_services.py]"]
  node_cache["Link cache<br/>[link_cache.py]"]
  node_limiter["Rate limiter<br/>[rate_limiter.py]"]
  node_db_access["Database access<br/>[database.py]"]
  node_postgres[("PostgreSQL")]
  node_redis_client["Redis client<br/>[redis_client.py]"]
  node_redis[("Redis")]
  node_config["Runtime configuration<br/>[config.py]"]
end

node_visitor(("Visitor or user"))

node_visitor -->|"sends requests"| node_app
node_app -->|"mounts"| node_link_routes
node_app -->|"mounts"| node_auth_routes
node_app -->|"mounts"| node_redirect_routes
node_auth_routes -->|"routes to"| node_auth_logic
node_link_routes -->|"routes to"| node_link_create
node_redirect_routes -->|"resolves with"| node_redirect_logic
node_auth_logic -->|"queries"| node_db_access
node_auth_logic -->|"uses"| node_shared_services
node_auth_logic -->|"validates with"| node_schemas
node_auth_logic -->|"creates sessions"| node_session_model
node_auth_logic -->|"queries users"| node_user_model
node_auth_guard -->|"queries"| node_db_access
node_auth_guard -->|"hashes tokens"| node_shared_services
node_auth_guard -->|"checks sessions"| node_session_model
node_auth_guard -->|"loads user"| node_user_model
node_link_create -->|"checks user"| node_auth_guard
node_link_create -->|"requires limit"| node_rate_guard
node_link_create -->|"persists link"| node_db_access
node_link_create -->|"generates code"| node_shared_services
node_link_create -->|"uses schemas"| node_schemas
node_link_create -->|"creates record"| node_link_model
node_link_manage -->|"queries links"| node_db_access
node_link_manage -->|"checks access"| node_auth_guard
node_link_manage -->|"reads or deletes"| node_link_model
node_link_manage -->|"invalidates cache"| node_cache
node_redirect_logic -->|"checks and fills"| node_cache
node_redirect_logic -->|"queries and counts"| node_db_access
node_redirect_logic -->|"loads link"| node_link_model
node_redirect_logic -->|"joins owner"| node_user_model
node_rate_guard -->|"applies limit"| node_limiter
node_db_access -->|"opens connection"| node_postgres
node_cache -->|"uses client"| node_redis_client
node_limiter -->|"uses client"| node_redis_client
node_redis_client -->|"connects to"| node_redis
node_db_access -->|"reads URL"| node_config
node_redis_client -->|"reads URL"| node_config
node_cleanup -->|"uses database"| node_db_access
node_cleanup -->|"cleans sessions"| node_session_model

click node_app "https://github.com/thrigunchandra/c4_shortroute/blob/main/app/main.py"
click node_auth_routes "https://github.com/thrigunchandra/c4_shortroute/tree/main/app/routes/auth"
click node_link_routes "https://github.com/thrigunchandra/c4_shortroute/tree/main/app/routes/links"
click node_redirect_routes "https://github.com/thrigunchandra/c4_shortroute/tree/main/app/routes/redirects"
click node_auth_guard "https://github.com/thrigunchandra/c4_shortroute/blob/main/app/dependencies/auth.py"
click node_rate_guard "https://github.com/thrigunchandra/c4_shortroute/blob/main/app/dependencies/rate_limit.py"
click node_auth_logic "https://github.com/thrigunchandra/c4_shortroute/tree/main/app/routes/auth"
click node_session_model "https://github.com/thrigunchandra/c4_shortroute/blob/main/app/models/session.py"
click node_user_model "https://github.com/thrigunchandra/c4_shortroute/blob/main/app/models/user.py"
click node_link_create "https://github.com/thrigunchandra/c4_shortroute/blob/main/app/routes/links/create.py"
click node_link_manage "https://github.com/thrigunchandra/c4_shortroute/tree/main/app/routes/links"
click node_redirect_logic "https://github.com/thrigunchandra/c4_shortroute/blob/main/app/services/link_redirect.py"
click node_link_model "https://github.com/thrigunchandra/c4_shortroute/blob/main/app/models/link.py"
click node_schemas "https://github.com/thrigunchandra/c4_shortroute/blob/main/app/schemas/all_schemas.py"
click node_shared_services "https://github.com/thrigunchandra/c4_shortroute/blob/main/app/services/all_services.py"
click node_cache "https://github.com/thrigunchandra/c4_shortroute/blob/main/app/services/link_cache.py"
click node_limiter "https://github.com/thrigunchandra/c4_shortroute/blob/main/app/services/rate_limiter.py"
click node_db_access "https://github.com/thrigunchandra/c4_shortroute/blob/main/app/database/database.py"
click node_redis_client "https://github.com/thrigunchandra/c4_shortroute/blob/main/app/database/redis_client.py"
click node_config "https://github.com/thrigunchandra/c4_shortroute/blob/main/app/config.py"
click node_cleanup "https://github.com/thrigunchandra/c4_shortroute/blob/main/app/scripts/cleanup_sessions.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_auth_routes,node_link_routes,node_redirect_routes,node_visitor toneBlue
class node_auth_guard,node_rate_guard,node_auth_logic,node_session_model,node_user_model,node_cleanup toneAmber
class node_link_create,node_link_manage,node_redirect_logic,node_link_model,node_schemas toneMint
class node_shared_services,node_cache,node_limiter,node_db_access,node_postgres,node_redis_client,node_redis,node_config toneRose
```

## Components

### API entry and routes

- [FastAPI app](https://github.com/thrigunchandra/c4_shortroute/blob/main/app/main.py): `app/main.py`
- [Authentication routes](https://github.com/thrigunchandra/c4_shortroute/tree/main/app/routes/auth): `app/routes/auth`
- [Link management routes](https://github.com/thrigunchandra/c4_shortroute/tree/main/app/routes/links): `app/routes/links`
- [Redirect routes](https://github.com/thrigunchandra/c4_shortroute/tree/main/app/routes/redirects): `app/routes/redirects`

### Identity and access

- [Session authentication](https://github.com/thrigunchandra/c4_shortroute/blob/main/app/dependencies/auth.py): `app/dependencies/auth.py`
- [Creation rate limit](https://github.com/thrigunchandra/c4_shortroute/blob/main/app/dependencies/rate_limit.py): `app/dependencies/rate_limit.py`
- [Auth handlers](https://github.com/thrigunchandra/c4_shortroute/tree/main/app/routes/auth): `app/routes/auth`
- [Login sessions](https://github.com/thrigunchandra/c4_shortroute/blob/main/app/models/session.py): `app/models/session.py`
- [Users](https://github.com/thrigunchandra/c4_shortroute/blob/main/app/models/user.py): `app/models/user.py`
- [Session cleanup](https://github.com/thrigunchandra/c4_shortroute/blob/main/app/scripts/cleanup_sessions.py): `app/scripts/cleanup_sessions.py`

### Link lifecycle

- [Link creation](https://github.com/thrigunchandra/c4_shortroute/blob/main/app/routes/links/create.py): `app/routes/links/create.py`
- [Link management](https://github.com/thrigunchandra/c4_shortroute/tree/main/app/routes/links): `app/routes/links`
- [Redirect resolution](https://github.com/thrigunchandra/c4_shortroute/blob/main/app/services/link_redirect.py): `app/services/link_redirect.py`
- [Short links](https://github.com/thrigunchandra/c4_shortroute/blob/main/app/models/link.py): `app/models/link.py`
- [Request and response schemas](https://github.com/thrigunchandra/c4_shortroute/blob/main/app/schemas/all_schemas.py): `app/schemas/all_schemas.py`

### Services and persistence

- [Token and password utilities](https://github.com/thrigunchandra/c4_shortroute/blob/main/app/services/all_services.py): `app/services/all_services.py`
- [Link cache](https://github.com/thrigunchandra/c4_shortroute/blob/main/app/services/link_cache.py): `app/services/link_cache.py`
- [Rate limiter](https://github.com/thrigunchandra/c4_shortroute/blob/main/app/services/rate_limiter.py): `app/services/rate_limiter.py`
- [Database access](https://github.com/thrigunchandra/c4_shortroute/blob/main/app/database/database.py): `app/database/database.py`
- **PostgreSQL**
- [Redis client](https://github.com/thrigunchandra/c4_shortroute/blob/main/app/database/redis_client.py): `app/database/redis_client.py`
- **Redis**
- [Runtime configuration](https://github.com/thrigunchandra/c4_shortroute/blob/main/app/config.py): `app/config.py`

### Other components

- **Visitor or user**

## Connections

- Visitor or user → FastAPI app: sends requests (evidence: `app/main.py`)
- FastAPI app → Link management routes: mounts (evidence: `app/main.py`)
- FastAPI app → Authentication routes: mounts (evidence: `app/main.py`)
- FastAPI app → Redirect routes: mounts (evidence: `app/main.py`)
- Authentication routes → Auth handlers: routes to (evidence: `app/routes/auth/__init__.py`)
- Link management routes → Link creation: routes to (evidence: `app/routes/links/__init__.py`)
- Redirect routes → Redirect resolution: resolves with (evidence: `app/routes/redirects/short_code.py`)
- Auth handlers → Database access: queries (evidence: `app/routes/auth/login.py`)
- Auth handlers → Token and password utilities: uses (evidence: `app/routes/auth/login.py`)
- Auth handlers → Request and response schemas: validates with (evidence: `app/routes/auth/login.py`)
- Auth handlers → Login sessions: creates sessions (evidence: `app/routes/auth/login.py`)
- Auth handlers → Users: queries users (evidence: `app/routes/auth/login.py`)
- Session authentication → Database access: queries (evidence: `app/dependencies/auth.py`)
- Session authentication → Token and password utilities: hashes tokens (evidence: `app/dependencies/auth.py`)
- Session authentication → Login sessions: checks sessions (evidence: `app/dependencies/auth.py`)
- Session authentication → Users: loads user (evidence: `app/dependencies/auth.py`)
- Link creation → Session authentication: checks user (evidence: `app/routes/links/create.py`)
- Link creation → Creation rate limit: requires limit (evidence: `app/routes/links/create.py`)
- Link creation → Database access: persists link (evidence: `app/routes/links/create.py`)
- Link creation → Token and password utilities: generates code (evidence: `app/routes/links/create.py`)
- Link creation → Request and response schemas: uses schemas (evidence: `app/routes/links/create.py`)
- Link creation → Short links: creates record (evidence: `app/routes/links/create.py`)
- Link management → Database access: queries links (evidence: `app/routes/links/list.py`)
- Link management → Session authentication: checks access (evidence: `app/routes/links/delete.py`)
- Link management → Short links: reads or deletes (evidence: `app/routes/links/detail.py`)
- Link management → Link cache: invalidates cache (evidence: `app/routes/links/delete.py`)
- Redirect resolution → Link cache: checks and fills (evidence: `app/services/link_redirect.py`)
- Redirect resolution → Database access: queries and counts (evidence: `app/services/link_redirect.py`)
- Redirect resolution → Short links: loads link (evidence: `app/services/link_redirect.py`)
- Redirect resolution → Users: joins owner (evidence: `app/services/link_redirect.py`)
- Creation rate limit → Rate limiter: applies limit (evidence: `app/dependencies/rate_limit.py`)
- Database access → PostgreSQL: opens connection (evidence: `app/database/database.py`)
- Link cache → Redis client: uses client (evidence: `app/services/link_cache.py`)
- Rate limiter → Redis client: uses client (evidence: `app/services/rate_limiter.py`)
- Redis client → Redis: connects to (evidence: `app/database/redis_client.py`)
- Database access → Runtime configuration: reads URL (evidence: `app/database/database.py`)
- Redis client → Runtime configuration: reads URL (evidence: `app/database/redis_client.py`)
- Session cleanup → Database access: uses database (evidence: `app/scripts/cleanup_sessions.py`)
- Session cleanup → Login sessions: cleans sessions (evidence: `app/scripts/cleanup_sessions.py`)
