# bal16/link3 architecture

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

- Interactive diagram: https://gitdiagram.com/bal16/link3
- Repository: https://github.com/bal16/link3

## Overview

Link3 is a self-hosted URL-shortener API. Requests enter through the Elysia server and controller; link operations validate or generate slugs, query the repository, and return API responses or redirects. The README also documents paginated search, JWT-protected writes, and Scalar OpenAPI docs. The excerpts show the route-to-service-to-repository calls; database and documentation capabilities are corroborated by the README and server setup, while unsampled Prisma schema details are not expanded.

Main entry points: [`src/app/controller.ts`](https://github.com/bal16/link3/blob/main/src/app/controller.ts) (Link routes), [`src/app/service.ts`](https://github.com/bal16/link3/blob/main/src/app/service.ts) (Link service), [`src/app/server.ts`](https://github.com/bal16/link3/blob/main/src/app/server.ts) (Elysia server), [`src/index.ts`](https://github.com/bal16/link3/blob/main/src/index.ts) (Application entrypoint)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API surface"]
  node_server["Elysia server<br/>[server.ts]"]
  node_routes["Link routes<br/>[controller.ts]"]
  node_jwt["JWT verification<br/>[controller.ts]"]
  node_schemas["Request schemas<br/>[link.model.ts]"]
  node_webresponse["Response model<br/>[web.model.ts]"]
end

subgraph group_links["Link operations"]
  node_linkservice["Link service<br/>[service.ts]"]
  node_sluglogic["Slug generation<br/>[service.ts]"]
  node_listing["Search and pagination<br/>[service.ts]"]
  node_redirect["Short-link redirect<br/>[controller.ts]"]
end

subgraph group_storage["Persistence"]
  node_repository["Prisma repository<br/>[repository.ts]"]
  node_postgres[("PostgreSQL")]
end

subgraph group_platform["Runtime and docs"]
  node_runtime["Application entrypoint<br/>[index.ts]"]
  node_baseurl["Base URL config<br/>[const.ts]"]
  node_apidocs["OpenAPI and Scalar<br/>[server.ts]"]
end

node_client(("API client"))

node_client -->|"sends requests"| node_runtime
node_runtime -->|"starts"| node_server
node_server -->|"mounts"| node_routes
node_client -->|"calls routes"| node_routes
node_routes -->|"verifies writes"| node_jwt
node_routes -->|"validates bodies"| node_schemas
node_routes -->|"invokes operations"| node_linkservice
node_linkservice -->|"generates slugs"| node_sluglogic
node_linkservice -->|"searches and pages"| node_listing
node_linkservice -->|"queries links"| node_repository
node_repository -->|"reads and writes"| node_postgres
node_routes -->|"resolves slug"| node_redirect
node_redirect -->|"gets target URL"| node_linkservice
node_linkservice -->|"builds short URLs"| node_baseurl
node_runtime -->|"logs address"| node_baseurl
node_routes -->|"returns envelopes"| node_webresponse
node_server -->|"configures docs"| node_apidocs
node_client -->|"opens UI"| node_apidocs

click node_server "https://github.com/bal16/link3/blob/main/src/app/server.ts"
click node_routes "https://github.com/bal16/link3/blob/main/src/app/controller.ts"
click node_jwt "https://github.com/bal16/link3/blob/main/src/app/controller.ts"
click node_schemas "https://github.com/bal16/link3/blob/main/src/app/model/link.model.ts"
click node_webresponse "https://github.com/bal16/link3/blob/main/src/app/model/web.model.ts"
click node_linkservice "https://github.com/bal16/link3/blob/main/src/app/service.ts"
click node_sluglogic "https://github.com/bal16/link3/blob/main/src/app/service.ts"
click node_listing "https://github.com/bal16/link3/blob/main/src/app/service.ts"
click node_redirect "https://github.com/bal16/link3/blob/main/src/app/controller.ts"
click node_repository "https://github.com/bal16/link3/blob/main/src/app/repository.ts"
click node_runtime "https://github.com/bal16/link3/blob/main/src/index.ts"
click node_baseurl "https://github.com/bal16/link3/blob/main/src/const.ts"
click node_apidocs "https://github.com/bal16/link3/blob/main/src/app/server.ts"

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_jwt,node_schemas,node_webresponse,node_client toneBlue
class node_linkservice,node_sluglogic,node_listing,node_redirect toneAmber
class node_repository,node_postgres toneMint
class node_runtime,node_baseurl,node_apidocs toneRose
```

## Components

### API surface

- [Elysia server](https://github.com/bal16/link3/blob/main/src/app/server.ts): `src/app/server.ts`
- [Link routes](https://github.com/bal16/link3/blob/main/src/app/controller.ts): `src/app/controller.ts`
- [JWT verification](https://github.com/bal16/link3/blob/main/src/app/controller.ts): `src/app/controller.ts`
- [Request schemas](https://github.com/bal16/link3/blob/main/src/app/model/link.model.ts): `src/app/model/link.model.ts`
- [Response model](https://github.com/bal16/link3/blob/main/src/app/model/web.model.ts): `src/app/model/web.model.ts`

### Link operations

- [Link service](https://github.com/bal16/link3/blob/main/src/app/service.ts): `src/app/service.ts`
- [Slug generation](https://github.com/bal16/link3/blob/main/src/app/service.ts): `src/app/service.ts`
- [Search and pagination](https://github.com/bal16/link3/blob/main/src/app/service.ts): `src/app/service.ts`
- [Short-link redirect](https://github.com/bal16/link3/blob/main/src/app/controller.ts): `src/app/controller.ts`

### Persistence

- [Prisma repository](https://github.com/bal16/link3/blob/main/src/app/repository.ts): `src/app/repository.ts`
- **PostgreSQL**

### Runtime and docs

- [Application entrypoint](https://github.com/bal16/link3/blob/main/src/index.ts): `src/index.ts`
- [Base URL config](https://github.com/bal16/link3/blob/main/src/const.ts): `src/const.ts`
- [OpenAPI and Scalar](https://github.com/bal16/link3/blob/main/src/app/server.ts): `src/app/server.ts`

### Other components

- **API client**

## Connections

- API client → Application entrypoint: sends requests (evidence: `README.md`)
- Application entrypoint → Elysia server: starts (evidence: `src/index.ts`)
- Elysia server → Link routes: mounts (evidence: `src/app/server.ts`)
- API client → Link routes: calls routes (evidence: `README.md`)
- Link routes → JWT verification: verifies writes (evidence: `src/app/controller.ts`)
- Link routes → Request schemas: validates bodies (evidence: `src/app/controller.ts`)
- Link routes → Link service: invokes operations (evidence: `src/app/controller.ts`)
- Link service → Slug generation: generates slugs (evidence: `src/app/service.ts`)
- Link service → Search and pagination: searches and pages (evidence: `src/app/service.ts`)
- Link service → Prisma repository: queries links (evidence: `src/app/service.ts`)
- Prisma repository → PostgreSQL: reads and writes (evidence: `README.md`)
- Link routes → Short-link redirect: resolves slug (evidence: `src/app/controller.ts`)
- Short-link redirect → Link service: gets target URL (evidence: `src/app/controller.ts`)
- Link service → Base URL config: builds short URLs (evidence: `src/app/service.ts`)
- Application entrypoint → Base URL config: logs address (evidence: `src/index.ts`)
- Link routes → Response model: returns envelopes (evidence: `src/app/controller.ts`)
- Elysia server → OpenAPI and Scalar: configures docs (evidence: `src/app/server.ts`)
- API client → OpenAPI and Scalar: opens UI (evidence: `README.md`)
