hilal
← Back

Case study ·

lokalhost.io — Product Case Study

A developer ecosystem I designed and built solo: a CLI-installable component registry, a React Native + Flutter mobile kit, templates, and a Pro tier billed through Razorpay.

lokalhost.io landing page hero with bento grid
The lokalhost.io landing page

lokalhost.io is a developer ecosystem I designed and built solo: a shadcn-compatible component registry installable from the CLI, a React Native + Flutter mobile kit, web templates and design kits, and a paid Pro tier billed through Razorpay.

~50k
lines of TypeScript, TSX, MDX and Dart
420+
source files
52
mobile items (React Native + Flutter)
15
merged pull requests
Role
Solo founder, designer and full-stack engineer
Timeline
Jun 2026 – Nov 2026 (first commit 29 Jun 2026; billing shipped 13 Nov 2026)
Web stack
Next.js 15 (App Router), React 19, TypeScript, Tailwind CSS v4, Framer Motion, Radix UI
Docs
Fumadocs (MDX), Shiki syntax highlighting
Backend
Supabase (Postgres, Auth, Row-Level Security), MongoDB / Mongoose for catalog content
Payments
Razorpay (orders, subscriptions, webhooks) behind a provider-agnostic billing layer
Distribution
shadcn registry JSON at /r/*.json, installed with npx shadcn add
Mobile
26 React Native (Expo) items and 26 Flutter items

Problem and goals

Developers building AI-era products rebuild the same UI pieces for every project, and most libraries stop at copy-paste snippets for one platform.

  • Component libraries are usually web-only; mobile teams in React Native or Flutter start from zero.
  • Copy-paste code drifts: dependencies, the cn helper and imports are easy to miss.
  • Templates and design kits live in separate products with separate logins and payments.

Goals I set for the product

  1. 1One command installs any component, with its dependencies, into the user's own project.
  2. 2Every component has a live preview, source view, props table and manual install path.
  3. 3The same catalog covers web (React / Next.js) and mobile (React Native, Flutter).
  4. 4A Pro tier that charges Indian customers in INR, monthly or yearly, without ever granting access twice or losing a paid user.
  5. 5Previews stay public so visitors can try before they buy; only account pages require sign-in.

Product walkthrough

The product has seven surfaces.

1. Landing page

Bento grids for components, templates and designs, a social dock, an iPhone device preview and CTA sections, including a CLI section that shows the install flow right on the home page.

Landing page CLI section with terminal commands
“Install components straight into your project” — the CLI section on the landing page

2. Component docs

Fumadocs-powered pages with a custom shell, sidebar and table of contents. Each component page has a live preview, a code tab with Shiki highlighting, a CLI tab with npm / pnpm / yarn / bun switching, a manual install tab and a props table.

Download Button docs page with Preview tab and CLI install tabs
Preview / Code tabs and the CLI install block with package-manager switcher
Code Block component page with package manager dropdown
The install command switches between npm, pnpm, yarn and bun
Props table for the Download Button component
Every component ships a typed props table

3. Component catalog

Current web components: Download Button, Code Block, Code Preview Block, Install Command, Copy Page Markdown, Model Picker, Models Selector and Composer Actions (micro AI components).

Docs overview grid of all React UI components
The /docs overview — every component with a live thumbnail

4. Mobile kit

A separate docs shell for React Native and Flutter: components (button, card, bottom sheet, tabs, toast, skeleton), blocks (stats grid, story rail, pricing plans) and full screens (onboarding, sign-in, chat, feed, cart, product, profile, settings). Each item renders inside a phone frame with a framework toggle.

Mobile UI overview with browse-by-category phone previews
/mobile — browse by category
All mobile items with type, category and platform filters
All items, filterable by type, category, platform and Free / Pro
Onboarding screen flow in three phone frames with React Native / Flutter toggle
A three-screen onboarding flow, with the React Native / Flutter toggle and iOS / Android switch
Product screen rendered inside an iPhone 15 Pro frame
A Pro commerce screen inside the phone-frame preview

5. Templates and designs

Filtered galleries with sorting, detail pages per template and premium badges.

Keep notes app landing page template detail page
Unlock template checkout modal with yearly and monthly options
A template detail page, and the checkout that opens from “Unlock with Pro”

6. Auth

Email + password, OAuth and email confirmation through Supabase. After login the user returns to where they started, including an open checkout.

Login page in light mode
Login page in dark mode
Sign-in with Google, GitHub or email — light and dark

7. Pricing, checkout and billing

Monthly (₹999 / month, auto-renews) or yearly (₹7,999 one-time, “Save 33%”). Razorpay Checkout opens in a modal; the billing page shows status, renewal date and cancel.

Pricing page with Free, Pro Monthly and Pro Yearly plans
Free, Pro Monthly and Pro Yearly

Architecture

One Next.js 15 app serves the marketing site, the docs, the static registry JSON and the billing API. Supabase holds users and money; MongoDB holds catalog content.

Tech stack

LayerChoiceWhy
FrameworkNext.js 15 App Router, React 19Server components, route groups, API routes and middleware in one deploy
StylingTailwind CSS v4, Radix UI, Framer MotionSame primitives the shadcn ecosystem expects, so installed components just work
DocsFumadocs MDX, ShikiTyped MDX collections (docs, mobile, authdocs, backgrounds) with frontmatter validated by Zod
RegistryCustom build script (tsx) emitting shadcn registry-item JSONNo extra infra: JSON is served from /r with a one-year immutable cache header
AuthSupabase Auth via @supabase/ssrCookie sessions that work in middleware, server actions and route handlers
Billing dataSupabase Postgres with RLS and security-definer functionsAtomic, idempotent grants inside the database
PaymentsRazorpay (Stripe kept behind the same interface)INR, UPI and Indian cards; monthly subscriptions and one-time orders
ContentMongoDB + MongooseTemplates, designs, enquiries, feedback
EmailResend, NodemailerContact and transactional mail
Data fetchingTanStack Query with persisted cacheFast template galleries
HostingVercel (+ Analytics, Blob, next-video)Zero-config deploys from GitHub

Folder structure

lokalhost_io/
lokalhost_io/
├── app/
│   ├── (auth)/                 login, sign-up
│   ├── (main)/                 site, docs, templates, designs, pricing, checkout, account
│   │   ├── api/billing/        checkout, verify, status, cancel
│   │   ├── api/webhooks/razorpay/
│   │   ├── docs/[[...slug]]/   Fumadocs pages
│   │   └── preview/[[...slug]]/  isolated component previews
│   └── (mobile)/mobile/        React Native + Flutter docs shell
├── components/
│   ├── lokalhost_io/           the components shipped through the registry
│   ├── mdx/                    preview, code view, install tabs, props table
│   ├── docs/  mobile/          docs shells, sidebars, phone frame
│   ├── billing/                checkout dialog, billing UI
│   └── landing/  ui/  magicui/ ...
├── content/
│   ├── docs/                   component MDX pages
│   └── mobile/                 installation, CLI, theming, changelog
├── registry/
│   ├── schema.ts               Zod schema for registry entries
│   ├── registry-components.ts, registry-lib.ts, index.ts
│   └── mobile/react-native/  mobile/flutter/   26 + 26 items
├── public/r/                   generated registry JSON (download-button.json, ...)
├── scripts/
│   ├── build-registry.ts       npm run build:registry
│   └── razorpay-setup.ts       npm run billing:check
├── lib/
│   ├── billing/                provider interface, razorpay, entitlements, logging
│   ├── supabase/               browser, server, admin, middleware clients
│   ├── mobile/                 catalog, install commands, nav
│   ├── models/                 Mongoose models
│   └── registry.ts  safe-redirect.ts  plans.ts  env.ts
├── supabase/migrations/        billing schema, RLS, grant functions
├── middleware.ts               session refresh, route protection, OAuth fallback
└── source.config.ts            Fumadocs collections

Deep dives

A. Component registry and CLI distribution

Instead of publishing my own npm package, I made lokalhost.io a shadcn-compatible registry: users run the shadcn CLI they already have, pointed at my JSON.

  1. 1Each component is declared once in registry/registry-components.ts (name, type, dependencies, registryDependencies, file paths), validated by a Zod schema in registry/schema.ts.
  2. 2npm run build:registry runs scripts/build-registry.ts, which reads every source file, inlines its content and writes public/r/<name>.json with the official $schema.
  3. 3Next.js serves /r/* with Cache-Control: public, max-age=31536000, immutable.
  4. 4The docs build the install command per package manager from lib/registry.ts, so every page shows the right command for npm, pnpm, yarn or bun.
terminal
npx shadcn@latest add https://lokalhost.io/r/download-button.json

For mobile, React Native items use a namespaced registry (@lokalhost/<slug>, set once in components.json), and Flutter items install through npx lokalhost@latest add <slug> --flutter, which writes into lib/widgets and runs flutter pub add.

Onboarding screen code view and namespaced install command
A mobile screen's code view, installed with npx shadcn@latest add @lokalhost/onboarding

B. Payments and subscriptions with Razorpay

Access is never granted from the browser: the browser only reports a payment, the server verifies it and Postgres decides. Whichever of the verify call or the webhook arrives first grants access; the second finds the payment already recorded and does nothing.
  • Plans. pro_monthly (₹999, recurring Razorpay subscription) and pro_yearly (₹7,999 one-time order, 365 days). Prices are read from the plans table on the server; the client copy in lib/plans.ts is display-only.
  • Checkout. POST /api/billing/checkout creates an order or subscription and returns the public key and ids to open Razorpay Checkout.
  • Verify. POST /api/billing/verify checks the HMAC-SHA256 signature with a timing-safe comparison, fetches the payment from Razorpay and grants access.
  • Webhook. /api/webhooks/razorpay verifies the signature on the raw body, records the event in webhook_events and processes it once. A failure returns 500 so Razorpay retries.
  • Entitlements. Three Postgres functions (grant_for_order, grant_for_subscription_charge, revoke_for_payment) are the only code that grants or removes access. They run as security definer and only the service role may call them.
  • Stacking. Buying a year while on monthly adds the year after the current access ends and schedules the monthly plan to cancel at cycle end.
  • Self-service. /account/billing shows status and lets the user cancel; they keep access until the paid period ends.
  • Provider-agnostic. lib/billing/provider.ts defines a BillingProvider interface, so Stripe can be added without touching routes or SQL.

C. Authentication and safe redirects

Supabase Auth handles email / password and OAuth; middleware.ts refreshes the session on every request and protects only /account. A buyer who clicks “Buy” while logged out goes to /login?next=/pricing&plan=pro_yearly and comes back with checkout opening automatically. lib/safe-redirect.ts rejects absolute URLs, //evil.com, backslashes and control characters, which closes open-redirect holes.

D. Docs and preview system

Reusable MDX components (Preview, CodeView, InstallationTabs, ManualInstallation, PropsTable) render every component page from the same parts. /preview/[[...slug]] renders a component alone for iframe previews, and /mobile generates its pages from lib/mobile/catalog.ts instead of one MDX file per item.

Challenges and how I solved them

The two hardest problems were shipping a registry that the shadcn CLI accepts on every machine, and taking real money without ever granting access twice or losing a paying user.

1. Building a component registry with CLI install

Problem. I wanted npx shadcn add <url> to install my components, but the CLI is strict about the JSON it accepts and failed in ways that were hard to trace (2–5 Jul 2026).

  • Unsafe file path errors. File paths with a leading / made the CLI abort with “unsafe file path”, because it treats them as absolute. Fix: a toRelative() step in the build script so every path and target is relative.
  • Builds that lied. Early versions caught write errors and still printed “done”, so a broken registry reached production. Fix: no silent catches; any missing source file or duplicate name throws, and the script exits with code 1 so the Vercel build fails.
  • Wrong URLs in install commands. NEXT_PUBLIC_BASE_URL was set with a protocol in one environment and without in another. Fix: lib/registry.ts normalises the base URL once and every command is built from it.
  • Source files missing in production. The code view reads component source at runtime, but Vercel's file tracing dropped those files. Fix: outputFileTracingIncludes for components/lokalhost_io/**.
  • Flutter is not a shadcn target. The shadcn CLI only installs JS/TS. Fix: React Native uses a namespaced shadcn registry, and Flutter gets its own lokalhost CLI command plus a Manual tab as a fallback.
  • Keeping docs and registry in sync. Fix: one registry entry drives the JSON, the CLI command, the manual dependency list and the docs page.

2. Payment integration with Razorpay

Problem. Payments arrive through two paths at once (the browser's verify call and Razorpay's webhook). Events can arrive late, twice or out of order, and any mistake either gives free access or takes money without giving access. It took four iterations (pull requests 12–15, 13 Nov 2026).

  • Race between verify and webhook. Both could grant the same payment. Fix: all grants go through Postgres functions that take a per-user advisory lock and use ON CONFLICT (provider_payment_id) DO NOTHING, so repeat calls are harmless.
  • Duplicate and out-of-order webhooks. Fix: a webhook_events table keyed by Razorpay's event id (or a SHA-256 of the body) with processed_at and attempts; a finished subscription is never revived by a late event, and “authenticated” never downgrades an “active” subscription.
  • Signature checks failing. Parsing JSON before verifying changes the bytes. Fix: read the raw body first, verify HMAC-SHA256 with timingSafeEqual, then parse.
  • Price tampering. Fix: the amount is always read from the plans table on the server, and the SQL rejects any payment whose amount or currency does not match.
  • Payments refunded automatically. If auto-capture is off, Razorpay refunds authorized payments. Fix: a capture fallback that captures through the API when the amount matches.
  • Double clicks creating two orders. Fix: an unpaid order or subscription created in the last 30 minutes is reused.
  • Subscription activation lag. Right after payment the subscription is often not “active” yet. Fix: verify polls up to 3 times, 1.2 s apart, and the webhook grants it if that window passes.
  • Monthly and yearly overlap. Fix: monthly is blocked while any access is live; yearly stacks after current access and schedules the monthly plan to cancel at cycle end.
  • Test vs live mode confusion. Fix: npm run billing:check reports which mode the keys are in and can create the ₹999 plan in that mode.
  • Payment-gateway approval. Fix: added Terms, Privacy, Refund and Shipping policy pages.

3. Auth redirects that silently broke

Problem. After OAuth, users sometimes landed on the home page instead of the checkout they started. Supabase matches redirect URLs exactly, so adding ?next= made the allowed callback URL stop matching and Supabase fell back to the Site URL.

Fix. The return path travels in an httpOnly cookie (lk_next, 30 minutes) instead of the URL, middleware forwards any stray /?code= to /auth/callback, and the callback origin comes from the request so localhost and production both work.

4. Two mobile frameworks, one catalog

Problem. Keeping 26 React Native items and 26 Flutter items consistent, with docs, previews and install steps, is double the work.

Fix. A single typed catalog (lib/mobile/catalog.ts) generates every component, block and screen page; one phone-frame preview and a framework toggle render both. Old /mobile/* URLs keep working through redirects in next.config.ts.

5. Scope and momentum as a solo builder

Problem. The product spans components, templates, designs, mobile, auth and billing, built alone, with a four-month gap between July and November 2026.

Fix. I shipped in vertical slices behind feature branches and pull requests (registry first, then docs, then mobile, then billing), and wrote explanatory comments in the code so I could pick the work back up quickly.

Results, learnings and next steps

In about five months I took lokalhost.io from first commit to a live product with CLI-installable components, a two-framework mobile kit and working INR billing.

What shipped

  • 6 registry items published at /r (5 components + the utils helper), each installable with one command in npm, pnpm, yarn or bun.
  • 52 mobile items (26 React Native, 26 Flutter) with phone-frame previews.
  • Full billing: monthly subscription, yearly one-time plan, verify route, webhook, cancel flow, billing page, and an 11-table Supabase schema with RLS.
  • Auth with email, OAuth and safe post-login redirects back into checkout.

What I learned

  1. 1Build on standards people already use. Shipping a shadcn registry meant zero new tooling for users.
  2. 2Make builds fail loudly. A script that prints “done” after an error costs more than one that crashes.
  3. 3Treat payments as a distributed system. Webhooks repeat and reorder; idempotency keys and database-level locks are the real safety net.
  4. 4Never trust the client with money. Price, plan and access are decided on the server and in SQL.
  5. 5Read the provider's exact rules. The Supabase redirect bug came from one query string.

Next steps

  • Publish the mobile registry endpoints and the lokalhost Flutter CLI.
  • Clean up registry names (one duplicated entry is rejected by the build guard).
  • Add Stripe behind the existing BillingProvider interface for international buyers.
  • Gate Pro components and templates with has_active_access and API tokens.
  • Billing emails (renewal, failed payment) through Resend.
  • Automated tests for the billing functions and the registry build.

Links and references

HILAL-11

HILAL