Skip to content
All work

Dr. Siri

A storefront and an admin portal, sharing one schema.

Role
Full-Stack Architect
Platforms
Web
Year
2025

A multi-vendor organic marketplace for a German client, built as two applications: the customer storefront and the admin portal sellers and staff run it from.

Both live in one Turborepo sharing types, UI primitives and utilities, so a schema change cannot silently drift between them. The interesting work is in the database, global search across products, sellers and categories in a single round trip, with no external search cluster.

2 apps
storefront and admin, one monorepo
3
independent auth layers
4
shared packages
  • Next.js 15
  • React Server Components
  • Turborepo
  • Supabase
  • PL/pgSQL
  • Tailwind

How it fits together.

Apps

Storefront

Next.js 15 · RSC

Apps

Admin Portal

Next.js 15 · dashboard

Shared

packages/*

ui · types · utils · config

One schema, two apps

Edge

Edge Middleware

Session + role gate

Edge

Server Actions

Server-side re-verify

Database

global_search()

PL/pgSQL · JSONB

one round trip

Database

RLS + is_admin()

SECURITY DEFINER

Shared packages keep two Next.js apps honest; RLS keeps the client honest.

How it was built.

Search in Postgres, not Elasticsearch

Problem
Search spans three tables. LIKE '%query%' cannot use an index and degrades into full table scans as the catalogue grows. The reflex fix is Algolia or Elasticsearch, another service to run, sync and pay for, on a marketplace that did not yet have the traffic to justify it.
Approach
A PL/pgSQL global_search RPC doing parallel aggregation across all three tables and returning one JSONB payload, backed by B-tree indexes on lower(name) columns so case-insensitive prefix matching stays on the index.
Trade-off
Search stays a single round trip with no extra infrastructure to run or pay for. It handles prefixes rather than fuzzy matching or typo tolerance. The honest ceiling of this approach, and well beyond what the catalogue needs.

Authorisation enforced three times

Problem
Admin routes guarded only in the UI are not guarded. Any client-side check can be bypassed by calling the endpoint directly.
Approach
Three independent layers: Next.js edge middleware inspecting session cookies before the route renders, server actions re-verifying through the Supabase server SDK, and Postgres RLS policies requiring a SECURITY DEFINER is_admin() check on every write.
Trade-off
The database refuses unauthorised writes even if both application layers were bypassed entirely. Authorisation lives closest to the data, where it cannot be routed around.