How plinkkcorp/plinkk-web works
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: plinkkService.ts Services · src/server.ts Public HTTP · schema.prisma Prisma model · src/server.ts Dashboard HTTP
Components 17
Applications
Runtime apps and their request handling stacks
- Dashboard HTTP · Authenticated control-plane server with SSR pages and JSON APIs
apps/dashboard/src/server.ts - Auth routes · Login, register, OAuth, TOTP, logout, and recovery flows
apps/dashboard/src/routes/auth/index.ts - Dashboard APIs · Write-heavy JSON endpoints for users, admins, Stripe, themes, redirects, plinkks, inbox, and reports
apps/dashboard/src/server/apiRoutes.ts - Dashboard pages · Server-rendered dashboard views for account, edit, admin, and user workflows
apps/dashboard/src/server/dashboardRoutes.ts - Services · Domain workflows for plinkks, users, sessions, themes, email, stats, Stripe, and moderation
apps/dashboard/src/services/plinkkService.ts - Editor UI · Client-side profile editor, state/history, iframe sync, and live preview controls
apps/dashboard/src/public/js/dashboard-ui/index.js - Middleware · Auth, session validation, rate limiting, reserved-root protection, and audit hooks
apps/dashboard/src/middleware/auth.ts - Public HTTP · Public-facing server for profiles, docs, marketing pages, and lightweight tracking
apps/public/src/server.ts - Content routes · Landing pages, docs, pricing, partners, patch notes, and legal pages
apps/public/src/server/staticPagesRoutes.ts - Profile routes · Public profile rendering, redirects, and profile-page interactions
apps/public/src/server/plinkkFrontUserRoutes.ts - Tracking API · Bug reports, metrics, and tracking endpoints that stay public-safe
apps/public/src/server/trackingRoutes.ts - Public UI · 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 · Shared schema, migrations, seed data, client generation, and RBAC definitions
packages/prisma/prisma/schema.prisma - Shared domain · Reusable domain helpers, security utilities, bundle generation, and shared EJS partials
packages/shared/src/index.ts - Postgres · Primary production datastore for users, sessions, plinkks, themes, roles, reports, and tracking
- External services · Stripe, Resend, S3, OAuth providers, Discord webhooks, and QR generation
Operations
Background jobs, scripts, and admin-side maintenance
- Ops scripts · Migrations, seeding, cleanup, account/admin bootstrap, and maintenance utilities
scripts/seed-permissions.js
Connections 25
- 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