How boli27/young-cousins works
Purpose and entry points
This is a Next.js App Router commerce backend/frontend shell: product catalog and variants, cart state, order creation/status, administrator operations, authentication, and WhatsApp notification support. The browser entry is app/page.tsx, wrapped by app/layout.tsx; server entry points are route handlers under app/api/**.
Application shell and request gating
The root layout establishes global UI styling and document-level composition through app/layout.tsx and app/globals.css. middleware.ts is the cross-cutting request boundary, likely enforcing routing/auth policy before protected API handlers execute. Authentication is exposed through the NextAuth catch-all endpoint at app/api/auth/[...nextauth]/route.ts and configured by lib/auth.ts.
Catalog domain and product APIs
Products are a first-class persisted domain, modeled in prisma/schema.prisma and initialized by prisma/seed.ts. Public catalog access is handled by app/api/products/route.ts and app/api/products/[id]/route.ts; variant management is separately scoped to app/api/products/[id]/variants/route.ts. Administrative product operations use app/api/admin/products/route.ts, establishing a public-versus-admin API boundary.
Cart and order lifecycle
Client-side cart state is isolated in store/cart.ts, rather than represented as a dedicated cart API. Order orchestration is centralized in lib/orders.ts: the public collection endpoint (app/api/orders/route.ts) creates or retrieves orders, while app/api/orders/[id]/status/route.ts advances order status. Administrative order access is separated at app/api/admin/orders/route.ts, where staff-oriented listing or management belongs.
Persistence boundary
Prisma is the database access layer, with shared client initialization in lib/prisma.ts, schema definitions in prisma/schema.prisma, and versioned database changes in prisma/migrations/20260714204830_init/migration.sql. API routes and order services should depend on this shared Prisma boundary rather than directly creating database clients.
API composition and external integration
lib/api-helpers.ts provides a likely common response/error/request-validation boundary for route handlers. lib/whatsapp.ts encapsulates outbound WhatsApp messaging, keeping notification-provider behavior outside order routes and persistence code. The expected flow is cart state → order API/service → Prisma persistence → optional WhatsApp notification, with status changes routed through the dedicated status endpoint.
Runtime and infrastructure
The project runs on Node.js via Next.js and TypeScript, using the App Router route-handler runtime. Prisma requires a configured database connection and migration deployment. NextAuth requires authentication-provider/session configuration. WhatsApp delivery requires provider credentials/configuration. next.config.ts is the Next.js runtime/build integration point; deployment is compatible with Vercel per the repository README.
Main entry points: prisma.ts Prisma client · orders.ts Order orchestration · page.tsx Browser UI · middleware.ts Request middleware
Components 21
Next.js application
- Browser UI
app/page.tsx - Root layout · Provides document composition and global styling.
app/layout.tsx - Request middleware · Applies cross-cutting routing and authentication policy.
middleware.ts - Cart state · Keeps cart state in the client rather than a cart API.
store/cart.ts
Route handlers
- Auth endpoint
app/api/auth/[...nextauth]/route.ts - Public products API
app/api/products/route.ts - Product detail API
app/api/products/[id]/route.ts - Variant API
app/api/products/[id]/variants/route.ts - Admin products API
app/api/admin/products/route.ts - Orders API · Creates or retrieves orders.
app/api/orders/route.ts - Order status API · Advances an order through its status lifecycle.
app/api/orders/[id]/status/route.ts - Admin orders API
app/api/admin/orders/route.ts
Domain services
- Auth configuration
lib/auth.ts - API helpers · Centralizes route validation, errors, and responses.
lib/api-helpers.ts - Order orchestration · Coordinates order creation and lifecycle work.
lib/orders.ts - WhatsApp notifications · Encapsulates outbound notification delivery.
lib/whatsapp.ts
Persistence
- Prisma client · Shared database client boundary for routes and services.
lib/prisma.ts - Commerce schema · Defines persisted products, variants, and order data.
prisma/schema.prisma - Initial migration
prisma/migrations/20260714204830_init/migration.sql - Catalog seed · Initializes persisted catalog data.
prisma/seed.ts - Configured database
Connections 22
- Browser UI → Root layout: renders within
- Browser UI → Cart state: uses
- Browser UI → Public products API: reads catalog
- Cart state → Orders API: submits order
- Request middleware → Auth endpoint: gates requests
- Request middleware → Admin products API: protects
- Request middleware → Admin orders API: protects
- Auth endpoint → Auth configuration: uses
- Public products API → Prisma client: queries
- Product detail API → Prisma client: queries
- Variant API → Prisma client: manages
- Admin products API → Prisma client: manages
- Orders API → Order orchestration: creates or retrieves
- Order status API → Order orchestration: updates status
- Admin orders API → Prisma client: lists or manages
- Orders API → API helpers: uses
- Order orchestration → Prisma client: persists orders
- Order orchestration → WhatsApp notifications: notifies optionally
- Prisma client → Commerce schema: maps
- Prisma client → Configured database: connects to
- Initial migration → Configured database: deploys schema
- Catalog seed → Prisma client: loads catalog