Project management on React Router v8, MySQL 8 and Clerk
Project-management layer: user-owned projects, kanban tasks with status/priority, many-to-many assignees, per-project labels, and comment threads.
56 files, 4 tables and 209 lines of schema, verified 2026-08-23 on React Router v8, MySQL 8 and Clerk.
16 pinned upstream versions
request path. session validation runs in server components and route handlers, not at the edge
What you're getting
React Router v8 (framework mode): SSR, config/file routes under app/, loaders/actions, and resource routes for API endpoints.
MySQL 8 via Drizzle ORM and the mysql2 driver.
Clerk: hosted identity (sign-in UI, sessions, user management) mounted via middleware + provider.
Project-management layer: user-owned projects, kanban tasks with status/priority, many-to-many assignees, per-project labels, and comment threads.
Setup
bun add react-router react react-dom drizzle-orm mysql2 @clerk/nextjsDATABASE_URLMySQL connection string (mysql://…)NEXT_PUBLIC_CLERK_PUBLISHABLE_KEYCLERK_SECRET_KEYCLERK_WEBHOOK_SECRETsvix secret that verifies Clerk webhook signaturesApply the schema with bunx drizzle-kit push
Initialization
Database client
Project-management schema: projects, tasks, assignees, labels & comments
6 tables, 29 columns and 14 indexes and constraints, applied to a live MySQL 8 and asserted to materialize.
projects5 columns · 2 indexedtasks7 columns · 2 indexedtask_assignees4 columns · 3 indexedlabels5 columns · 2 indexedtask_labels3 columns · 3 indexedtask_comments5 columns · 2 indexedWhat this schema is built to answer
tasks, served by idx_task_project_status on (project_id, status): equality on both columns is a single index range, and the same index answers a project-wide read through its leading column.
task_assignees, via idx_assignee_user on assignee_id — the only index that reaches work without going through projects. Each hit joins to tasks by primary key.
task_assignees carries the composite unique task_assignees_task_user_unique on (task_id, assignee_id), so a repeat insert is a constraint violation and the handler can stay an idempotent ON CONFLICT DO NOTHING.
task_comments, with idx_comment_task_time on (task_id, created_at) supplying both the filter and the sort order, so the thread comes back without a separate sort step.
task_labels, read backwards through idx_task_label_label on label_id; labels themselves are scoped per project by idx_label_project on project_id.
Projects owned by a usertop-level containers keyed to a Better Auth user via owner_id FK, with active/archived status
Tasks with status, priority & due datethe unit of work scoped to a project, with a composite (project_id, status) index driving board-column queries
Task assignees & per-project labelstask↔user assignment join (unique per pair) and a project-scoped label catalog with a task↔label join table
Task comment threadsappend-only comment rows keyed to a task and a Better Auth author, indexed on (task_id, created_at) for chronological feeds
Verified identity sync (Clerk)
Deploy targets
The app UI
Decisions and compatibility
Framework mode (not data/library mode): routes live under app/, declared in app/routes.ts. API endpoints are resource routes (a route module exporting loader/action but no default component).
Data flows through loaders (run on the server before render) and actions (mutations); components read it with useLoaderData / useActionData. There are no React Server Components — every server-rendered route is a loader plus a client component.
Auth gates in the loader, not in middleware: a protected route's loader calls requireAuth(request), which throws a redirect Response that React Router short-circuits on — so a logged-out user never reaches the protected data or renders the page.
The `@/` import alias maps to app/ (this framework's source root), so shared modules like @/lib/auth resolve under app/ — the one path prefix that differs from Next's src/, which is why the auth slice's mount code is framework-specific.
mysql2's pool multiplexes connections; drizzle-orm/mysql2 wraps it. One module-level pool is right for a serverless/edge app — the runtime and the pool handle concurrency.
MySQL has no row-level security: multi-tenant isolation is enforced in application code via the forOrg helper (src/lib/tenant.ts), not by the database. See the tenant-scoping section on SaaS pages.
Hosted: Clerk owns identity and does NOT create a local `user` table. Store `clerk_user_id` as text without a foreign key, or sync Clerk users into a local table via webhook before relying on FKs to `user`.
Route protection is clerkMiddleware() + auth.protect() in the Next proxy (getAuth() in a React Router loader, or event.context.auth() on Nuxt) — logged-out users bounce to Clerk's hosted sign-in, so there are no self-hosted auth pages to build or maintain.
Keeping the local mirror in sync is a webhook job: a svix-verified webhook route replays user.created / user.updated / user.deleted idempotently into the local `user` row, so app-type foreign keys to `user` resolve even though Clerk is the source of truth.
ClerkProvider (client) wraps the app so the hosted <SignIn/> / <UserButton/> components and hooks work; the publishable key is read client-side, while the secret key is only ever read server-side by clerkMiddleware.
task_assignees carries a composite unique on (task_id, assignee_id) — a user can be assigned to a task at most once; the per-user index on assignee_id backs the 'tasks assigned to me' feed.
Status and priority are stored as text + CHECK (not pgEnum) so new values like 'blocked' or 'critical' ship without an ALTER TYPE migration dance.
Clerk is a hosted identity provider and does not create a local `user` table. This schema's foreign keys to `user` assume a local identity table (as Better Auth provides). With Clerk, store `clerk_user_id` as a text column without a foreign key, or sync Clerk users into a local `users` table via webhook before relying on these FKs.
MySQL provides no row-level security. On MySQL, multi-tenant isolation is APP-ENFORCED via the forOrg helper (src/lib/tenant.ts), not database-enforced like Postgres RLS. Every org-scoped query MUST go through forOrg — a missed query leaks across tenants. Postgres cells enforce this in the database itself (RLS), so it holds even for a query that forgets to scope.
How this stack fits together
Clerk is a hosted directory, so there is no local user row for projects, tasks, task_assignees, labels, task_labels and task_comments to reference directly. The composer emits an identity mirror and a sync webhook instead, and the foreign keys point at the mirrored row, which is why this cell ships a webhook handler that the library-auth cells in this registry do not.
MySQL 8 stores those surrogate keys as varchar(36), so every foreign key across the 6 tables and 29 columns below is a varchar(36) column. The migration was applied to a live MySQL 8 and the tables asserted, not just type-checked.
Project management
Six tables sit on top of Better Auth's identity layer, and their shape is a tracker rather than a tenant. projects is the root, tasks hang off a project, and assignments, labels and comments all hang off a task. Ownership is one owner_id column on projects referencing user.id as text — text because that is what Better Auth issues — and there is no organization or membership table anywhere in the schema. A project has exactly one owner; participation is expressed by task_assignees rows, not by joining a team. tasks carries the state a board reads: status (todo, in_progress, done), priority (low, medium, high, urgent) and a nullable due_date.
Both graded columns are text guarded by named CHECKs, tasks_status_check and tasks_priority_check, instead of pgEnum, so adding a 'blocked' column is a constraint swap on a live table rather than an ALTER TYPE. The one composite index, idx_task_project_status on (project_id, status), is the board itself: a single kanban column is one range on that index, and a project-wide read uses the same index by prefix. Both many-to-many edges are modelled as sets, not logs. task_assignees is unique on (task_id, assignee_id), so re-assigning the same person is idempotent instead of duplicating a row, and idx_assignee_user on assignee_id is the only path into work that does not start from a project — it is what makes a cross-project 'assigned to me' view cheap.
task_labels repeats that shape against the per-project labels catalog, unique on (task_id, label_id) with idx_task_label_label covering the reverse read from a label back to its tasks. task_comments is append-only and indexed on (task_id, created_at), which supplies the filter and the ordering out of one structure. Every foreign key cascades downward on delete: removing a project takes its tasks, and each task takes its assignments, label links and comments with it in one statement. What is not indexed is due_date and priority, so an overdue-everywhere report scans — add that index before you build the screen, not after it starts timing out.
React Router v8
React Router v8 in framework mode puts everything under app/, and `@/` maps to that root instead of Next's src/ — the one prefix that differs, which is why shared modules like @/lib/auth and @/db/schema stay byte-identical to their Next counterparts. initCode writes app/lib/db.ts, then the auth fragment adds app/lib/auth.ts, the resource route app/routes/api.auth.$.ts, and app/lib/require-auth.ts. The route table itself is app/routes.ts: routes are declared configuration, and a file becomes a URL because that table says so. There are no React Server Components here. Every server-rendered route is a loader plus an ordinary client component: the loader runs on the server before render, the component reads its result with useLoaderData, and mutations go through an action read back with useActionData.
An API endpoint is the same module minus the default export — a resource route, named with the flat dotted convention (app/routes/api.auth.$.ts for the auth splat, app/routes/webhooks.polar.ts for a webhook POST). Auth gates in the loader rather than in a middleware layer. A protected route awaits requireAuth(request) from app/lib/require-auth.ts, which calls auth.api.getSession({ headers: request.headers }) — a real server-side validation, not a cookie peek — and throws redirect("/sign-in") when there is no session. React Router treats a thrown Response as the route's outcome, so the loader short-circuits and neither the protected query nor the component ever runs. The trade that follows: there is no matcher array to widen and no edge tier to keep honest, but protection is per-route discipline.
A new route is protected because its loader calls requireAuth; forget the call and the page is public. In return, every gate sits one function call away from the data it guards, the session is already in hand when the loader queries db, and the same request-in / Response-out contract covers pages, API endpoints and the auth mount alike.
MySQL 8
MySQL 8 here is the mysql2 driver under Drizzle's mysql-core dialect: drizzle({ client: pool }) over one module-level mysql.createPool(DATABASE_URL). mysql2's pool multiplexes connections itself, so a single pool per module is the right shape — the runtime and the pool handle concurrency, with no globalThis singleton needed. The framework decides where that file lands (src/lib/db.ts on Next, app/lib/db.ts on React Router, server/lib/db.ts on Nuxt); the client text is the same in all three. The dialect's constraints show up directly in the column types.
MySQL cannot index a TEXT column without a prefix length, so anything that is a primary key, a UNIQUE, an index or a CHECK target is varchar with a declared length: ids are varchar(36) with no database default — the application generates them with crypto.randomUUID(), since there is no uuid type and no defaultRandom() — Better Auth's user.id and every FK pointing at it are varchar(255), an email or slug is varchar(255), a role or status varchar(32), a SHA-256 hex digest varchar(64). Free-form columns nobody indexes stay text. Timestamps are plain timestamp().defaultNow() without the withTimezone flag the Postgres bodies carry, and counters are bigint({ mode: "number" }). The operational difference that matters most: MySQL has no row-level security.
There is no policy layer to fall back on, so multi-tenant isolation is enforced in application code by forOrg(db, orgId) in src/lib/tenant.ts, which wraps each org-owned table's select/update/delete with a where on organization_id and throws on a missing orgId instead of quietly running unscoped. It is a real boundary only while every read and write goes through it — the shared plans catalog sits deliberately outside — and it is app-enforced, not database-enforced. Connections change with the deploy target: connectionLimit 2 per short-lived serverless instance, 10 in a long-running Node process, and on Cloudflare Workers mysql2 cannot run at all — there are no TCP sockets — so the edge client swaps to @planetscale/database over HTTP with drizzle-orm/planetscale-serverless.
Clerk
Clerk keeps identity on its own servers. The emitted app has no auth instance, no password column and no session table: the card at /sign-in is Clerk's <SignIn/> component rendered under a [[...sign-in]] catch-all so Clerk can mount its own verification and SSO-callback sub-routes there, and the endpoints behind it belong to Clerk. What does land in your database is a single mirror table. db/auth-schema.ts declares user with id set to the Clerk user id (text; varchar(255) on MySQL, so the app-type FK columns match exactly), plus email, first and last name, image URL, and an updated_at column used purely as a staleness key. It exists so app-type schemas can foreign-key user the way they would under a self-hosted auth.
It is not a source of truth, and application code should never write to it. Filling that mirror is a webhook job, and this fragment emits the whole path. lib/identity/record.ts holds recordClerkEvent; the mount is a Next route handler at src/app/api/webhooks/clerk/route.ts, an action in app/routes/webhooks.clerk.ts on React Router, or a Nitro .post.ts handler on Nuxt. Clerk delivers through svix, so the route verifies the raw body against CLERK_WEBHOOK_SECRET before anything reaches the database, and the record core is written for a delivery channel that retries and reorders: the staleness comparison lives inside the UPDATE's WHERE clause so an older event cannot clobber newer state, the insert path absorbs a concurrent duplicate (onConflictDoNothing on Postgres, an ER_DUP_ENTRY catch on MySQL), and user.deleted removes the row. Session checks never touch your Postgres.
Next's proxy.ts runs clerkMiddleware() and calls auth.protect() for anything matching createRouteMatcher(["/dashboard(.*)", "/settings(.*)"]); Nuxt reads event.context.auth() inside a Nitro middleware that the @clerk/nuxt module populates. Even the package name is framework-specific — @clerk/nextjs, @clerk/react-router, @clerk/nuxt — which upstreamPkgFor resolves per cell. The trade is concrete. You never build, style or maintain auth screens, and breaking changes arrive with Clerk's releases rather than your lockfile. In exchange, your user rows are eventually consistent with someone else's database, and a webhook you never configured is a table of missing foreign-key targets that only shows up when an app-type insert fails.
