# antormojumdar/url-shortener architecture

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

- Interactive diagram: https://gitdiagram.com/antormojumdar/url-shortener
- Repository: https://github.com/antormojumdar/url-shortener

## Overview

This is a FastAPI URL-shortening service with optional Redis acceleration and rate limiting. A user submits a validated link request; the API enforces limits, creates a link, and returns its short URL. Visits resolve the code, check expiry, record privacy-conscious click details, and redirect. Separate API operations list links, report browser/device/day analytics, and delete links. The graph follows calls visible in the excerpts and capabilities documented in the README; unsampled behavior is not inferred.

Main entry points: [`url_shortener/app/main.py`](https://github.com/antormojumdar/url-shortener/blob/main/url_shortener/app/main.py) (FastAPI routes), [`url_shortener/app/crud.py`](https://github.com/antormojumdar/url-shortener/blob/main/url_shortener/app/crud.py) (Link operations), [`url_shortener/app/rate_limit.py`](https://github.com/antormojumdar/url-shortener/blob/main/url_shortener/app/rate_limit.py) (Request rate limiter), [`url_shortener/app/database.py`](https://github.com/antormojumdar/url-shortener/blob/main/url_shortener/app/database.py) (SQLAlchemy database setup)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["HTTP API"]
  node_api["FastAPI routes<br/>[main.py]"]
  node_schemas["Request and response schemas<br/>[schemas.py]"]
end

subgraph group_links["Link Management"]
  node_crud["Link operations<br/>[crud.py]"]
  node_codes["Code generation<br/>[utils.py]"]
  node_models["Link and click models<br/>[models.py]"]
end

subgraph group_analytics["Click Analytics"]
  node_clickdata["Click detail parsing and hashing<br/>[utils.py]"]
  node_stats["Click aggregation<br/>[crud.py]"]
end

subgraph group_infra["Persistence and Acceleration"]
  node_database["SQLAlchemy database setup<br/>[database.py]"]
  node_sqlstore[("SQLite or PostgreSQL")]
  node_cache["Redirect cache<br/>[cache.py]"]
  node_ratelimit["Request rate limiter<br/>[rate_limit.py]"]
  node_redis[("Redis")]
  node_config["Runtime settings<br/>[config.py]"]
end

node_user(("API user"))

node_user -->|"sends requests"| node_api
node_api -->|"validates and shapes"| node_schemas
node_api -->|"enforces limits"| node_ratelimit
node_api -->|"creates, reads, deletes"| node_crud
node_api -->|"reads and updates"| node_cache
node_api -->|"parses and hashes"| node_clickdata
node_api -->|"requests breakdown"| node_stats
node_crud -->|"generates codes"| node_codes
node_crud -->|"queries and records"| node_models
node_crud -->|"uses sessions"| node_database
node_stats -->|"aggregates click events"| node_models
node_database -->|"loads connection settings"| node_config
node_database -->|"connects to"| node_sqlstore
node_models -->|"uses declarative base"| node_database
node_cache -->|"loads Redis settings"| node_config
node_cache -.->|"caches URLs"| node_redis
node_ratelimit -->|"loads limit settings"| node_config
node_ratelimit -->|"uses Redis client"| node_cache
node_ratelimit -.->|"checks distributed limits"| node_redis

click node_api "https://github.com/antormojumdar/url-shortener/blob/main/url_shortener/app/main.py"
click node_schemas "https://github.com/antormojumdar/url-shortener/blob/main/url_shortener/app/schemas.py"
click node_crud "https://github.com/antormojumdar/url-shortener/blob/main/url_shortener/app/crud.py"
click node_codes "https://github.com/antormojumdar/url-shortener/blob/main/url_shortener/app/utils.py"
click node_models "https://github.com/antormojumdar/url-shortener/blob/main/url_shortener/app/models.py"
click node_clickdata "https://github.com/antormojumdar/url-shortener/blob/main/url_shortener/app/utils.py"
click node_stats "https://github.com/antormojumdar/url-shortener/blob/main/url_shortener/app/crud.py"
click node_database "https://github.com/antormojumdar/url-shortener/blob/main/url_shortener/app/database.py"
click node_cache "https://github.com/antormojumdar/url-shortener/blob/main/url_shortener/app/cache.py"
click node_ratelimit "https://github.com/antormojumdar/url-shortener/blob/main/url_shortener/app/rate_limit.py"
click node_config "https://github.com/antormojumdar/url-shortener/blob/main/url_shortener/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_api,node_schemas,node_user toneBlue
class node_crud,node_codes,node_models toneAmber
class node_clickdata,node_stats toneMint
class node_database,node_sqlstore,node_cache,node_ratelimit,node_redis,node_config toneRose
```

## Components

### HTTP API

- [FastAPI routes](https://github.com/antormojumdar/url-shortener/blob/main/url_shortener/app/main.py): `url_shortener/app/main.py`
- [Request and response schemas](https://github.com/antormojumdar/url-shortener/blob/main/url_shortener/app/schemas.py): `url_shortener/app/schemas.py`

### Link Management

- [Link operations](https://github.com/antormojumdar/url-shortener/blob/main/url_shortener/app/crud.py): `url_shortener/app/crud.py`
- [Code generation](https://github.com/antormojumdar/url-shortener/blob/main/url_shortener/app/utils.py): `url_shortener/app/utils.py`
- [Link and click models](https://github.com/antormojumdar/url-shortener/blob/main/url_shortener/app/models.py): `url_shortener/app/models.py`

### Click Analytics

- [Click detail parsing and hashing](https://github.com/antormojumdar/url-shortener/blob/main/url_shortener/app/utils.py): `url_shortener/app/utils.py`
- [Click aggregation](https://github.com/antormojumdar/url-shortener/blob/main/url_shortener/app/crud.py): `url_shortener/app/crud.py`

### Persistence and Acceleration

- [SQLAlchemy database setup](https://github.com/antormojumdar/url-shortener/blob/main/url_shortener/app/database.py): `url_shortener/app/database.py`
- **SQLite or PostgreSQL**
- [Redirect cache](https://github.com/antormojumdar/url-shortener/blob/main/url_shortener/app/cache.py): `url_shortener/app/cache.py`
- [Request rate limiter](https://github.com/antormojumdar/url-shortener/blob/main/url_shortener/app/rate_limit.py): `url_shortener/app/rate_limit.py`
- **Redis**
- [Runtime settings](https://github.com/antormojumdar/url-shortener/blob/main/url_shortener/app/config.py): `url_shortener/app/config.py`

### Other components

- **API user**

## Connections

- API user → FastAPI routes: sends requests (evidence: `README.md`)
- FastAPI routes → Request and response schemas: validates and shapes (evidence: `url_shortener/app/main.py`)
- FastAPI routes → Request rate limiter: enforces limits (evidence: `url_shortener/app/main.py`)
- FastAPI routes → Link operations: creates, reads, deletes (evidence: `url_shortener/app/main.py`)
- FastAPI routes → Redirect cache: reads and updates (evidence: `url_shortener/app/main.py`)
- FastAPI routes → Click detail parsing and hashing: parses and hashes (evidence: `url_shortener/app/main.py`)
- FastAPI routes → Click aggregation: requests breakdown (evidence: `url_shortener/app/main.py`)
- Link operations → Code generation: generates codes (evidence: `url_shortener/app/crud.py`)
- Link operations → Link and click models: queries and records (evidence: `url_shortener/app/crud.py`)
- Link operations → SQLAlchemy database setup: uses sessions (evidence: `url_shortener/app/crud.py`)
- Click aggregation → Link and click models: aggregates click events (evidence: `url_shortener/app/crud.py`)
- SQLAlchemy database setup → Runtime settings: loads connection settings (evidence: `url_shortener/app/database.py`)
- SQLAlchemy database setup → SQLite or PostgreSQL: connects to (evidence: `README.md`)
- Link and click models → SQLAlchemy database setup: uses declarative base (evidence: `url_shortener/app/models.py`)
- Redirect cache → Runtime settings: loads Redis settings (evidence: `url_shortener/app/cache.py`)
- Redirect cache → Redis: caches URLs (evidence: `url_shortener/app/cache.py`)
- Request rate limiter → Runtime settings: loads limit settings (evidence: `url_shortener/app/rate_limit.py`)
- Request rate limiter → Redirect cache: uses Redis client (evidence: `url_shortener/app/rate_limit.py`)
- Request rate limiter → Redis: checks distributed limits (evidence: `url_shortener/app/rate_limit.py`)
