# alexwithstars/shortlink architecture

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

- Interactive diagram: https://gitdiagram.com/alexwithstars/shortlink
- Repository: https://github.com/alexwithstars/shortlink

## Overview

This is a URL-shortening service with a browser-based link administration UI. The main workflow is to submit and validate a link, create or edit it through the API, persist it through the configured model, and redirect visitors through its alias while recording clicks. The API also exposes link lists, aliases, individual links, and click counts. MongoDB is shown from sampled implementation; Firebase exists in the tree, but its runtime wiring was not verified. The README is empty, so feature coverage relies on the source index and excerpts.

Main entry points: [`src/index.js`](https://github.com/alexwithstars/shortlink/blob/main/src/index.js) (Express server), [`src/routes/shortener.js`](https://github.com/alexwithstars/shortlink/blob/main/src/routes/shortener.js) (API routes), [`src/models/mongodb/shortener.js`](https://github.com/alexwithstars/shortlink/blob/main/src/models/mongodb/shortener.js) (Mongo link model), [`src/controllers/shortener.js`](https://github.com/alexwithstars/shortlink/blob/main/src/controllers/shortener.js) (Link controller)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["HTTP service"]
  node_server["Express server<br/>[index.js]"]
  node_routes["API routes<br/>[shortener.js]"]
  node_dev_tracking["Development tracking<br/>[development.js]"]
end

subgraph group_domain["Link operations"]
  node_controller["Link controller<br/>[shortener.js]"]
  node_validation["Request validation<br/>[shortener.js]"]
  node_link_schema["Link schema<br/>[links.js]"]
end

subgraph group_persistence["Persistence"]
  node_model_mongo["Mongo link model<br/>[shortener.js]"]
  node_mongo_schema["Mongo link schema<br/>[models.js]"]
  node_mongo_db[("MongoDB")]
  node_model_firebase["Firebase model<br/>[shortener.js]"]
end

subgraph group_admin["Admin interface"]
  node_admin_ui["Admin UI<br/>[main.js]"]
  node_api_client["Browser API client<br/>[links.js]"]
  node_view_assets["Admin page assets<br/>[index.html]"]
end

subgraph group_shared["Shared support"]
  node_schema_errors["Validation errors<br/>[all.js]"]
  node_response_errors["API responses<br/>[reponse.js]"]
  node_debug["Debug diagnostics<br/>[debug.js]"]
  node_constants["Routes and config<br/>[consts.js]"]
end

node_visitor(("Link visitor"))
node_admin_user(("Admin user"))

node_visitor -->|"requests"| node_server
node_admin_user -->|"manages links"| node_admin_ui
node_server -->|"mounts router"| node_routes
node_server -->|"uses in development"| node_dev_tracking
node_server -->|"runs when enabled"| node_debug
node_server -.->|"selects configured model"| node_model_mongo
node_server -.->|"may select model"| node_model_firebase
node_routes -->|"dispatches handlers"| node_controller
node_routes -->|"validates mutations"| node_validation
node_validation -->|"validates payload"| node_link_schema
node_validation -->|"formats errors"| node_schema_errors
node_routes -->|"returns auth errors"| node_response_errors
node_controller -.->|"performs link operations"| node_model_mongo
node_model_mongo -->|"uses Link model"| node_mongo_schema
node_model_mongo -->|"reads and writes"| node_mongo_db
node_admin_ui -->|"calls"| node_api_client
node_api_client -->|"sends HTTP requests"| node_routes
node_server -->|"serves static UI"| node_view_assets
node_server -->|"reads configuration"| node_constants
node_controller -->|"returns link errors"| node_response_errors

click node_server "https://github.com/alexwithstars/shortlink/blob/main/src/index.js"
click node_routes "https://github.com/alexwithstars/shortlink/blob/main/src/routes/shortener.js"
click node_controller "https://github.com/alexwithstars/shortlink/blob/main/src/controllers/shortener.js"
click node_validation "https://github.com/alexwithstars/shortlink/blob/main/src/middlewares/shortener.js"
click node_link_schema "https://github.com/alexwithstars/shortlink/blob/main/src/schemas/links.js"
click node_schema_errors "https://github.com/alexwithstars/shortlink/blob/main/src/schemas/all.js"
click node_response_errors "https://github.com/alexwithstars/shortlink/blob/main/src/utils/reponse.js"
click node_model_mongo "https://github.com/alexwithstars/shortlink/blob/main/src/models/mongodb/shortener.js"
click node_mongo_schema "https://github.com/alexwithstars/shortlink/blob/main/src/models/mongodb/models.js"
click node_model_firebase "https://github.com/alexwithstars/shortlink/blob/main/src/models/firebase/shortener.js"
click node_admin_ui "https://github.com/alexwithstars/shortlink/blob/main/src/view/main.js"
click node_api_client "https://github.com/alexwithstars/shortlink/blob/main/src/view/apis/links.js"
click node_view_assets "https://github.com/alexwithstars/shortlink/blob/main/src/view/index.html"
click node_dev_tracking "https://github.com/alexwithstars/shortlink/blob/main/src/middlewares/development.js"
click node_debug "https://github.com/alexwithstars/shortlink/blob/main/src/debug.js"
click node_constants "https://github.com/alexwithstars/shortlink/blob/main/src/utils/consts.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_server,node_routes,node_dev_tracking,node_admin_user toneBlue
class node_controller,node_validation,node_link_schema toneAmber
class node_model_mongo,node_mongo_schema,node_mongo_db,node_model_firebase toneMint
class node_admin_ui,node_api_client,node_view_assets toneRose
class node_schema_errors,node_response_errors,node_debug,node_constants,node_visitor toneIndigo
```

## Components

### HTTP service

- [Express server](https://github.com/alexwithstars/shortlink/blob/main/src/index.js): `src/index.js`
- [API routes](https://github.com/alexwithstars/shortlink/blob/main/src/routes/shortener.js): `src/routes/shortener.js`
- [Development tracking](https://github.com/alexwithstars/shortlink/blob/main/src/middlewares/development.js): `src/middlewares/development.js`

### Link operations

- [Link controller](https://github.com/alexwithstars/shortlink/blob/main/src/controllers/shortener.js): `src/controllers/shortener.js`
- [Request validation](https://github.com/alexwithstars/shortlink/blob/main/src/middlewares/shortener.js): `src/middlewares/shortener.js`
- [Link schema](https://github.com/alexwithstars/shortlink/blob/main/src/schemas/links.js): `src/schemas/links.js`

### Persistence

- [Mongo link model](https://github.com/alexwithstars/shortlink/blob/main/src/models/mongodb/shortener.js): `src/models/mongodb/shortener.js`
- [Mongo link schema](https://github.com/alexwithstars/shortlink/blob/main/src/models/mongodb/models.js): `src/models/mongodb/models.js`
- **MongoDB**
- [Firebase model](https://github.com/alexwithstars/shortlink/blob/main/src/models/firebase/shortener.js): `src/models/firebase/shortener.js`

### Admin interface

- [Admin UI](https://github.com/alexwithstars/shortlink/blob/main/src/view/main.js): `src/view/main.js`
- [Browser API client](https://github.com/alexwithstars/shortlink/blob/main/src/view/apis/links.js): `src/view/apis/links.js`
- [Admin page assets](https://github.com/alexwithstars/shortlink/blob/main/src/view/index.html): `src/view/index.html`

### Shared support

- [Validation errors](https://github.com/alexwithstars/shortlink/blob/main/src/schemas/all.js): `src/schemas/all.js`
- [API responses](https://github.com/alexwithstars/shortlink/blob/main/src/utils/reponse.js): `src/utils/reponse.js`
- [Debug diagnostics](https://github.com/alexwithstars/shortlink/blob/main/src/debug.js): `src/debug.js`
- [Routes and config](https://github.com/alexwithstars/shortlink/blob/main/src/utils/consts.js): `src/utils/consts.js`

### Other components

- **Link visitor**
- **Admin user**

## Connections

- Link visitor → Express server: requests (evidence: `src/index.js`)
- Admin user → Admin UI: manages links (evidence: `src/view/main.js`)
- Express server → API routes: mounts router (evidence: `src/index.js`)
- Express server → Development tracking: uses in development (evidence: `src/index.js`)
- Express server → Debug diagnostics: runs when enabled (evidence: `src/index.js`)
- Express server → Mongo link model: selects configured model
- Express server → Firebase model: may select model
- API routes → Link controller: dispatches handlers (evidence: `src/routes/shortener.js`)
- API routes → Request validation: validates mutations (evidence: `src/routes/shortener.js`)
- Request validation → Link schema: validates payload (evidence: `src/middlewares/shortener.js`)
- Request validation → Validation errors: formats errors (evidence: `src/middlewares/shortener.js`)
- API routes → API responses: returns auth errors (evidence: `src/routes/shortener.js`)
- Link controller → Mongo link model: performs link operations
- Mongo link model → Mongo link schema: uses Link model (evidence: `src/models/mongodb/shortener.js`)
- Mongo link model → MongoDB: reads and writes (evidence: `src/models/mongodb/shortener.js`)
- Admin UI → Browser API client: calls (evidence: `src/view/main.js`)
- Browser API client → API routes: sends HTTP requests (evidence: `src/view/apis/links.js`)
- Express server → Admin page assets: serves static UI (evidence: `src/index.js`)
- Express server → Routes and config: reads configuration (evidence: `src/index.js`)
- Link controller → API responses: returns link errors (evidence: `src/controllers/shortener.js`)
