All work

RannaGhor

A multi-vendor e-commerce platform with three roles: customers who shop, vendors who sell, and admins who approve and manage.

Type
Full-stack web app
Stack
Bun, React 19, TanStack Router, Hono, Better Auth, Drizzle, PostgreSQL
Source Code
GitHub

Overview

RannaGhor is an online marketplace. Customers browse a catalog, search, save items to a wishlist, fill a cart and place orders. Vendors register, wait for approval, then manage their own products. Admins approve vendors and run the platform from an admin panel.

It also covers product bundles, coupons, ratings, notifications and promotional banners.

Problem

A marketplace has three kinds of user working on the same data with different rights. A vendor must be able to change their own products and nobody else’s. A customer must never reach a vendor or admin action. Stock and orders must stay correct while all of them act at once.

Architecture

RannaGhorA customer’s request through the checks it meets

Flowchart of how a RannaGhor request moves. Security headers are set on every response, and a signed-in request passes the session and a role check before it reaches a route handler and PostgreSQL. A customer calling a vendor route is refused at the role check by middleware that guards vendor and admin routes separately. An order locks the product rows, checks stock and reduces it in one database transaction; when two orders reach the last item, the first commits and the second is refused at the stock check.

The API is split into 21 route modules. Some routes are defined with OpenAPI schemas, so their requests and responses are validated and the API documentation is generated from the same definitions.

Tech decisions

A Bun monorepo with shared packages.

The API and the auth package share one schema, and both apps read their environment through the same package, so they cannot disagree.

Hono with typed OpenAPI routes.

One definition gives validation, types and documentation for the routes that use it.

Drizzle ORM on PostgreSQL.

The schema is written in TypeScript and split into modules for products, vendors, orders, coupons and the rest.

Better Auth for sign-in.

Email and password with verification, Google sign-in, and sessions with a “remember me” option.

Environment variables validated at start-up.

A missing or wrong value stops the app at once and names the variable.

File-based routing with TanStack Router, server state with TanStack Query.

Routes are type-checked, and data fetching and caching follow one pattern.

Challenges and solutions

  1. Challenge

    Privilege escalation.

    With three roles, one missing check lets a customer act as a vendor or an admin.

    Solution

    Role checks as middleware, proven by tests.

    Separate middleware guards vendor and admin routes. Dedicated test suites cover authorization, privilege escalation, session security and database row-level policies.

  2. Challenge

    Sign-in abuse.

    Limiting attempts by address alone does not stop an attacker who targets one account from many addresses.

    Solution

    Rate limits per account.

    Sign-in and password reset are limited per account as well as per address.

  3. Challenge

    State leaking between users.

    Cart and wishlist contents showed across accounts on a shared browser.

    Solution

    Cart and wishlist scoped to the signed-in user.

    The wishlist is stored per user, a guest’s items move to their account at sign-in, and cart and coupon state are cleared at sign-out.

  4. Challenge

    Stock under concurrent orders.

    Two orders for the last item must not both succeed.

    Solution

    Stock changes inside transactions.

    An order locks the product rows, checks stock and reduces it in one database transaction, with tests for the concurrent case.

Results

Customers shop, vendors manage their own products after an admin approves them, and admins run the platform, each in one area of a single typed codebase.

commits in under two months, 60 of them merged pull requests
64
API route modules
21
roles, each with its own area and tested access rules
3
test files across the API and the web app
15

The platform covers the full path from sign-up to a managed order, with a vendor dashboard and an admin panel.