LinkDen
Reference

API Reference

Architecture overview and endpoint reference for LinkDen's tRPC API.

API Reference

LinkDen's API is built with tRPC v11 on Hono, running on Cloudflare Workers. Every call is end-to-end type-safe -- no code generation required.

Architecture

Next.js Frontend (apps/web)
       |
       | tRPC Client (HTTP requests)
       |
       v
Hono Server (apps/server)
       |
       |-- Better Auth (session validation)
       |-- tRPC Router (packages/api)
       |
       v
Drizzle ORM (packages/db)
       |
       | SQL queries
       |
       v
Cloudflare D1 (SQLite)
  • Hono -- Lightweight web framework for edge runtimes. Zero cold start on Cloudflare Workers.
  • tRPC v11 -- End-to-end type safety. Router definitions live in packages/api.
  • Better Auth -- Email/password authentication. Session cookies validated on protected procedures.
  • Drizzle ORM -- Type-safe SQL for Cloudflare D1. Schema lives in packages/db/src/schema/.

Authentication

LinkDen uses Better Auth with email/password sign-in.

Session Flow

  1. Create an admin account during first-time setup at /admin/setup.
  2. Better Auth issues a secure session cookie.
  3. Sign in at /admin/login on subsequent visits.
  4. The cookie is sent with every API request to authenticate protected routes.

Environment Variables

VariableDescription
BETTER_AUTH_SECRETSecret key for session signing
BETTER_AUTH_URLBase URL for the auth server (API server URL)
CORS_ORIGINTrusted origin for the frontend

Generate a secret with: openssl rand -base64 32

Tip: If you hit 401 errors, double-check that CORS_ORIGIN matches your frontend URL exactly -- including protocol, no trailing slash.


Endpoint Reference

All endpoints live at /trpc/<router>.<procedure>. Public procedures need no auth. Protected procedures require a valid session cookie.

Blocks

Manage content blocks on your page.

ProcedureTypeAuthDescription
blocks.listQueryProtectedGet all blocks ordered by position
blocks.getQueryProtectedGet a single block by ID
blocks.createMutationProtectedCreate a new block
blocks.updateMutationProtectedUpdate block fields by ID
blocks.deleteMutationProtectedDelete a block by ID
blocks.reorderMutationProtectedBatch update block positions
blocks.toggleEnabledMutationProtectedToggle block visibility

Settings

Manage site-wide key-value configuration.

ProcedureTypeAuthDescription
settings.getQueryProtectedGet a single setting by key
settings.getAllQueryProtectedGet all settings as key-value map
settings.updateMutationProtectedUpsert a single key-value pair
settings.updateBulkMutationProtectedUpsert multiple key-value pairs

Contacts

Handle contact form submissions.

ProcedureTypeAuthDescription
contacts.listQueryProtectedList submissions (filterable by read status)
contacts.getQueryProtectedGet a single submission by ID
contacts.markReadMutationProtectedMark submission as read
contacts.markUnreadMutationProtectedMark submission as unread
contacts.deleteMutationProtectedDelete a submission
contacts.unreadCountQueryProtectedCount of unread submissions

Analytics

Track page views and clicks. All queries accept an optional period parameter: "7d", "30d", or "90d".

ProcedureTypeAuthDescription
analytics.overviewQueryProtectedTotal views and clicks for period
analytics.viewsOverTimeQueryProtectedDaily view counts
analytics.clicksOverTimeQueryProtectedDaily click counts
analytics.topLinksQueryProtectedTop 10 links by clicks
analytics.referrersQueryProtectedTop 10 referrer domains
analytics.countriesQueryProtectedTop 20 countries by views

Social

Manage social network entries for Social Icons blocks.

ProcedureTypeAuthDescription
social.listQueryProtectedList all networks (optional activeOnly filter)
social.toggleMutationProtectedToggle a network on/off by slug

Wallet

Configure Apple Wallet passes.

ProcedureTypeAuthDescription
wallet.getConfigQueryProtectedGet wallet settings
wallet.updateConfigMutationProtectedUpdate wallet settings
wallet.generatePreviewQueryProtectedPreview data for pass generation

vCard

Manage and generate vCard contact files.

ProcedureTypeAuthDescription
vcard.getConfigQueryProtectedGet vCard config and data
vcard.updateConfigMutationProtectedUpdate vCard fields
vcard.previewQueryProtectedGenerate .vcf string

Backup

Import and export all data.

ProcedureTypeAuthDescription
backup.exportQueryProtectedExport all data as JSON
backup.importMutationProtectedImport data ("merge" or "replace" mode)

Version

ProcedureTypeAuthDescription
version.currentQueryPublicReturns current version
version.checkUpdateQueryPublicCheck for available updates

Public

Public-facing endpoints -- no authentication needed.

ProcedureTypeDescription
public.getPageQueryFull page data: profile, blocks, theme, settings
public.submitContactMutationSubmit contact form (with optional CAPTCHA)
public.trackViewMutationRecord a page view
public.trackClickMutationRecord a link click
public.getVCardQueryDownload vCard if enabled
public.getSetupStatusQueryCheck if setup is complete

All input is validated with shared Zod schemas from packages/validators.

On this page