GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - raiyansarker/openlink

BranchesTags
Open more actions menu

Latest commit

 

History

867 Commits
867 Commits

Folders and files

NameName
Last commit message
Last commit date
.cursor
.cursor
 
 
.github/workflows
.github/workflows
 
 
apps/web
apps/web
 
 
docs
docs
 
 
packages
packages
 
 
.gitignore
.gitignore
 
 
.npmrc
.npmrc
 
 
AGENTS.md
AGENTS.md
 
 
README.md
README.md
 
 
bun.lock
bun.lock
 
 
package.json
package.json
 
 
turbo.json
turbo.json
 
 

Repository files navigation

OpenLink logo

OpenLink

OpenLink is a link shortener and redirect platform built for Cloudflare Workers. Organizations manage custom domains, create rich short links (scheduling, passwords, UTM, fallbacks), and expose a versioned HTTP API from a single Worker that handles both SSR and API traffic.

This repository is a Turborepo monorepo managed with Bun.

Features

  • Organizations & invites — create orgs behind invite tokens; members join via accept-invite flow
  • Custom domains — attach hostnames per org (@opencoredev/domain-sdk); memory provider locally, Cloudflare SaaS in production
  • Links — slugs, aliases, schedules, click limits, optional password protection, expired/fallback destinations, tags, and UTM parameters
  • Auth — email + password via Better Auth (social / magic link planned)
  • Contract-first API — oRPC OpenAPI contracts in TypeScript with ArkType; live spec at GET /api/v1/openapi.json and interactive docs at /api/docs
  • Edge data — Drizzle ORM on Cloudflare D1 with checked-in migrations

Requirements

Tool Version
Bun 1.4.4 (see package.json)
Node ≥ 24 (for tooling compatibility)

Quick start

bun install
cp apps/web/.dev.vars.example apps/web/.dev.vars   # set BETTER_AUTH_SECRET
cd apps/web
bun run check-types                                  # wrangler types + tsc
bun run db:migrate:local
cd ../..
bun run dev --filter=web

The web app listens on port 3000. Sign up, then create your first workspace.

Resource URL
OpenAPI JSON http://localhost:3000/api/v1/openapi.json
API docs (Stoplight) http://localhost:3000/api/docs

Monorepo layout

openlink/
├── apps/
│   └── web/                 # TanStack Start app on Cloudflare Workers (API + app shell)
└── packages/
    ├── contracts/           # oRPC OpenAPI contract + ArkType schemas (shared with clients)
    ├── db/                  # Drizzle schema and D1 migrations
    ├── domain/              # Domain SDK client (memory | cloudflare)
    └── typescript-config/   # Shared TS configs

API surface (contract packages)

Contracts live under packages/contracts/src/ and are composed in contract.ts:

Area Tags / scope
system Health, metadata
auth Sign-up, sign-in, session
organizations Orgs, members, invites, ownership transfer
domains Custom domains per org
folders Nested link folders (rename, move, delete modes)
links CRUD per domain, workspace search, bulk move/tag/delete, history
comments Link comment threads and reactions
activity Workspace audit feed (also powers link history)
apiKeys Workspace API keys (Authorization: Bearer sk_…)

Short links resolve at /{slug} on any active custom domain (redirect, password gate, expiry/fallback, click limits).

The Worker implements the contract with implement(contract) and an OpenAPI handler. Business logic uses Effect in apps/web/src/server/effect/; contracts stay Effect-free so frontends can import types only.

Commands

From the repository root:

bun run dev            # all apps (web → :3000)
bun run build
bun run test
bun run check-types
bun run lint
bun run format         # Prettier on ts, tsx, md

Web-only or database:

bun run dev --filter=web
cd apps/web && bun run db:migrate:local
cd apps/web && bun run deploy    # build + wrangler deploy (Cloudflare auth required)

Local development notes

Environment

  • Copy apps/web/.dev.vars.example → apps/web/.dev.vars and set a strong BETTER_AUTH_SECRET (e.g. openssl rand -base64 32).
  • .dev.vars sets DOMAIN_PROVIDER=memory for local dev so domain verification stays in-process.
  • worker-configuration.d.ts is generated by wrangler types and is gitignored; bun run check-types in apps/web runs types generation before tsc.

Custom domains in dev vs production

With DOMAIN_PROVIDER=memory, hostname verification uses the in-memory Domain SDK adapter—no Cloudflare API calls. To exercise real SaaS hostnames, set DOMAIN_PROVIDER=cloudflare and add CF_API_TOKEN, CF_ZONE_ID, CF_SAAS_CNAME_TARGET, and CF_SAAS_CUSTOM_ORIGIN in .dev.vars.

