back

work/closeby/

CloseBy

Local shop platform for Guna, with AI tools that take routine work off shop owners

Solo: design, frontend, backend, AI layer · 2026

Next.js 15TypeScriptSupabase PostgresClerkClaude APIRazorpay
CloseBy: Local shop platform for Guna, with AI tools that take routine work off shop owners

Manual work before

Shop owners type every product by hand, keep stock in their heads, and answer the same buyer questions all day. Unpaid orders and refunds are chased by hand.

What it automates

  • -Stock entry from photos and voice lists
  • -Restock and price ideas
  • -Draft chat replies
  • -Cancelling unpaid orders
  • -Refunds for rejected orders

The workflow

  1. triggerThe owner uploads a shelf photo or a voice list of stock.
  2. step 1The AI reads the catalogue through tools and drafts a stock import.
  3. step 2The owner reviews the draft and approves it. Nothing is saved before that.
  4. step 3Buyers nearby find the shop through geohash search and place an order.
  5. step 4The order moves through a seven-state machine. Razorpay holds stock until the server confirms payment.
  6. step 5Unpaid orders cancel after 15 minutes. Rejected paid orders are refunded automatically.
  7. outcomeCatalogue entry, order tracking, payment checks and refunds run on their own; the owner only approves.

status Live demo.

In short

  • -Every AI call passes one gateway: auth, rate limit, kill switch, daily spend cap, input cleaning, tool loop, cost logging.
  • -AI only drafts (stock imports, restock ideas, chat replies); the owner approves before anything is saved.
  • -Razorpay flow holds stock until payment is confirmed and auto-refunds rejected orders.
  • -27 eval cases covering Hindi aliases, misspellings and gibberish input.

Architecture

A Next.js app with a single server-side AI gateway. The model never writes to the database directly; it returns Zod-validated drafts that the owner approves.

System designOne Next.js app; every model call goes through the AI gateway, every order through the state machine.
CLIENTSNEXT.JS 15 · VERCELMANAGED SERVICESHTTPSHTTPSAIhelpersactionstool looptools ·cost logsSQLcheckout ·webhookssessionBuyersearch · order · pay ·trackShop ownercatalogue · orders ·approves AI draftsNext.js appApp Router · server actions· role-gated dashboardsAI gatewayrate limit · kill switch ·spend cap · input cleaningOrder service7-state machine · integerpaiseClaude / OpenAItool loop · switchableproviderSupabasePostgres · Realtime ·Storage · RLSClerksessions · buyer / ownerrolesRazorpaycheckout · webhooks ·refunds
  • user
  • client
  • guard
  • service
  • ai
  • data
  • external
  • call
  • logical link
  • ← scroll →
  1. 01Owner uploads a shelf photo or voice list
  2. 02Gateway: auth → rate limit → kill switch → spend cap → input cleaning
  3. 03Claude tool loop returns a structured draft (validated with Zod)
  4. 04Owner reviews and approves the draft
  5. 05Approved items saved to Supabase Postgres; cost logged per call

Decisions

+ One gateway for every model call- Calling the model from each feature directly  Rate limits, spend caps and logging live in one place, so a new AI feature can't skip them.
+ Human approval before any write- Letting the model save stock automatically  A wrong price or quantity costs a real shop money; a review step is cheap.
+ Integer paise and a seven-state order machine- Float rupees and free-form status strings  No rounding errors, and illegal status jumps are rejected at the boundary.

Failure handling

Model returns malformed or partial output

Zod validation fails closed; the owner sees an error, nothing is saved.

Daily AI spend exceeds the cap

Gateway refuses new calls until the next day; manual entry still works.

Prompt injection in uploaded text

Input cleaning plus tool-only output; the model can't trigger writes.

Numbers

27

Eval cases

7

Order states

TODO

p50 import latency

measure and fill in

TODO

Cost per import

from cost logs

Next

  • ○ Grow the eval set to ~100 hard cases
  • ○ Record a 90-second demo video
  • ○ Stock substitution suggestions