# plinkkcorp/plinkk-web architecture

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

- Interactive diagram: https://gitdiagram.com/plinkkcorp/plinkk-web
- Repository: https://github.com/plinkkcorp/plinkk-web

## Overview

1. **Repository shape**
   This is a Bun/TypeScript monorepo split into two runtime applications plus shared packages:
   - `apps/dashboard`: authenticated dashboard, admin console, and most write APIs
   - `apps/public`: public-facing profile pages, docs, landing pages, and tracking endpoints
   - `packages/prisma`: shared Prisma schema/client and RBAC definitions
   - `packages/shared`: shared business utilities, view partials, and domain helpers

2. **Primary architectural boundary: dashboard vs public**
   The strongest boundary is between the private dashboard and the public site. The dashboard handles user/account management, editing, admin operations, billing, and internal APIs. The public app serves end-user profile pages and marketing/documentation content, and also hosts request paths that must remain lightweight and public-safe. They are deployed separately and have separate Dockerfiles and ports.

3. **Request handling stack**
   Both apps use **Fastify** as the HTTP server and **EJS** for server-side rendered pages. The codebase is organized around route modules rather than a single monolithic server file. Fastify plugins/middleware handle auth, rate limiting, sessions, and special request hooks before requests reach route handlers.

4. **Dashboard backend domains**
   Dashboard server code is split into:
   - `src/routes/auth`: login, register, OAuth, TOTP, logout, password recovery
   - `src/server/api`: JSON APIs for user, admin, Stripe, themes, redirects, plinkks, inbox, bug reports, etc.
   - `src/server/dashboard`: page-rendering handlers for the dashboard UI
   - `src/services`: the business logic layer used by both API and page routes

   This separation suggests controllers/routes are thin, with state changes and cross-cutting workflows moved into services.

5. **Public-facing domains**
   The public app contains server routes for:
   - profile page rendering and profile-related tracking
   - static marketing pages, docs, pricing, partners, patch notes
   - public-facing forms and error pages
   - public interactions around profile links and redirects

   It also includes frontend assets for the public site and a separate UI bundle for the profile pages themselves.

6. **Core data model and persistence**
   `packages/prisma` is the persistence boundary. Prisma manages the database schema, migrations, seed scripts, and generated types/client. The key entities called out by the repo are:
   - users, sessions, OAuth connections
   - plinkks, links, themes, labels/categories/hosts
   - roles and permissions for RBAC
   - bug reports, announcements, magic links
   - tracking/monetization-related models

   PostgreSQL is the production store, with SQLite used for lighter development flows.

7. **Business logic center**
   Most domain behavior lives in service modules rather than route handlers. The services layer covers:
   - plinkk CRUD, export, history, premium logic
   - user/session management
   - themes and redirects
   - email queueing, quotas, inbox, notifications
   - stats and tracking aggregation
   - Stripe integration
   - maintenance and announcements
   - admin logging and user logging

   This is the main place where workflows combine DB access, validation, caching, and external integrations.

8. **Auth, session, and security flow**
   Authentication is multi-channel: email/password, OAuth2 providers, magic links, and TOTP 2FA. Sessions are encrypted server-side via `@fastify/secure-session`. Access control is enforced through middleware and shared RBAC helpers, with separate role/permission checks for staff, premium capabilities, and resource quotas. Rate limiting and reserved-root protection are additional defensive boundaries.

9. **Dashboard editor and live preview**
   A notable subsystem is the profile editor in `apps/dashboard/src/public/js/dashboard-ui`. It manages editing state, history, settings, theme controls, link management, and iframe communication. The live preview is synchronized with the public profile renderer through `postMessage`-style communication, so editing changes are reflected in the preview without a full page reload. This is one of the main client-to-server/client-to-client data flows in the repo.

10. **Frontend asset model**
   The repo contains a large amount of browser-side JavaScript and CSS under each app’s `src/public`. These assets support:
   - dashboard editing UI
   - theme toggles and animations
   - profile rendering components
   - cookies/security helpers
   - tutorial and onboarding flows
   - UI utilities and reusable interactive widgets

   The public and dashboard apps duplicate some shared assets, but their entry points and page shells remain distinct.

11. **External services and integration points**
   Several integrations materially shape the architecture:
   - **Stripe** for subscriptions and webhooks
   - **Resend** for transactional email and queued notifications
   - **AWS S3** for avatars/uploads
   - **OAuth providers**: GitHub, Discord, Google
   - **Discord webhooks** for notifications/admin events
   - **QR code generation** for onboarding or 2FA flows

   These are not isolated helpers; they appear in dedicated services and route families, so they are part of the system’s core operational flow.

