# amanbtech/shorturl architecture

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

- Interactive diagram: https://gitdiagram.com/amanbtech/shorturl
- Repository: https://github.com/amanbtech/shorturl

## Overview

This repository implements a URL-shortener web application: users create short links, share them, and redirect visitors, with account management and link metrics as supporting capabilities. The backend is a FastAPI service that routes authentication and link operations to SQLite and Redis; a scheduler refreshes cached popular links and synchronizes click counts. The frontend tree also includes dashboard, analytics, link-management, profile, settings, and password-recovery screens. README documentation is absent, and some frontend/backend wiring is not shown, so those connections are omitted or marked unverified.

Main entry points: [`routes/url_routes.py`](https://github.com/amanbtech/shorturl/blob/main/routes/url_routes.py) (Short links), [`main.py`](https://github.com/amanbtech/shorturl/blob/main/main.py) (FastAPI app), [`routes/auth_routes.py`](https://github.com/amanbtech/shorturl/blob/main/routes/auth_routes.py) (Authentication), [`frontend/craete.js`](https://github.com/amanbtech/shorturl/blob/main/frontend/craete.js) (Create links)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web interface"]
  node_web_auth["Sign in / signup<br/>[script.js]"]
  node_web_create["Create links<br/>[craete.js]"]
  node_web_links["Manage links<br/>[myurl.js]"]
  node_web_dashboard["Dashboard<br/>[dashboard.js]"]
  node_web_analytics["Analytics<br/>[analystics.js]"]
  node_web_account["Account screens<br/>[profile.js]"]
  node_web_recovery["Password recovery<br/>[forget.js]"]
end

subgraph group_api["API and domain"]
  node_app["FastAPI app<br/>[main.py]"]
  node_auth_api["Authentication<br/>[auth_routes.py]"]
  node_link_api["Short links<br/>[url_routes.py]"]
  node_metrics_api["Link metrics<br/>[url_routes.py]"]
  node_recovery_api["Password recovery<br/>[url_routes.py]"]
  node_auth_logic["Token and passwords<br/>[auth.py]"]
  node_request_models["Request schemas<br/>[schemas.py]"]
  node_code_utils["Code and OTP helpers<br/>[utils.py]"]
end

subgraph group_state["Persistence and cache"]
  node_users_db[("User records<br/>[database.py]")]
  node_links_db[("Link records<br/>[database.py]")]
  node_redis_cache[("Redis cache<br/>[redis_client.py]")]
end

subgraph group_ops["Background maintenance"]
  node_scheduler["Cache and click sync<br/>[scheduler.py]"]
end

node_visitor(("Visitor"))

node_visitor -->|"creates links"| node_web_create
node_web_create -->|"submits link"| node_link_api
node_web_create -->|"requests dashboard"| node_link_api
node_app -->|"registers router"| node_auth_api
node_app -->|"registers router"| node_link_api
node_app -->|"starts scheduler"| node_scheduler
node_app -->|"initializes tables"| node_users_db
node_auth_api -->|"validates requests"| node_request_models
node_auth_api -->|"reads and writes users"| node_users_db
node_auth_api -->|"hashes and verifies"| node_auth_logic
node_link_api -->|"validates requests"| node_request_models
node_link_api -->|"checks current user"| node_auth_logic
node_link_api -->|"reads and writes links"| node_links_db
node_link_api -->|"reads and updates cache"| node_redis_cache
node_link_api -->|"generates link codes"| node_code_utils
node_metrics_api -->|"queries link metrics"| node_links_db
node_recovery_api -->|"updates password"| node_users_db
node_recovery_api -->|"stores OTP"| node_redis_cache
node_recovery_api -->|"generates OTP"| node_code_utils
node_scheduler -->|"reads and updates links"| node_links_db
node_scheduler -->|"refreshes and reads cache"| node_redis_cache

click node_web_auth "https://github.com/amanbtech/shorturl/blob/main/frontend/script.js"
click node_web_create "https://github.com/amanbtech/shorturl/blob/main/frontend/craete.js"
click node_web_links "https://github.com/amanbtech/shorturl/blob/main/frontend/myurl.js"
click node_web_dashboard "https://github.com/amanbtech/shorturl/blob/main/frontend/dashboard.js"
click node_web_analytics "https://github.com/amanbtech/shorturl/blob/main/frontend/analystics.js"
click node_web_account "https://github.com/amanbtech/shorturl/blob/main/frontend/profile.js"
click node_web_recovery "https://github.com/amanbtech/shorturl/blob/main/frontend/forget.js"
click node_app "https://github.com/amanbtech/shorturl/blob/main/main.py"
click node_auth_api "https://github.com/amanbtech/shorturl/blob/main/routes/auth_routes.py"
click node_link_api "https://github.com/amanbtech/shorturl/blob/main/routes/url_routes.py"
click node_metrics_api "https://github.com/amanbtech/shorturl/blob/main/routes/url_routes.py"
click node_recovery_api "https://github.com/amanbtech/shorturl/blob/main/routes/url_routes.py"
click node_auth_logic "https://github.com/amanbtech/shorturl/blob/main/auth.py"
click node_request_models "https://github.com/amanbtech/shorturl/blob/main/schemas.py"
click node_code_utils "https://github.com/amanbtech/shorturl/blob/main/utils.py"
click node_users_db "https://github.com/amanbtech/shorturl/blob/main/database.py"
click node_links_db "https://github.com/amanbtech/shorturl/blob/main/database.py"
click node_redis_cache "https://github.com/amanbtech/shorturl/blob/main/redis_client.py"
click node_scheduler "https://github.com/amanbtech/shorturl/blob/main/scheduler.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_web_auth,node_web_create,node_web_links,node_web_dashboard,node_web_analytics,node_web_account,node_web_recovery toneBlue
class node_app,node_auth_api,node_link_api,node_metrics_api,node_recovery_api,node_auth_logic,node_request_models,node_code_utils toneAmber
class node_users_db,node_links_db,node_redis_cache toneMint
class node_scheduler toneRose
class node_visitor toneIndigo
```

## Components

### Web interface

- [Sign in / signup](https://github.com/amanbtech/shorturl/blob/main/frontend/script.js): `frontend/script.js`
- [Create links](https://github.com/amanbtech/shorturl/blob/main/frontend/craete.js): `frontend/craete.js`
- [Manage links](https://github.com/amanbtech/shorturl/blob/main/frontend/myurl.js): `frontend/myurl.js`
- [Dashboard](https://github.com/amanbtech/shorturl/blob/main/frontend/dashboard.js): `frontend/dashboard.js`
- [Analytics](https://github.com/amanbtech/shorturl/blob/main/frontend/analystics.js): `frontend/analystics.js`
- [Account screens](https://github.com/amanbtech/shorturl/blob/main/frontend/profile.js): `frontend/profile.js`
- [Password recovery](https://github.com/amanbtech/shorturl/blob/main/frontend/forget.js): `frontend/forget.js`

### API and domain

- [FastAPI app](https://github.com/amanbtech/shorturl/blob/main/main.py): `main.py`
- [Authentication](https://github.com/amanbtech/shorturl/blob/main/routes/auth_routes.py): `routes/auth_routes.py`
- [Short links](https://github.com/amanbtech/shorturl/blob/main/routes/url_routes.py): `routes/url_routes.py`
- [Link metrics](https://github.com/amanbtech/shorturl/blob/main/routes/url_routes.py): `routes/url_routes.py`
- [Password recovery](https://github.com/amanbtech/shorturl/blob/main/routes/url_routes.py): `routes/url_routes.py`
- [Token and passwords](https://github.com/amanbtech/shorturl/blob/main/auth.py): `auth.py`
- [Request schemas](https://github.com/amanbtech/shorturl/blob/main/schemas.py): `schemas.py`
- [Code and OTP helpers](https://github.com/amanbtech/shorturl/blob/main/utils.py): `utils.py`

### Persistence and cache

- [User records](https://github.com/amanbtech/shorturl/blob/main/database.py): `database.py`
- [Link records](https://github.com/amanbtech/shorturl/blob/main/database.py): `database.py`
- [Redis cache](https://github.com/amanbtech/shorturl/blob/main/redis_client.py): `redis_client.py`

### Background maintenance

- [Cache and click sync](https://github.com/amanbtech/shorturl/blob/main/scheduler.py): `scheduler.py`

### Other components

- **Visitor**

## Connections

- Visitor → Create links: creates links
- Create links → Short links: submits link (evidence: `frontend/craete.js`)
- Create links → Short links: requests dashboard (evidence: `frontend/craete.js`)
- FastAPI app → Authentication: registers router (evidence: `main.py`)
- FastAPI app → Short links: registers router (evidence: `main.py`)
- FastAPI app → Cache and click sync: starts scheduler (evidence: `main.py`)
- FastAPI app → User records: initializes tables (evidence: `main.py`)
- Authentication → Request schemas: validates requests (evidence: `routes/auth_routes.py`)
- Authentication → User records: reads and writes users (evidence: `routes/auth_routes.py`)
- Authentication → Token and passwords: hashes and verifies (evidence: `routes/auth_routes.py`)
- Short links → Request schemas: validates requests (evidence: `routes/url_routes.py`)
- Short links → Token and passwords: checks current user (evidence: `routes/url_routes.py`)
- Short links → Link records: reads and writes links (evidence: `routes/url_routes.py`)
- Short links → Redis cache: reads and updates cache (evidence: `routes/url_routes.py`)
- Short links → Code and OTP helpers: generates link codes (evidence: `routes/url_routes.py`)
- Link metrics → Link records: queries link metrics (evidence: `routes/url_routes.py`)
- Password recovery → User records: updates password (evidence: `routes/url_routes.py`)
- Password recovery → Redis cache: stores OTP (evidence: `routes/url_routes.py`)
- Password recovery → Code and OTP helpers: generates OTP (evidence: `routes/url_routes.py`)
- Cache and click sync → Link records: reads and updates links (evidence: `scheduler.py`)
- Cache and click sync → Redis cache: refreshes and reads cache (evidence: `scheduler.py`)
