# pratyushmjm/url-shortner architecture

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

- Interactive diagram: https://gitdiagram.com/pratyushmjm/url-shortner
- Repository: https://github.com/pratyushmjm/url-shortner

## Overview

This is an Express URL-shortening service. A client submits a long URL; the route delegates to a controller that generates an ID and stores the mapping. A request to that ID records a visit and redirects to the saved URL; analytics returns the recorded visits and click count. MongoDB holds URL records, and Nano ID supplies short IDs. The graph reflects the supplied source; it does not imply behavior beyond the documented features and sampled implementation.

Main entry points: [`urlshortener/index.js`](https://github.com/pratyushmjm/url-shortner/blob/main/urlshortener/index.js) (Express app), [`urlshortener/controller/url.js`](https://github.com/pratyushmjm/url-shortner/blob/main/urlshortener/controller/url.js) (URL controller), [`urlshortener/models/url.js`](https://github.com/pratyushmjm/url-shortner/blob/main/urlshortener/models/url.js) (URL model), [`urlshortener/routes/url.js`](https://github.com/pratyushmjm/url-shortner/blob/main/urlshortener/routes/url.js) (URL routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_http["HTTP interface"]
  node_app["Express app<br/>[index.js]"]
  node_routes["URL routes<br/>[url.js]"]
end

subgraph group_shortening["Shortening and analytics"]
  node_controller["URL controller<br/>[url.js]"]
  node_nanoid["Nano ID"]
end

subgraph group_persistence["Persistence"]
  node_model["URL model<br/>[url.js]"]
  node_connect["Mongo connector<br/>[connect.js]"]
  node_mongodb[("MongoDB")]
end

node_client(("API client"))

node_client -->|"sends requests"| node_app
node_app -->|"mounts at /url"| node_routes
node_routes -->|"delegates POST"| node_controller
node_controller -->|"generates ID"| node_nanoid
node_controller -->|"creates mapping"| node_model
node_app -->|"records visit"| node_model
node_app -->|"requests analytics"| node_controller
node_controller -->|"reads analytics"| node_model
node_app -->|"connects to database"| node_connect
node_model -->|"reads and writes"| node_mongodb
node_connect -->|"establishes connection"| node_mongodb
node_app -->|"redirects or returns analytics"| node_client

click node_app "https://github.com/pratyushmjm/url-shortner/blob/main/urlshortener/index.js"
click node_routes "https://github.com/pratyushmjm/url-shortner/blob/main/urlshortener/routes/url.js"
click node_controller "https://github.com/pratyushmjm/url-shortner/blob/main/urlshortener/controller/url.js"
click node_model "https://github.com/pratyushmjm/url-shortner/blob/main/urlshortener/models/url.js"
click node_connect "https://github.com/pratyushmjm/url-shortner/blob/main/urlshortener/connect.js"

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_client toneBlue
class node_controller,node_nanoid toneAmber
class node_model,node_connect,node_mongodb toneMint
```

## Components

### HTTP interface

- [Express app](https://github.com/pratyushmjm/url-shortner/blob/main/urlshortener/index.js): `urlshortener/index.js`
- [URL routes](https://github.com/pratyushmjm/url-shortner/blob/main/urlshortener/routes/url.js): `urlshortener/routes/url.js`

### Shortening and analytics

- [URL controller](https://github.com/pratyushmjm/url-shortner/blob/main/urlshortener/controller/url.js): `urlshortener/controller/url.js`
- **Nano ID**

### Persistence

- [URL model](https://github.com/pratyushmjm/url-shortner/blob/main/urlshortener/models/url.js): `urlshortener/models/url.js`
- [Mongo connector](https://github.com/pratyushmjm/url-shortner/blob/main/urlshortener/connect.js): `urlshortener/connect.js`
- **MongoDB**

### Other components

- **API client**

## Connections

- API client → Express app: sends requests
- Express app → URL routes: mounts at /url
- URL routes → URL controller: delegates POST
- URL controller → Nano ID: generates ID
- URL controller → URL model: creates mapping
- Express app → URL model: records visit
- Express app → URL controller: requests analytics
- URL controller → URL model: reads analytics
- Express app → Mongo connector: connects to database
- URL model → MongoDB: reads and writes
- Mongo connector → MongoDB: establishes connection
- Express app → API client: redirects or returns analytics
