How saranskumar/secondchances works
1. This is a Next.js App Router application that implements an e-commerce marketplace flow: public browsing, authenticated shopping, checkout, order management, and role-based dashboards for buyers and sellers.
2. The top-level architecture is split between UI routes under src/app, reusable UI/components under src/components, shared client state in src/contexts, and backend integration helpers in src/lib/supabase. The app appears to use Supabase as its primary backend for auth, database, and storage.
3. The route structure shows the main user journeys:
- src/app/page.tsx as the landing/home page
- browse, products/[id], and cart for discovery and shopping
- checkout for purchase completion
- orders/[id] for order detail views
- dashboard/buyer and dashboard/seller for role-specific account areas
- profile for user profile/feedback
- auth/* for sign-in, sign-up, OTP verification, password reset, and auth callback handling
- legal/* for static policy pages
4. The data and business-logic boundary is centered in src/actions. These server-side action modules (addresses.ts, orders.ts, products.ts, profile.ts) likely encapsulate CRUD and workflow operations against Supabase, separating page/components from direct database access and keeping mutations on the server side.
5. Authentication is handled through Supabase helpers in src/lib/supabase/client.ts, server.ts, and middleware.ts, plus a global src/middleware.ts. This indicates a boundary where requests are authenticated/rewritten at the edge or server layer, while Supabase client instances are configured differently for browser, server, and middleware contexts.
6. The app uses a shared cart state in src/contexts/CartContext.tsx, which suggests cart interactions are client-side and persistent enough to be shared across browse/product/checkout pages. The Add to Cart button and product card components reinforce that product selection is a reusable front-end concern, with checkout likely consuming cart state rather than re-fetching it from every page.
7. UI composition is modular and layered:
- src/components/ui contains primitive design-system controls such as Button, Input, Card, and Badge
- src/components/layout contains cross-cutting shell elements like Navbar and Footer
- src/components/ProductCard and src/components/AddToCartButton provide domain-specific commerce UI
This suggests a clean separation between generic UI, layout chrome, and commerce-specific widgets.
8. The Supabase directory is an important infrastructure boundary. It contains schema, migrations, RLS policy material, and seed data:
- initial_schema.sql and later migrations define the database structure
- storage_product_images.sql indicates product image assets are stored in Supabase Storage
- addresses.sql and order-related fixes show evolving relational data and access rules
- seed_mock_data.sql supports local development/demo data
This implies the app relies on database-enforced authorization, not just application-level checks.
9. The presence of src/types/database.ts suggests generated or hand-maintained typed database models used throughout the app to keep Supabase queries type-safe. In diagram terms, this is a shared contract layer between the Next.js app and the Supabase schema.
10. The runtime model is a hybrid Next.js setup: server components/pages and server actions for protected data access, client components for interactive shopping and form flows, and route handlers for auth callback processing. Middleware likely protects authenticated routes and/or refreshes Supabase sessions before requests reach pages.
11. The main data flow is:
user lands on public pages → browses products fetched from Supabase → adds items to client cart state → checks out through server actions → order records are written to the database → authenticated users view orders/profile/dashboard data via server-rendered pages and actions. Auth flows are routed through Supabase and the /auth/callback handler.
12. Overall, the repo is best diagrammed as a Next.js front end layered over a Supabase backend, with clear separation between presentation, client state, server mutations, and database/storage/auth infrastructure.
Main entry points: server.ts Supabase server · products.ts Products actions · orders.ts Orders actions · database.ts Database types
Components 30
Next.js app
Route segments and page flows
- Home · Landing page for public browsing
src/app/page.tsx - Browse · Product discovery and listing page
src/app/browse/page.tsx - Product detail · Single product view and purchase entry
src/app/products/[id]/page.tsx - Cart · Client cart review and edits
src/app/cart/page.tsx - Checkout · Purchase completion and payment flow
src/app/checkout/page.tsx - Order detail · View a specific order
src/app/orders/[id]/page.tsx - Buyer dashboard · Buyer order and account area
src/app/dashboard/buyer/page.tsx - Seller dashboard · Seller inventory and marketplace area
src/app/dashboard/seller/page.tsx - Profile · User profile and feedback area
src/app/profile/page.tsx - Auth hub · Entry page for authentication flows
src/app/auth/page.tsx - Auth callback · Supabase auth callback processing
src/app/auth/callback/route.ts
UI layer
Reusable presentation and layout components
- Navbar · Top-level navigation and session entry points
src/components/layout/Navbar.tsx - Footer · Shared bottom chrome
src/components/layout/Footer.tsx - Product card · Reusable product listing tile
src/components/ProductCard.tsx - Add to cart · Product purchase action button
src/components/AddToCartButton.tsx
Client state
Shared browser-side state and context
- Cart state · Shared cart state across shopping pages
src/contexts/CartContext.tsx
Server logic
Server actions and request boundaries
- Products actions · Server-side product reads and mutations
src/actions/products.ts - Orders actions · Order creation and order workflow logic
src/actions/orders.ts - Addresses actions · Saved address CRUD for checkout and profile
src/actions/addresses.ts - Profile actions · Profile and feedback updates
src/actions/profile.ts - Supabase server · Server-side Supabase client setup
src/lib/supabase/server.ts - Supabase browser · Client-side Supabase client setup
src/lib/supabase/client.ts - Supabase middleware · Auth/session handling for middleware
src/lib/supabase/middleware.ts - App middleware · Global request interception and protection
src/middleware.ts
Supabase backend
Auth, database, storage, and schema
- Database types · Shared typed Supabase schema models
src/types/database.ts - Schema · Primary database structure definition
supabase/schema.sql - Migrations · Schema evolution and production upgrades
supabase/migrations/20260226000001_initial_schema.sql - RLS policies · Row-level security rules and fixes
supabase/rls.sql - Image storage · Product image bucket and storage rules
supabase/migrations/20260313000002_storage_product_images.sql - Seed data · Mock and development seed data
supabase/seed_mock_data.sql
Connections 32
- Home → Navbar: uses · Home page uses shared navigation
- Home → Footer: uses · Home page uses shared footer
- Browse → Product card: renders · Browse page shows product cards
- Browse → Products actions: loads · Fetches catalog data through server actions
- Product detail → Add to cart: uses · Product detail exposes add-to-cart action
- Product detail → Products actions: loads · Fetches product details from backend
- Product detail → Cart state: updates · Adds selected item to shared cart state
- Cart → Cart state: consumes · Cart page reads shared cart contents
- Checkout → Cart state: consumes · Checkout uses cart state as input
- Checkout → Orders actions: submits · Creates orders through server action
- Checkout → Addresses actions: uses · Uses saved addresses during checkout
- Order detail → Orders actions: loads · Fetches order detail and status
- Buyer dashboard → Orders actions: loads · Buyer dashboard summarizes orders
- Buyer dashboard → Addresses actions: loads · Buyer dashboard manages addresses
- Seller dashboard → Products actions: loads · Seller dashboard manages product listings
- Profile → Profile actions: updates · Profile page persists user changes
- Profile → Navbar: uses · Profile page uses shared navigation
- Auth hub → Supabase browser: authenticates · Auth flows run through browser Supabase client
- Auth callback → Supabase server: finalizes · Callback completes session exchange server-side
- App middleware → Supabase middleware: wraps · Global middleware delegates Supabase session handling
- Products actions → Supabase server: queries · Server actions access Supabase from the server
- Orders actions → Supabase server: queries · Order workflow uses server Supabase client
- Addresses actions → Supabase server: queries · Address CRUD uses server Supabase client
- Profile actions → Supabase server: queries · Profile mutations use server Supabase client
- Supabase server → Database types: typed by · Server queries use database types
- Supabase browser → Database types: typed by · Browser client uses database types
- Supabase middleware → Database types: typed by · Middleware client uses database types
- Schema → Migrations: evolves into · Schema is defined and updated by migrations
- Migrations → RLS policies: enforces · Migrations include security and access rules
- Migrations → Image storage: provisions · Storage setup for product images
- Schema → Database types: generates · Database schema backs shared typed models
- Seed data → Schema: populates · Seed data matches the schema