How burakorkmez/northwind-store works
Purpose and entry points
This is a PERN e-commerce platform: React SPA frontend, Express/TypeScript API, PostgreSQL persistence, authenticated checkout/orders, admin product management, and order-scoped Stream chat/video support. Backend startup is backend/src/index.ts; the browser entry and route composition begin at frontend/src/main.jsx and frontend/src/App.jsx.
Client application
The Vite React client renders catalog, product, cart, checkout return, order, admin, chat, and video views. Page-specific hooks own server-state interactions and view orchestration, while a client cart store holds shopping-cart state. API access is centralized in frontend/src/lib/api.js.
• frontend/src/App.jsx
• frontend/src/hooks/useCartPage.js
• frontend/src/store/cart.js
API and HTTP boundary
Express routers partition the API by business domain; controllers implement request handling for products, checkout, orders, administration, and Stream tokens/channel setup. The frontend reaches this boundary through its configured backend URL rather than directly accessing PostgreSQL or payment APIs.
• backend/src/routes/productRouter.ts
• backend/src/routes/chekoutRouter.ts
• backend/src/controllers/orderController.ts
Persistence and domain model
PostgreSQL, hosted on Neon, is accessed through Drizzle. The schema is the authoritative persistence boundary for users, products, orders, and related commerce state; a seed script supports initial data.
• backend/src/db/index.ts
• backend/src/db/schema.ts
• backend/scripts/seed.ts
Identity, authorization, and user lifecycle
Clerk authenticates users. Request middleware connects Clerk identity to backend/Sentry context, role utilities gate administrative operations, and the Clerk webhook synchronizes lifecycle changes into local persistence.
• backend/src/middleware/sentryClerkUser.ts
• backend/src/lib/roles.ts
• backend/src/webhooks/clerk.ts
Commerce and payment flow
Users browse products, retain a client cart, initiate checkout through the backend’s Polar integration, then return to an order/checkout UI. Polar webhooks are the server-side confirmation boundary for payment events and order state rather than trusting browser redirects.
• backend/src/controllers/checkoutController.ts
• backend/src/lib/polar.ts
• backend/src/webhooks/polar.ts
Media and customer-support collaboration
ImageKit provides product/media upload and delivery integration. Stream powers real-time order customer-support chat and video, with backend code handling privileged integration operations and frontend order views consuming the resulting experience.
• backend/src/lib/imagekit.ts
• backend/src/lib/stream.ts
• frontend/src/pages/OrderChatPage.jsx
• frontend/src/pages/OrderVideoPage.jsx
Operations and deployment
Sentry instrumentation/error UX spans backend and frontend. Backend environment validation and cron work centralize runtime operational concerns. The repository includes a Dockerfile for containerized deployment; required external infrastructure is Neon/PostgreSQL, Clerk, Polar, Stream, ImageKit, and Sentry.
• backend/src/instrument.ts
• backend/src/lib/env.ts
• backend/src/lib/cron.ts
• Dockerfile
Main entry points: productRouter.ts Commerce routers · schema.ts Commerce schema · App.jsx SPA entry & routes · index.ts API startup
Components 20
React client
- SPA entry & routes · Composes catalog, cart, checkout, order, admin, chat, and video views.
frontend/src/App.jsx - Cart store
frontend/src/store/cart.js - Cart page orchestration
frontend/src/hooks/useCartPage.js - API client · Uses the configured backend URL.
frontend/src/lib/api.js - Order chat view
frontend/src/pages/OrderChatPage.jsx - Order video view
frontend/src/pages/OrderVideoPage.jsx
Express API
- API startup
backend/src/index.ts - Commerce routers · Partitions product and checkout API endpoints.
backend/src/routes/productRouter.ts - Order controller
backend/src/controllers/orderController.ts - Checkout controller
backend/src/controllers/checkoutController.ts - Identity & admin roles · Clerk identity is attached to requests and roles gate administration.
backend/src/middleware/sentryClerkUser.ts - Clerk lifecycle webhook · Synchronizes user lifecycle changes locally.
backend/src/webhooks/clerk.ts - Polar payment webhook · Confirms payment events and order state server-side.
backend/src/webhooks/polar.ts - Commerce schema · Authoritative model for users, products, orders, and commerce state.
backend/src/db/schema.ts
External services
- Neon PostgreSQL
- Clerk
- Polar
- Stream
- ImageKit
- Sentry
Connections 23
- SPA entry & routes → Cart page orchestration: renders cart
- Cart page orchestration → Cart store: reads and updates
- SPA entry & routes → API client: uses
- API client → Commerce routers: HTTPS API
- API startup → Commerce routers: mounts
- Commerce routers → Checkout controller: checkout requests
- Commerce routers → Order controller: order requests
- Identity & admin roles → Commerce routers: authenticates and authorizes
- Checkout controller → Polar: creates checkout
- Polar → Polar payment webhook: payment events
- Polar payment webhook → Commerce schema: updates order state
- Order controller → Commerce schema: reads and writes orders
- Commerce routers → Commerce schema: product and admin data
- Commerce schema → Neon PostgreSQL: Drizzle persistence
- Clerk → Identity & admin roles: request identity
- Clerk → Clerk lifecycle webhook: lifecycle events
- Clerk lifecycle webhook → Commerce schema: syncs users
- Order chat view → Stream: order support chat
- Order video view → Stream: order support video
- Commerce routers → Stream: privileged tokens and channels
- Commerce routers → ImageKit: product media integration
- API startup → Sentry: backend instrumentation
- SPA entry & routes → Sentry: frontend error UX