# sm-joe/linkforge architecture

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

- Interactive diagram: https://gitdiagram.com/sm-joe/linkforge
- Repository: https://github.com/sm-joe/linkforge

## Overview

LinkForge is a self-hosted URL shortener: users create and manage validated short links in the web dashboard, then follow redirects and inspect QR codes, click analytics, and destination-health history. The Go API owns these workflows and persists link, click, and health data in SQLite; destination validation is a separate Go package. Arrows below follow sampled calls or explicit README/API documentation. Several handlers and storage modules were not excerpted, so their internal wiring is represented only where documented.

Main entry points: [`apps/api/cmd/server/main.go`](https://github.com/sm-joe/linkforge/blob/main/apps/api/cmd/server/main.go) (Go HTTP API), [`apps/api/internal/link/service.go`](https://github.com/sm-joe/linkforge/blob/main/apps/api/internal/link/service.go) (Link service), [`apps/web/lib/api.ts`](https://github.com/sm-joe/linkforge/blob/main/apps/web/lib/api.ts) (API client), [`apps/web/app/page.tsx`](https://github.com/sm-joe/linkforge/blob/main/apps/web/app/page.tsx) (Home page)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web dashboard"]
  node_home["Home page<br/>[page.tsx]"]
  node_createform["Create form<br/>[CreateLinkForm.tsx]"]
  node_dashboard["Links dashboard<br/>[Dashboard.tsx]"]
  node_linkcard["Link card<br/>[LinkCard.tsx]"]
  node_webapi["API client<br/>[api.ts]"]
end

subgraph group_api["API workflows"]
  node_api["Go HTTP API<br/>[main.go]"]
  node_linkhandlers["Link endpoints<br/>[link_handler.go]"]
  node_management["Link management"]
  node_analytics["Click analytics"]
  node_qr["QR endpoint<br/>[qr_handler.go]"]
  node_redirect["Redirect endpoint"]
  node_health["Health endpoints<br/>[health_handler.go]"]
  node_history["Health history"]
end

subgraph group_domain["Link domain"]
  node_service["Link service<br/>[service.go]"]
  node_healthservice["Health service<br/>[health_service.go]"]
  node_healthclient["Safe health client<br/>[health_client.go]"]
end

subgraph group_state["SQLite state"]
  node_linksrepo["SQLite link repository"]
  node_clickrepo["Click records"]
  node_healthrepo["Health records"]
  node_sqlite[("SQLite database<br/>[database.go]")]
end

subgraph group_validation["Destination safety"]
  node_urlvalidation["URL and IP validation<br/>[validator.go]"]
end

node_browser(("Browser"))
node_destination(("Destination host"))

node_browser -->|"opens dashboard"| node_home
node_home -->|"renders"| node_createform
node_home -->|"renders"| node_dashboard
node_createform -->|"creates link"| node_webapi
node_dashboard -->|"lists links"| node_webapi
node_dashboard -->|"renders"| node_linkcard
node_linkcard -->|"manages link"| node_webapi
node_webapi -->|"HTTP requests"| node_api
node_api -->|"routes link requests"| node_linkhandlers
node_api -->|"routes management"| node_management
node_api -->|"routes analytics"| node_analytics
node_api -->|"routes QR"| node_qr
node_api -->|"routes short codes"| node_redirect
node_api -->|"routes health"| node_health
node_api -->|"routes history"| node_history
node_linkhandlers -.->|"delegates"| node_service
node_management -->|"calls"| node_service
node_analytics -.->|"reads analytics"| node_clickrepo
node_redirect -.->|"records clicks"| node_clickrepo
node_health -.->|"runs checks"| node_healthservice
node_health -.->|"gets link"| node_service
node_history -.->|"reads history"| node_healthrepo
node_service -->|"validates destination"| node_urlvalidation
node_service -.->|"persists links"| node_linksrepo
node_healthservice -.->|"checks destination"| node_healthclient
node_healthservice -.->|"stores checks"| node_healthrepo
node_healthclient -->|"validates host"| node_urlvalidation
node_healthclient -->|"requests health"| node_destination
node_linksrepo -.->|"reads and writes"| node_sqlite
node_clickrepo -->|"reads and writes"| node_sqlite
node_healthrepo -.->|"reads and writes"| node_sqlite
node_urlvalidation -->|"resolves host"| node_destination

click node_home "https://github.com/sm-joe/linkforge/blob/main/apps/web/app/page.tsx"
click node_createform "https://github.com/sm-joe/linkforge/blob/main/apps/web/components/links/CreateLinkForm.tsx"
click node_dashboard "https://github.com/sm-joe/linkforge/blob/main/apps/web/components/links/Dashboard.tsx"
click node_linkcard "https://github.com/sm-joe/linkforge/blob/main/apps/web/components/links/LinkCard.tsx"
click node_webapi "https://github.com/sm-joe/linkforge/blob/main/apps/web/lib/api.ts"
click node_api "https://github.com/sm-joe/linkforge/blob/main/apps/api/cmd/server/main.go"
click node_linkhandlers "https://github.com/sm-joe/linkforge/blob/main/apps/api/internal/http/link_handler.go"
click node_management "https://github.com/sm-joe/linkforge/blob/main/apps/api/internal/http/link_management_handler.go"
click node_analytics "https://github.com/sm-joe/linkforge/blob/main/apps/api/internal/http/analytics_handler.go"
click node_qr "https://github.com/sm-joe/linkforge/blob/main/apps/api/internal/http/qr_handler.go"
click node_redirect "https://github.com/sm-joe/linkforge/blob/main/apps/api/internal/http/redirect_handler.go"
click node_health "https://github.com/sm-joe/linkforge/blob/main/apps/api/internal/http/health_handler.go"
click node_history "https://github.com/sm-joe/linkforge/blob/main/apps/api/internal/http/health_history_handler.go"
click node_service "https://github.com/sm-joe/linkforge/blob/main/apps/api/internal/link/service.go"
click node_healthservice "https://github.com/sm-joe/linkforge/blob/main/apps/api/internal/link/health_service.go"
click node_healthclient "https://github.com/sm-joe/linkforge/blob/main/apps/api/internal/link/health_client.go"
click node_linksrepo "https://github.com/sm-joe/linkforge/blob/main/apps/api/internal/link/sqlite_repository.go"
click node_clickrepo "https://github.com/sm-joe/linkforge/blob/main/apps/api/internal/link/click_repository.go"
click node_healthrepo "https://github.com/sm-joe/linkforge/blob/main/apps/api/internal/link/health_repository.go"
click node_sqlite "https://github.com/sm-joe/linkforge/blob/main/apps/api/internal/link/database.go"
click node_urlvalidation "https://github.com/sm-joe/linkforge/blob/main/packages/url-validation/validator.go"

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_home,node_createform,node_dashboard,node_linkcard,node_webapi,node_browser toneBlue
class node_api,node_linkhandlers,node_management,node_analytics,node_qr,node_redirect,node_health,node_history toneAmber
class node_service,node_healthservice,node_healthclient toneMint
class node_linksrepo,node_clickrepo,node_healthrepo,node_sqlite toneRose
class node_urlvalidation,node_destination toneIndigo
```

## Components

### Web dashboard

- [Home page](https://github.com/sm-joe/linkforge/blob/main/apps/web/app/page.tsx): `apps/web/app/page.tsx`
- [Create form](https://github.com/sm-joe/linkforge/blob/main/apps/web/components/links/CreateLinkForm.tsx): `apps/web/components/links/CreateLinkForm.tsx`
- [Links dashboard](https://github.com/sm-joe/linkforge/blob/main/apps/web/components/links/Dashboard.tsx): `apps/web/components/links/Dashboard.tsx`
- [Link card](https://github.com/sm-joe/linkforge/blob/main/apps/web/components/links/LinkCard.tsx): `apps/web/components/links/LinkCard.tsx`
- [API client](https://github.com/sm-joe/linkforge/blob/main/apps/web/lib/api.ts): `apps/web/lib/api.ts`

### API workflows

- [Go HTTP API](https://github.com/sm-joe/linkforge/blob/main/apps/api/cmd/server/main.go): `apps/api/cmd/server/main.go`
- [Link endpoints](https://github.com/sm-joe/linkforge/blob/main/apps/api/internal/http/link_handler.go): `apps/api/internal/http/link_handler.go`
- [Link management](https://github.com/sm-joe/linkforge/blob/main/apps/api/internal/http/link_management_handler.go): `apps/api/internal/http/link_management_handler.go`
- [Click analytics](https://github.com/sm-joe/linkforge/blob/main/apps/api/internal/http/analytics_handler.go): `apps/api/internal/http/analytics_handler.go`
- [QR endpoint](https://github.com/sm-joe/linkforge/blob/main/apps/api/internal/http/qr_handler.go): `apps/api/internal/http/qr_handler.go`
- [Redirect endpoint](https://github.com/sm-joe/linkforge/blob/main/apps/api/internal/http/redirect_handler.go): `apps/api/internal/http/redirect_handler.go`
- [Health endpoints](https://github.com/sm-joe/linkforge/blob/main/apps/api/internal/http/health_handler.go): `apps/api/internal/http/health_handler.go`
- [Health history](https://github.com/sm-joe/linkforge/blob/main/apps/api/internal/http/health_history_handler.go): `apps/api/internal/http/health_history_handler.go`

### Link domain

- [Link service](https://github.com/sm-joe/linkforge/blob/main/apps/api/internal/link/service.go): `apps/api/internal/link/service.go`
- [Health service](https://github.com/sm-joe/linkforge/blob/main/apps/api/internal/link/health_service.go): `apps/api/internal/link/health_service.go`
- [Safe health client](https://github.com/sm-joe/linkforge/blob/main/apps/api/internal/link/health_client.go): `apps/api/internal/link/health_client.go`

### SQLite state

- [SQLite link repository](https://github.com/sm-joe/linkforge/blob/main/apps/api/internal/link/sqlite_repository.go): `apps/api/internal/link/sqlite_repository.go`
- [Click records](https://github.com/sm-joe/linkforge/blob/main/apps/api/internal/link/click_repository.go): `apps/api/internal/link/click_repository.go`
- [Health records](https://github.com/sm-joe/linkforge/blob/main/apps/api/internal/link/health_repository.go): `apps/api/internal/link/health_repository.go`
- [SQLite database](https://github.com/sm-joe/linkforge/blob/main/apps/api/internal/link/database.go): `apps/api/internal/link/database.go`

### Destination safety

- [URL and IP validation](https://github.com/sm-joe/linkforge/blob/main/packages/url-validation/validator.go): `packages/url-validation/validator.go`

### Other components

- **Browser**
- **Destination host**

## Connections

- Browser → Home page: opens dashboard (evidence: `README.md`)
- Home page → Create form: renders (evidence: `apps/web/app/page.tsx`)
- Home page → Links dashboard: renders (evidence: `apps/web/app/page.tsx`)
- Create form → API client: creates link (evidence: `apps/web/components/links/CreateLinkForm.tsx`)
- Links dashboard → API client: lists links (evidence: `apps/web/components/links/Dashboard.tsx`)
- Links dashboard → Link card: renders (evidence: `apps/web/components/links/Dashboard.tsx`)
- Link card → API client: manages link (evidence: `apps/web/components/links/LinkCard.tsx`)
- API client → Go HTTP API: HTTP requests (evidence: `README.md`)
- Go HTTP API → Link endpoints: routes link requests (evidence: `apps/api/cmd/server/main.go`)
- Go HTTP API → Link management: routes management (evidence: `apps/api/cmd/server/main.go`)
- Go HTTP API → Click analytics: routes analytics (evidence: `apps/api/cmd/server/main.go`)
- Go HTTP API → QR endpoint: routes QR (evidence: `apps/api/cmd/server/main.go`)
- Go HTTP API → Redirect endpoint: routes short codes (evidence: `apps/api/cmd/server/main.go`)
- Go HTTP API → Health endpoints: routes health (evidence: `apps/api/cmd/server/main.go`)
- Go HTTP API → Health history: routes history (evidence: `apps/api/cmd/server/main.go`)
- Link endpoints → Link service: delegates
- Link management → Link service: calls (evidence: `apps/api/internal/http/link_management_handler.go`)
- Click analytics → Click records: reads analytics
- Redirect endpoint → Click records: records clicks
- Health endpoints → Health service: runs checks
- Health endpoints → Link service: gets link
- Health history → Health records: reads history
- Link service → URL and IP validation: validates destination (evidence: `apps/api/internal/link/service.go`)
- Link service → SQLite link repository: persists links
- Health service → Safe health client: checks destination
- Health service → Health records: stores checks
- Safe health client → URL and IP validation: validates host (evidence: `apps/api/internal/link/health_client.go`)
- Safe health client → Destination host: requests health (evidence: `apps/api/internal/link/health_client.go`)
- SQLite link repository → SQLite database: reads and writes
- Click records → SQLite database: reads and writes (evidence: `apps/api/internal/link/click_repository.go`)
- Health records → SQLite database: reads and writes
- URL and IP validation → Destination host: resolves host (evidence: `README.md`)
