# damodarpurohit29/url_shortener architecture

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

- Interactive diagram: https://gitdiagram.com/damodarpurohit29/url_shortener
- Repository: https://github.com/damodarpurohit29/url_shortener

## Overview

This is a FastAPI URL-shortening service. A client submits a target URL and optional custom code or expiry; the API validates the request, generates a code when needed, and stores the mapping. A later code request checks the mapping and expiry, updates visit statistics, and redirects the client. A separate stats route returns mapping and visit details. Source excerpts show the API and ORM behavior; the README is empty, and no separate analytics or background-processing subsystem is evident.

Main entry points: [`api/url_api.py`](https://github.com/damodarpurohit29/url_shortener/blob/main/api/url_api.py) (URL Routes), [`main.py`](https://github.com/damodarpurohit29/url_shortener/blob/main/main.py) (FastAPI App), [`db/session.py`](https://github.com/damodarpurohit29/url_shortener/blob/main/db/session.py) (DB Session), [`models/url_model.py`](https://github.com/damodarpurohit29/url_shortener/blob/main/models/url_model.py) (URL ORM Model)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["HTTP API"]
  node_app["FastAPI App<br/>[main.py]"]
  node_routes["URL Routes<br/>[url_api.py]"]
  node_schemas["Request and Response Schemas<br/>[url_schema.py]"]
end

subgraph group_logic["Shortening Logic"]
  node_codes["Code Generator<br/>[utils.py]"]
end

subgraph group_storage["Persistence"]
  node_url_model["URL ORM Model<br/>[url_model.py]"]
  node_db_session["DB Session<br/>[session.py]"]
  node_database[("URL Store")]
end

node_client(("Client"))
node_target(("Target Website"))

node_client -->|"sends HTTP requests"| node_app
node_app -->|"dispatches routes"| node_routes
node_routes -->|"validates and serializes"| node_schemas
node_routes -->|"generates code"| node_codes
node_routes -->|"gets DB session"| node_db_session
node_routes -->|"reads and writes mappings"| node_database
node_url_model -->|"maps URL records"| node_database
node_db_session -->|"creates DB connection"| node_database
node_routes -->|"redirects client"| node_target

click node_app "https://github.com/damodarpurohit29/url_shortener/blob/main/main.py"
click node_routes "https://github.com/damodarpurohit29/url_shortener/blob/main/api/url_api.py"
click node_schemas "https://github.com/damodarpurohit29/url_shortener/blob/main/schemas/url_schema.py"
click node_codes "https://github.com/damodarpurohit29/url_shortener/blob/main/utils.py"
click node_url_model "https://github.com/damodarpurohit29/url_shortener/blob/main/models/url_model.py"
click node_db_session "https://github.com/damodarpurohit29/url_shortener/blob/main/db/session.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_routes,node_schemas,node_client toneBlue
class node_codes toneAmber
class node_url_model,node_db_session,node_database toneMint
class node_target toneIndigo
```

## Components

### HTTP API

- [FastAPI App](https://github.com/damodarpurohit29/url_shortener/blob/main/main.py): `main.py`
- [URL Routes](https://github.com/damodarpurohit29/url_shortener/blob/main/api/url_api.py): `api/url_api.py`
- [Request and Response Schemas](https://github.com/damodarpurohit29/url_shortener/blob/main/schemas/url_schema.py): `schemas/url_schema.py`

### Shortening Logic

- [Code Generator](https://github.com/damodarpurohit29/url_shortener/blob/main/utils.py): `utils.py`

### Persistence

- [URL ORM Model](https://github.com/damodarpurohit29/url_shortener/blob/main/models/url_model.py): `models/url_model.py`
- [DB Session](https://github.com/damodarpurohit29/url_shortener/blob/main/db/session.py): `db/session.py`
- **URL Store**

### Other components

- **Client**
- **Target Website**

## Connections

- Client → FastAPI App: sends HTTP requests
- FastAPI App → URL Routes: dispatches routes
- URL Routes → Request and Response Schemas: validates and serializes
- URL Routes → Code Generator: generates code
- URL Routes → DB Session: gets DB session
- URL Routes → URL Store: reads and writes mappings
- URL ORM Model → URL Store: maps URL records
- DB Session → URL Store: creates DB connection
- URL Routes → Target Website: redirects client
