· 3 min read
Lotia: one marketplace, a storefront for every seller
How a Rosario marketplace served every seller from one Next.js app: subdomain tenancy, in-house auth, encrypted messages, plans and an admin app.
Lotia was a marketplace for Rosario, Argentina, where individuals, agencies and real estate companies listed vehicles, properties and other things for sale. The project is discontinued and the app is offline. The screenshots in this post come from a local copy running on invented listings, not from real sellers or buyers. What follows is how it was put together.

One app, two kinds of host
Every seller can get a storefront on a subdomain of their own, such as solis.rosario-garage.com. There is no second deployment per tenant. A single Next.js app looks at the hostname and rewrites the request: the root domain goes to /root/... and any subdomain goes to /[subdomain]/....
A small proxy classifies the host first. Public storefronts pass straight through. A request for /panel or /admin on the root domain without a session cookie is sent to the login page.
The root domain is read from one environment variable, so moving the brand from rosario-garage.com to lotia.ar would have been a one-line change. Custom domains go through a CNAME record, and provisioning it is a durable workflow, because "wait for DNS to verify" does not fit in a request handler.

Workspaces, not users
A seller is a workspace. An agency with fifteen members and a person selling one car have the same shape of data and different plan limits. Inviting someone to a workspace is a durable workflow too, not a one-off request.
Auth written in-house
The first version used Clerk. The later one does not. Passwords use scrypt, sessions are Ed25519-signed tokens through jose, refresh tokens rotate and a reused one is treated as theft, and every session carries its own CSRF token. On top of that sit TOTP, passkeys and sign-in by scanning a QR code from a phone.
Messages, encrypted, and reused for support
Buyers and sellers talk over WebSockets, with attachments stored in Blob. Message bodies are encrypted at rest with AES-256-GCM, using a key per conversation.
Support tickets are conversations of a different kind, SUPPORT. That reuses threads, sequence numbers, read cursors and the encryption, so a ticket renders in the existing inbox with nothing built in parallel. An unassigned ticket is one with a single participant, which makes "unassigned" something you can query instead of a column someone has to keep in sync.
Three plans, one source of truth
Personal is free and allows three published listings at a time. Pro costs ARS 24.900 a month, allows 30 listings, includes analytics and a custom subdomain. Agencia costs ARS 79.900 a month, allows 250 listings and 15 members, and gets priority support.
The definition of the plans lives in one file, lib/billing/catalog.ts, and the terms of service are generated from it. That rule exists because an earlier version of the legal text promised monthly quotas and expiry dates the product never implemented. Payments go through Mercado Pago subscriptions, with idempotent webhooks and a scheduled job that downgrades plans that lapse.

An admin app that shares the domain layer
The moderation and support tools are a separate Next.js app that imports the main app's domain layer through a tsconfig alias, so there is no duplicated schema, service or component. One rule came out of it: every Server Action re-checks the caller's role, because an action is its own POST endpoint and the layout's gate does not protect it.

Importing a listing from a link
A seller can paste the URL of an existing ad and get an editable draft. The parser tries JSON-LD first, then OpenGraph tags, then the raw page. A price like $ 12.500.000 is read with the Argentine separators in mind, since Number("12.500.000") is NaN. The fetcher refuses private and link-local addresses and checks again after every redirect, and the result is always a draft that never publishes itself.
Design
The theme is light only, on purpose. next-themes was removed, and the dark variants that ship with shadcn were left in place but inert.

Where it stopped
The plan file ends with all twelve milestones done and one item blocked: the production database cutover. The code, the tests (172 unit tests and 15 end-to-end tests at the last count) and the docs sit in a private GitHub repository.