12. **Operational subsystems**
   The repo includes cron jobs, cache, logging, and maintenance routines. There is an in-memory cache for hot data, scheduled cleanup of sessions/inactive users, and a range of admin tooling for moderation, patch notes, email templates, and reports. The presence of scripts for seeding permissions, migrations, data cleanup, and admin bootstrap indicates this is an operationally managed platform rather than a purely request/response web app.

13. **Shared code reuse**
   `packages/shared` centralizes cross-app utilities like theme generation, bundle generation, security helpers, error classes, plinkk resolution, role verification, and shared EJS partials. This package is the main mechanism preventing duplication between dashboard and public, especially for domain rules that must stay consistent across both apps.

14. **How to think about the system diagram**
   A good architecture diagram would show:
   - two HTTP apps on separate ports
   - both depending on the shared Prisma client and shared domain package
   - the dashboard as the write-heavy authenticated control plane
   - the public app as the read-heavy presentation and tracking plane
   - the database as the central source of truth
   - external services hanging off service-layer integration points
   - background jobs and admin scripts as operational side paths feeding the same database and services

Main entry points: [`apps/dashboard/src/services/plinkkService.ts`](https://github.com/plinkkcorp/plinkk-web/blob/master/apps/dashboard/src/services/plinkkService.ts) (Services), [`apps/public/src/server.ts`](https://github.com/plinkkcorp/plinkk-web/blob/master/apps/public/src/server.ts) (Public HTTP), [`packages/prisma/prisma/schema.prisma`](https://github.com/plinkkcorp/plinkk-web/blob/master/packages/prisma/prisma/schema.prisma) (Prisma model), [`apps/dashboard/src/server.ts`](https://github.com/plinkkcorp/plinkk-web/blob/master/apps/dashboard/src/server.ts) (Dashboard HTTP)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_apps["Applications"]
  node_dashboard_http["Dashboard HTTP<br/>Fastify app<br/>[server.ts]"]
  node_dashboard_auth["Auth routes<br/>Route module<br/>[index.ts]"]
  node_dashboard_api["Dashboard APIs<br/>API routes<br/>[apiRoutes.ts]"]
  node_dashboard_pages["Dashboard pages<br/>SSR routes<br/>[dashboardRoutes.ts]"]
  node_dashboard_services["Services<br/>Business logic<br/>[plinkkService.ts]"]
  node_dashboard_editor["Editor UI<br/>Browser UI<br/>[index.js]"]
  node_dashboard_mw["Middleware<br/>[auth.ts]"]
  node_public_http["Public HTTP<br/>Fastify app<br/>[server.ts]"]
  node_public_content["Content routes<br/>SSR routes"]
  node_public_profiles["Profile routes"]
  node_public_tracking["Tracking API<br/>Public API<br/>[trackingRoutes.ts]"]
  node_public_assets["Public UI<br/>Browser assets<br/>[init.js]"]
end

subgraph group_packages["Shared packages"]
  node_prisma_pkg[("Prisma model<br/>Persistence package<br/>[schema.prisma]")]
  node_shared_pkg["Shared domain<br/>Common package<br/>[index.ts]"]
  node_db[("Postgres<br/>Database")]
  node_external_services{{"External services<br/>Integrations"}}
end

subgraph group_ops["Operations"]
  node_ops_scripts["Ops scripts"]
end

node_dashboard_http -->|"uses"| node_dashboard_mw
node_dashboard_http -->|"mounts"| node_dashboard_auth
node_dashboard_http -->|"mounts"| node_dashboard_api
node_dashboard_http -->|"mounts"| node_dashboard_pages
node_dashboard_auth -->|"calls"| node_dashboard_services
node_dashboard_api -->|"calls"| node_dashboard_services
node_dashboard_pages -->|"calls"| node_dashboard_services
node_dashboard_editor -.->|"syncs with"| node_public_assets
node_dashboard_editor -->|"reuses"| node_shared_pkg
node_dashboard_services -->|"queries"| node_prisma_pkg
node_dashboard_services -->|"reuses"| node_shared_pkg
node_dashboard_services -->|"integrates"| node_external_services
node_public_http -->|"mounts"| node_public_content
node_public_http -->|"mounts"| node_public_profiles
node_public_http -->|"mounts"| node_public_tracking
node_public_http -->|"serves"| node_public_assets
node_public_profiles -->|"reuses"| node_shared_pkg
node_public_content -->|"reuses"| node_shared_pkg
node_public_tracking -->|"reads/writes"| node_prisma_pkg
node_public_profiles -->|"reads"| node_prisma_pkg
node_prisma_pkg -->|"maps to"| node_db
node_ops_scripts -->|"maintains"| node_prisma_pkg
node_ops_scripts -->|"operates on"| node_db
node_dashboard_services -->|"stores"| node_db
node_public_http -->|"reads"| node_db

click node_dashboard_http "https://github.com/plinkkcorp/plinkk-web/blob/master/apps/dashboard/src/server.ts"
click node_dashboard_auth "https://github.com/plinkkcorp/plinkk-web/blob/master/apps/dashboard/src/routes/auth/index.ts"
click node_dashboard_api "https://github.com/plinkkcorp/plinkk-web/blob/master/apps/dashboard/src/server/apiRoutes.ts"
click node_dashboard_pages "https://github.com/plinkkcorp/plinkk-web/blob/master/apps/dashboard/src/server/dashboardRoutes.ts"
click node_dashboard_services "https://github.com/plinkkcorp/plinkk-web/blob/master/apps/dashboard/src/services/plinkkService.ts"
click node_dashboard_editor "https://github.com/plinkkcorp/plinkk-web/blob/master/apps/dashboard/src/public/js/dashboard-ui/index.js"
click node_dashboard_mw "https://github.com/plinkkcorp/plinkk-web/blob/master/apps/dashboard/src/middleware/auth.ts"
click node_public_http "https://github.com/plinkkcorp/plinkk-web/blob/master/apps/public/src/server.ts"
click node_public_content "https://github.com/plinkkcorp/plinkk-web/blob/master/apps/public/src/server/staticPagesRoutes.ts"
click node_public_profiles "https://github.com/plinkkcorp/plinkk-web/blob/master/apps/public/src/server/plinkkFrontUserRoutes.ts"
click node_public_tracking "https://github.com/plinkkcorp/plinkk-web/blob/master/apps/public/src/server/trackingRoutes.ts"
click node_public_assets "https://github.com/plinkkcorp/plinkk-web/blob/master/apps/public/src/public/js/init.js"
click node_prisma_pkg "https://github.com/plinkkcorp/plinkk-web/blob/master/packages/prisma/prisma/schema.prisma"
click node_shared_pkg "https://github.com/plinkkcorp/plinkk-web/blob/master/packages/shared/src/index.ts"
click node_ops_scripts "https://github.com/plinkkcorp/plinkk-web/blob/master/scripts/seed-permissions.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_dashboard_http,node_dashboard_auth,node_dashboard_api,node_dashboard_pages,node_dashboard_services,node_dashboard_editor,node_dashboard_mw,node_public_http,node_public_content,node_public_profiles,node_public_tracking,node_public_assets toneBlue
class node_prisma_pkg,node_shared_pkg,node_db,node_external_services toneAmber
class node_ops_scripts toneMint
```

## Components

### Applications

Runtime apps and their request handling stacks

- [Dashboard HTTP](https://github.com/plinkkcorp/plinkk-web/blob/master/apps/dashboard/src/server.ts): Fastify app · Authenticated control-plane server with SSR pages and JSON APIs · `apps/dashboard/src/server.ts`
- [Auth routes](https://github.com/plinkkcorp/plinkk-web/blob/master/apps/dashboard/src/routes/auth/index.ts): Route module · Login, register, OAuth, TOTP, logout, and recovery flows · `apps/dashboard/src/routes/auth/index.ts`
- [Dashboard APIs](https://github.com/plinkkcorp/plinkk-web/blob/master/apps/dashboard/src/server/apiRoutes.ts): API routes · Write-heavy JSON endpoints for users, admins, Stripe, themes, redirects, plinkks, inbox, and reports · `apps/dashboard/src/server/apiRoutes.ts`
- [Dashboard pages](https://github.com/plinkkcorp/plinkk-web/blob/master/apps/dashboard/src/server/dashboardRoutes.ts): SSR routes · Server-rendered dashboard views for account, edit, admin, and user workflows · `apps/dashboard/src/server/dashboardRoutes.ts`
- [Services](https://github.com/plinkkcorp/plinkk-web/blob/master/apps/dashboard/src/services/plinkkService.ts): Business logic · Domain workflows for plinkks, users, sessions, themes, email, stats, Stripe, and moderation · `apps/dashboard/src/services/plinkkService.ts`
- [Editor UI](https://github.com/plinkkcorp/plinkk-web/blob/master/apps/dashboard/src/public/js/dashboard-ui/index.js): Browser UI · Client-side profile editor, state/history, iframe sync, and live preview controls · `apps/dashboard/src/public/js/dashboard-ui/index.js`
- [Middleware](https://github.com/plinkkcorp/plinkk-web/blob/master/apps/dashboard/src/middleware/auth.ts): Fastify middleware · Auth, session validation, rate limiting, reserved-root protection, and audit hooks · `apps/dashboard/src/middleware/auth.ts`
- [Public HTTP](https://github.com/plinkkcorp/plinkk-web/blob/master/apps/public/src/server.ts): Fastify app · Public-facing server for profiles, docs, marketing pages, and lightweight tracking · `apps/public/src/server.ts`
- [Content routes](https://github.com/plinkkcorp/plinkk-web/blob/master/apps/public/src/server/staticPagesRoutes.ts): SSR routes · Landing pages, docs, pricing, partners, patch notes, and legal pages · `apps/public/src/server/staticPagesRoutes.ts`
- [Profile routes](https://github.com/plinkkcorp/plinkk-web/blob/master/apps/public/src/server/plinkkFrontUserRoutes.ts): Profile routes · Public profile rendering, redirects, and profile-page interactions · `apps/public/src/server/plinkkFrontUserRoutes.ts`
- [Tracking API](https://github.com/plinkkcorp/plinkk-web/blob/master/apps/public/src/server/trackingRoutes.ts): Public API · Bug reports, metrics, and tracking endpoints that stay public-safe · `apps/public/src/server/trackingRoutes.ts`
- [Public UI](https://github.com/plinkkcorp/plinkk-web/blob/master/apps/public/src/public/js/init.js): Browser assets · Frontend bundles, inline handlers, styles, and profile-page components · `apps/public/src/public/js/init.js`

### Shared packages

Cross-app persistence and domain reuse

- [Prisma model](https://github.com/plinkkcorp/plinkk-web/blob/master/packages/prisma/prisma/schema.prisma): Persistence package · Shared schema, migrations, seed data, client generation, and RBAC definitions · `packages/prisma/prisma/schema.prisma`
- [Shared domain](https://github.com/plinkkcorp/plinkk-web/blob/master/packages/shared/src/index.ts): Common package · Reusable domain helpers, security utilities, bundle generation, and shared EJS partials · `packages/shared/src/index.ts`
- **Postgres**: Database · Primary production datastore for users, sessions, plinkks, themes, roles, reports, and tracking
- **External services**: Integrations · Stripe, Resend, S3, OAuth providers, Discord webhooks, and QR generation

### Operations

Background jobs, scripts, and admin-side maintenance

- [Ops scripts](https://github.com/plinkkcorp/plinkk-web/blob/master/scripts/seed-permissions.js): Scripts · Migrations, seeding, cleanup, account/admin bootstrap, and maintenance utilities · `scripts/seed-permissions.js`

## Connections

- Dashboard HTTP → Middleware: uses · Request pre-processing for auth, sessions, limits, and audits
- Dashboard HTTP → Auth routes: mounts · Installs authentication route family
- Dashboard HTTP → Dashboard APIs: mounts · Installs JSON API family
- Dashboard HTTP → Dashboard pages: mounts · Installs SSR dashboard pages
- Auth routes → Services: calls · Thin route handlers delegate state changes and workflows
- Dashboard APIs → Services: calls · APIs orchestrate domain operations through services
- Dashboard pages → Services: calls · Page handlers reuse business logic for rendered state
- Editor UI → Public UI: syncs with · Live preview and editor state stay aligned with public rendering
- Editor UI → Shared domain: reuses · Shared theme, security, and rendering helpers
- Services → Prisma model: queries · Business logic persists and reads through the shared Prisma boundary
- Services → Shared domain: reuses · Domain helpers, validation, bundle/theme generation, and error handling
- Services → External services: integrates · Email, billing, storage, OAuth, and notifications
- Public HTTP → Content routes: mounts · Serves docs and marketing routes
- Public HTTP → Profile routes: mounts · Serves public profile pages and redirects
- Public HTTP → Tracking API: mounts · Serves tracking and bug-report endpoints
- Public HTTP → Public UI: serves · Delivers browser assets for public pages
- Profile routes → Shared domain: reuses · Shared plinkk resolution, security, and view helpers
- Content routes → Shared domain: reuses · Shared partials and content rendering helpers
- Tracking API → Prisma model: reads/writes · Tracking and bug-report flows use the shared persistence model
- Profile routes → Prisma model: reads · Profile rendering and redirects depend on persisted plinkk data
- Prisma model → Postgres: maps to · Schema and migrations define the database boundary
- Ops scripts → Prisma model: maintains · Seeds, migrations, cleanup, and admin bootstrap keep data model aligned
- Ops scripts → Postgres: operates on · Operational scripts update and repair persisted state
- Services → Postgres: stores · Core dashboard workflows ultimately persist to the database
- Public HTTP → Postgres: reads · Public rendering and tracking read the same source of truth
