Skip to main content
Web ApplicationCompleted

ClickCart: E-commerce Platform Built on React and Supabase

An e-commerce store on React, TypeScript and Supabase with a database-backed cart, admin-only product writes under row-level security, and orders priced and created inside Postgres.

DeveloperMustafa Kürşad Başer
Started: Sep 2023Completed: Feb 2024
ClickCart: E-commerce Platform Built on React and Supabase

ClickCart is an e-commerce frontend wired to a real backend rather than a mock. Auth, profiles, products, carts and orders all run against Supabase. The frontend is React 18 with TypeScript and Vite; the backend is a Postgres schema built from SQL migrations, each later one paired with a rollback script, with Row Level Security on every table. The browser talks to Supabase directly, so every rule that matters has to live in the database and hold against someone calling the API with the same key.

The data model:

  • Products: Price and stock carry non-negative check constraints, with indexes on category and the featured flag. The migrations seed 33 products across five categories
  • Carts: One per user, enforced by a unique constraint. Items are unique per cart and product, quantity must be positive, and a trigger stamps the cart's last activity on every item write
  • Orders: Shipping and billing addresses as JSONB, and a status constrained to pending, processing, shipped or delivered

Who can do what:

  • Anyone can read products. Writing one requires the user to be listed in an admin_users table that has RLS on, no policies and no grants to the API roles, so it can only be changed from the SQL editor or with the service key. The product policies ask a security-definer function, is_admin(), which answers only for the calling user
  • A profile can be read by its owner or an admin, and written only by its owner
  • Cart and order items are reached through their parent: a policy checks that the cart or order belongs to the caller
  • Signing up fires two triggers on auth.users that create the profile, from the sign-up metadata, and an empty cart. Their functions run as security definer with an empty search_path

Placing an order: The browser cannot insert into orders or order_items. Checkout calls one security-definer function, create_order, with the addresses, a shipping method and a payment method. It rejects an unknown method or a missing address, locks the caller's cart row so a double submit cannot produce two orders, prices every line from the products table, adds shipping and 18% KDV, writes the order and its items, and empties the cart, in one transaction. The browser computes the same totals for display only; the stored total never comes from the client.

Shopping:

  • A catalog of 12 products per page with exact counts, six sort orders, a category filter kept in the URL, and a debounced search over title and description
  • A navbar search that suggests the top five title matches as you type
  • Product pages with up to four related products; add to cart is disabled at zero stock
  • The cart lives in Postgres, and the Zustand store reloads it after every change, so a signed-in user sees the same cart on any device

Account: Supabase Auth with email and password and a persisted session, with a loading state so protected pages do not flash the login screen. Checkout and the profile are protected routes. Changing the password re-authenticates with the current one first, and avatars go to Supabase Storage.

Stack: React 18, TypeScript, Vite, Tailwind CSS, Zustand, React Router v6, Framer Motion and Supabase for Postgres, Auth and Storage.

Not finished:

  • The wishlist, saved payment methods, address book and notification settings are placeholders
  • Payment is a choice between card and bank transfer and nothing more: the card fields are never read and no provider is connected
  • Placing an order neither checks nor reduces stock, and no code moves an order past pending
  • There is no guest cart; adding to the cart while signed out fails without a message
  • There is no admin screen, so products are managed in SQL
  • Flash deals run a client-side four-hour countdown with a fixed 30% discount computed in the UI
  • The avatars bucket is not created by the migrations, and there are no automated tests

Project Gallery

Tech Stack

ReactTypeScriptTailwind CSSSupabaseZustandFramer MotionReact Router