# rudra00434/shortly_url_shortener architecture

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

- Interactive diagram: https://gitdiagram.com/rudra00434/shortly_url_shortener
- Repository: https://github.com/rudra00434/shortly_url_shortener

## Overview

This is a React and FastAPI URL shortener. A user submits a long URL in the frontend; the API validates it, generates a collision-checked short code, and persists the mapping in PostgreSQL. A later request for that code retrieves the mapping and redirects the client. The frontend also supports copying the result and generating/downloading a QR code. Redis cache helpers and a rate limiter exist, but the sampled API does not connect them to its routes; those relationships are therefore not inferred.

Main entry points: [`shortener_app/main.py`](https://github.com/rudra00434/shortly_url_shortener/blob/main/shortener_app/main.py) (API routes), [`frontend/src/App.jsx`](https://github.com/rudra00434/shortly_url_shortener/blob/main/frontend/src/App.jsx) (Shortener UI), [`shortener_app/database.py`](https://github.com/rudra00434/shortly_url_shortener/blob/main/shortener_app/database.py) (DB session), [`shortener_app/models.py`](https://github.com/rudra00434/shortly_url_shortener/blob/main/shortener_app/models.py) (URL mapping model)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_frontend_mount["React mount<br/>[main.jsx]"]
  node_frontend_app["Shortener UI<br/>[App.jsx]"]
end

subgraph group_api["API and domain"]
  node_api_routes["API routes<br/>[main.py]"]
  node_url_schemas["URL schemas<br/>[schemas.py]"]
  node_url_crud["Short-code CRUD<br/>[crud.py]"]
end

subgraph group_storage["Persistence"]
  node_db_config["DB session<br/>[database.py]"]
  node_url_model["URL mapping model<br/>[models.py]"]
  node_postgres[("PostgreSQL")]
end

subgraph group_redis["Redis utilities"]
  node_redis_helpers["URL cache helpers<br/>[redis_client.py]"]
  node_rate_limiter["Rate limiter<br/>[rate_limiter.py]"]
  node_redis_service[("Redis")]
end

node_visitor(("Link user"))
node_destination(("Original URL site"))

node_visitor -->|"opens app"| node_frontend_mount
node_frontend_mount -->|"renders"| node_frontend_app
node_frontend_app -->|"POSTs URL"| node_api_routes
node_api_routes -->|"validates request"| node_url_schemas
node_api_routes -->|"gets session"| node_db_config
node_api_routes -->|"creates or looks up"| node_url_crud
node_url_crud -->|"queries and stores"| node_url_model
node_url_model -->|"uses Base"| node_db_config
node_api_routes -->|"creates table metadata"| node_url_model
node_db_config -->|"connects"| node_postgres
node_api_routes -->|"returns short code"| node_frontend_app
node_api_routes -->|"redirects client"| node_destination
node_frontend_app -->|"shows result"| node_visitor
node_redis_helpers -->|"reads and writes cache"| node_redis_service
node_rate_limiter -->|"uses Redis client"| node_redis_helpers

click node_frontend_mount "https://github.com/rudra00434/shortly_url_shortener/blob/main/frontend/src/main.jsx"
click node_frontend_app "https://github.com/rudra00434/shortly_url_shortener/blob/main/frontend/src/App.jsx"
click node_api_routes "https://github.com/rudra00434/shortly_url_shortener/blob/main/shortener_app/main.py"
click node_url_schemas "https://github.com/rudra00434/shortly_url_shortener/blob/main/shortener_app/schemas.py"
click node_url_crud "https://github.com/rudra00434/shortly_url_shortener/blob/main/shortener_app/crud.py"
click node_db_config "https://github.com/rudra00434/shortly_url_shortener/blob/main/shortener_app/database.py"
click node_url_model "https://github.com/rudra00434/shortly_url_shortener/blob/main/shortener_app/models.py"
click node_redis_helpers "https://github.com/rudra00434/shortly_url_shortener/blob/main/shortener_app/redis_client.py"
click node_rate_limiter "https://github.com/rudra00434/shortly_url_shortener/blob/main/shortener_app/rate_limiter.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_frontend_mount,node_frontend_app,node_visitor toneBlue
class node_api_routes,node_url_schemas,node_url_crud toneAmber
class node_db_config,node_url_model,node_postgres toneMint
class node_redis_helpers,node_rate_limiter,node_redis_service toneRose
class node_destination toneIndigo
```

## Components

### Frontend

- [React mount](https://github.com/rudra00434/shortly_url_shortener/blob/main/frontend/src/main.jsx): `frontend/src/main.jsx`
- [Shortener UI](https://github.com/rudra00434/shortly_url_shortener/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`

### API and domain

- [API routes](https://github.com/rudra00434/shortly_url_shortener/blob/main/shortener_app/main.py): `shortener_app/main.py`
- [URL schemas](https://github.com/rudra00434/shortly_url_shortener/blob/main/shortener_app/schemas.py): `shortener_app/schemas.py`
- [Short-code CRUD](https://github.com/rudra00434/shortly_url_shortener/blob/main/shortener_app/crud.py): `shortener_app/crud.py`

### Persistence

- [DB session](https://github.com/rudra00434/shortly_url_shortener/blob/main/shortener_app/database.py): `shortener_app/database.py`
- [URL mapping model](https://github.com/rudra00434/shortly_url_shortener/blob/main/shortener_app/models.py): `shortener_app/models.py`
- **PostgreSQL**

### Redis utilities

- [URL cache helpers](https://github.com/rudra00434/shortly_url_shortener/blob/main/shortener_app/redis_client.py): `shortener_app/redis_client.py`
- [Rate limiter](https://github.com/rudra00434/shortly_url_shortener/blob/main/shortener_app/rate_limiter.py): `shortener_app/rate_limiter.py`
- **Redis**

### Other components

- **Link user**
- **Original URL site**

## Connections

- Link user → React mount: opens app (evidence: `frontend/src/main.jsx`)
- React mount → Shortener UI: renders (evidence: `frontend/src/main.jsx`)
- Shortener UI → API routes: POSTs URL (evidence: `frontend/src/App.jsx`)
- API routes → URL schemas: validates request (evidence: `shortener_app/main.py`)
- API routes → DB session: gets session (evidence: `shortener_app/main.py`)
- API routes → Short-code CRUD: creates or looks up (evidence: `shortener_app/main.py`)
- Short-code CRUD → URL mapping model: queries and stores (evidence: `shortener_app/crud.py`)
- URL mapping model → DB session: uses Base (evidence: `shortener_app/models.py`)
- API routes → URL mapping model: creates table metadata (evidence: `shortener_app/main.py`)
- DB session → PostgreSQL: connects (evidence: `shortener_app/database.py`)
- API routes → Shortener UI: returns short code (evidence: `frontend/src/App.jsx`)
- API routes → Original URL site: redirects client (evidence: `shortener_app/main.py`)
- Shortener UI → Link user: shows result (evidence: `frontend/src/App.jsx`)
- URL cache helpers → Redis: reads and writes cache (evidence: `shortener_app/redis_client.py`)
- Rate limiter → URL cache helpers: uses Redis client (evidence: `shortener_app/rate_limiter.py`)
