# bhanu20102004/url-shortener architecture

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

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

## Overview

This Django service accepts URLs, validates them, creates unique short codes, and stores links with optional expiry. Visitors resolve codes through a redirect that records click details; separate API endpoints list links, report click statistics, and delete links. The graph distinguishes those domain stages and the underlying link/click records. The redirect and CRUD behavior is visible in the sampled views; the database configuration is explicit, while some ORM-to-database wiring follows Django’s documented behavior.

Main entry points: [`links/urls.py`](https://github.com/bhanu20102004/url-shortener/blob/main/links/urls.py) (Link routes), [`links/models.py`](https://github.com/bhanu20102004/url-shortener/blob/main/links/models.py) (Link and click records), [`links/views.py`](https://github.com/bhanu20102004/url-shortener/blob/main/links/views.py) (Create link), [`config/urls.py`](https://github.com/bhanu20102004/url-shortener/blob/main/config/urls.py) (URL dispatch)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_routing["HTTP routing"]
  node_url_dispatch["URL dispatch<br/>[urls.py]"]
  node_link_routes["Link routes<br/>[urls.py]"]
end

subgraph group_operations["Link operations"]
  node_create["Create link<br/>[views.py]"]
  node_code_generator["Code generator<br/>[utils.py]"]
  node_redirect["Resolve redirect<br/>[views.py]"]
  node_statistics["Click statistics<br/>[views.py]"]
  node_listing["List links<br/>[views.py]"]
  node_deletion["Delete link<br/>[views.py]"]
end

subgraph group_records["Stored records"]
  node_records_model[("Link and click records<br/>[models.py]")]
  node_database_config["SQLite configuration<br/>[settings.py]"]
end

node_visitor(("API client"))
node_destination(("Destination website"))

node_visitor -->|"sends requests"| node_url_dispatch
node_url_dispatch -->|"includes routes"| node_link_routes
node_link_routes -->|"routes create"| node_create
node_link_routes -->|"routes codes"| node_redirect
node_link_routes -->|"routes stats"| node_statistics
node_link_routes -->|"routes listing"| node_listing
node_link_routes -->|"routes delete"| node_deletion
node_create -->|"requests code"| node_code_generator
node_create -->|"creates link"| node_records_model
node_code_generator -->|"checks collisions"| node_records_model
node_redirect -->|"looks up and logs"| node_records_model
node_redirect -->|"redirects visitor"| node_destination
node_statistics -->|"reads click data"| node_records_model
node_listing -->|"reads links"| node_records_model
node_deletion -->|"deletes link"| node_records_model
node_database_config -.->|"configures storage"| node_records_model

click node_url_dispatch "https://github.com/bhanu20102004/url-shortener/blob/main/config/urls.py"
click node_link_routes "https://github.com/bhanu20102004/url-shortener/blob/main/links/urls.py"
click node_create "https://github.com/bhanu20102004/url-shortener/blob/main/links/views.py"
click node_code_generator "https://github.com/bhanu20102004/url-shortener/blob/main/links/utils.py"
click node_redirect "https://github.com/bhanu20102004/url-shortener/blob/main/links/views.py"
click node_statistics "https://github.com/bhanu20102004/url-shortener/blob/main/links/views.py"
click node_listing "https://github.com/bhanu20102004/url-shortener/blob/main/links/views.py"
click node_deletion "https://github.com/bhanu20102004/url-shortener/blob/main/links/views.py"
click node_records_model "https://github.com/bhanu20102004/url-shortener/blob/main/links/models.py"
click node_database_config "https://github.com/bhanu20102004/url-shortener/blob/main/config/settings.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_url_dispatch,node_link_routes,node_visitor toneBlue
class node_create,node_code_generator,node_redirect,node_statistics,node_listing,node_deletion toneAmber
class node_records_model,node_database_config toneMint
class node_destination toneIndigo
```

## Components

### HTTP routing

- [URL dispatch](https://github.com/bhanu20102004/url-shortener/blob/main/config/urls.py): `config/urls.py`
- [Link routes](https://github.com/bhanu20102004/url-shortener/blob/main/links/urls.py): `links/urls.py`

### Link operations

- [Create link](https://github.com/bhanu20102004/url-shortener/blob/main/links/views.py): `links/views.py`
- [Code generator](https://github.com/bhanu20102004/url-shortener/blob/main/links/utils.py): `links/utils.py`
- [Resolve redirect](https://github.com/bhanu20102004/url-shortener/blob/main/links/views.py): `links/views.py`
- [Click statistics](https://github.com/bhanu20102004/url-shortener/blob/main/links/views.py): `links/views.py`
- [List links](https://github.com/bhanu20102004/url-shortener/blob/main/links/views.py): `links/views.py`
- [Delete link](https://github.com/bhanu20102004/url-shortener/blob/main/links/views.py): `links/views.py`

### Stored records

- [Link and click records](https://github.com/bhanu20102004/url-shortener/blob/main/links/models.py): `links/models.py`
- [SQLite configuration](https://github.com/bhanu20102004/url-shortener/blob/main/config/settings.py): `config/settings.py`

### Other components

- **API client**
- **Destination website**

## Connections

- API client → URL dispatch: sends requests (evidence: `README.md`)
- URL dispatch → Link routes: includes routes (evidence: `config/urls.py`)
- Link routes → Create link: routes create (evidence: `links/urls.py`)
- Link routes → Resolve redirect: routes codes (evidence: `links/urls.py`)
- Link routes → Click statistics: routes stats (evidence: `links/urls.py`)
- Link routes → List links: routes listing (evidence: `links/urls.py`)
- Link routes → Delete link: routes delete (evidence: `links/urls.py`)
- Create link → Code generator: requests code (evidence: `links/views.py`)
- Create link → Link and click records: creates link (evidence: `links/views.py`)
- Code generator → Link and click records: checks collisions (evidence: `links/utils.py`)
- Resolve redirect → Link and click records: looks up and logs (evidence: `links/views.py`)
- Resolve redirect → Destination website: redirects visitor (evidence: `links/views.py`)
- Click statistics → Link and click records: reads click data (evidence: `links/views.py`)
- List links → Link and click records: reads links (evidence: `links/views.py`)
- Delete link → Link and click records: deletes link (evidence: `links/views.py`)
- SQLite configuration → Link and click records: configures storage (evidence: `README.md`)