Workspace roles

Role Read workspace data Manage links Manage domains and invitations
Owner Yes Yes Yes
Admin Yes Yes Yes
Member Yes Yes No
Viewer Yes No No

New workspace creators receive the owner role. Invitations can grant admin, member, or viewer, never ownership. Ownership transfer and member-role management are not exposed yet.

Apply database migrations before deploying the expanded role contract. Migration 0001_workspace_owners.sql promotes the earliest-joined admin in each existing workspace to owner (membership ID breaks ties), unless an owner already exists. This is a deterministic backfill, not proof of who originally created a workspace; review legacy ownership assignments before applying it in production. Workspaces without an admin are left unchanged and require manual ownership recovery. The role enum expansion itself needs no SQLite column change: roles are stored as text. Members can no longer add domains or refresh domain verification; those operations now require an owner or admin.

API keys

Workspace API keys use the Better Auth API key plugin (@better-auth/api-key), configured in apps/web/src/server/auth/api-keys.ts. Clients send Authorization: Bearer sk_…; requirePrincipal verifies the key with auth.api.verifyApiKey. The dashboard and the apiKeys oRPC routes call auth.api.* through apps/web/src/server/apikeys/service.ts.

Keys belong to workspaces. The plugin runs with references: 'organization', so a key's referenceId is the workspace id. Deleting a workspace deletes its keys.

Adapting the plugin to OpenLink workspaces. For organization-owned keys, the plugin expects Better Auth's organization plugin: it reads members from a member model and checks roles against that plugin's access-control options. OpenLink has its own organization and organization_member tables instead, so api-keys.ts adds a small companion plugin (openlink-workspace-members). It makes three adaptations:

  • It declares a member model, and instance.ts maps that model to schema.organizationMember. The plugin's membership lookups therefore read organization_member. Better Auth never writes to this model; joinedAt is declared only so its schema check accepts the table.
  • Its init puts orgOptions on the auth context with the roles below. The plugin uses them for list, create, update and delete. owner is the creator role and has every permission.
  • It does not install Better Auth's organization plugin. Workspaces, members and invites stay with OpenLink's own code.
Workspace role Manage API keys
Owner Yes
Admin Yes
Member No
Viewer No

The oRPC routes also require a signed-in owner or admin (requireOrgAdminUserEffect) before calling the plugin, and a request made with an API key can never manage keys.

This adaptation relies on plugin internals: it looks for orgOptions on the auth context and for a member model. Both packages are pinned to the same version (1.7.22). Run bun test src/server/apikeys after upgrading either one. Those tests use a real Better Auth instance, so they fail if the plugin stops finding members or roles.

Key role. A key's workspace role (admin, member or viewer; never owner) is stored in the plugin's permissions field as { "workspace": ["<role>"] }. The plugin only lets the server set permissions. For that reason the service creates keys and changes roles with server calls that pass the acting user's userId, not the request headers. A key without a valid role, for example one made by calling /api/auth/api-key/create directly, is hidden from the list and rejected when used.

Other settings:

  • Secrets start with sk_. Only a hash is stored; the list shows the first 9 characters (start).
  • The plugin's per-key rate limit is off. Its default is 10 requests per day.
  • lastRequest (shown as "last used") is updated on every authenticated request.
  • Names are required, up to 80 characters.

Plugin endpoints. The plugin also serves /api/auth/api-key/*. Those endpoints apply the same owner/admin check but skip OpenLink's activity log. The dashboard uses the apiKeys oRPC routes, which do write to it.

Migration. 0014_better_auth_api_keys.sql drops the old api_key table and creates the plugin's apikey table. Existing keys are not carried over: after the migration they stop working, and workspaces need to create new ones.

Changing the API

Edit schema.ts and contract.ts in the relevant folder under packages/contracts/src/. Restart the dev server; /api/v1/openapi.json updates from the contract—there is no hand-edited OpenAPI YAML.

Package-level notes: packages/contracts/README.md.

CI

GitHub Actions (.github/workflows/ci.yml) on main, backend, and pull requests:

  1. bun run test
  2. bun run check-types
  3. bun run lint

Docs

  • Workspace roles & permissions — what each role (owner, admin, member, viewer) can do, what the UI shows them, and how to change a permission

Stack reference

Layer Choice
Runtime Cloudflare Workers
App framework TanStack Start + React 19
API oRPC 2 (OpenAPI) + ArkType
Database D1 + Drizzle
Auth Better Auth
Domains domain-sdk (memory / cloudflare)
Monorepo Turborepo
Tooling Vite 8, Wrangler 4, oxlint, TypeScript

About

No description, website, or topics provided.

Resources

Readme
Activity

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.