Skip to content

Repository files navigation

FlashCart ⚡

A lightning-fast, production-grade headless e-commerce storefront built with Next.js 14+, TypeScript, Tailwind CSS, and GraphQL/REST API integration. Features secure Stripe & PayPal webhook handling for production-ready payments.

Next.jsTypeScriptTailwind CSSStripePayPalLicense: MIT


🚀 Features

AreaHighlights
Performance⚡ Next.js App Router, Server Components, ISR, Edge caching, optimized images
UI/UX🎨 Tailwind CSS design system, responsive mobile-first, accessible (WCAG 2.1 AA)
Payments💳 Stripe Checkout / Elements + PayPal Smart Buttons, webhook verification, idempotency
Cart & Checkout🛒 Client-side cart (Zustand), server-side order creation, inventory reservation
Data Layer🔗 GraphQL (Apollo) + REST fallback, typed hooks, optimistic updates
Auth (optional)🔐 NextAuth.js ready, JWT sessions, social providers
Observability📊 Structured logging (Pino), error tracking (Sentry), webhook audit logs
Testing✅ Vitest + React Testing Library (unit), Playwright (e2e)
CI/CD🔁 GitHub Actions: lint, type-check, test, build, deploy to Vercel

📦 Tech Stack

LayerTechnology
FrameworkNext.js 14 (App Router, Server Components)
LanguageTypeScript 5 (strict mode)
StylingTailwind CSS 3, Headless UI, Radix UI primitives
StateZustand (cart), TanStack Query (server state)
APIGraphQL (Apollo Client) + REST (fetch wrapper)
PaymentsStripe Node SDK, PayPal Node SDK, webhook signatures
ValidationZod (schemas), React Hook Form
TestingVitest, React Testing Library, Playwright
Lint/FormatESLint (Airbnb + Next), Prettier, Husky
DeployVercel (recommended), Docker-ready

🗂 Project Structure

FlashCart/
├── public/ # Static assets
├── src/
│ ├── app/ # Next.js App Router pages & layouts
│ │ ├── (auth)/ # Auth route group
│ │ ├── (shop)/ # Public shop routes
│ │ ├── api/ # API routes (webhooks, server actions)
│ │ └── checkout/ # Multi-step checkout flow
│ ├── components/
│ │ ├── ui/ # Reusable design-system primitives
│ │ ├── layout/ # Header, Footer, Navigation
│ │ ├── product/ # ProductCard, ProductGrid, PDP
│ │ ├── cart/ # CartDrawer, CartSummary, LineItem
│ │ └── checkout/ # ShippingForm, PaymentMethod, ReviewOrder
│ ├── context/ # React Context providers (CartProvider, etc.)
│ ├── hooks/ # Custom hooks (useCart, useProducts, etc.)
│ ├── lib/
│ │ ├── api/ # GraphQL client, REST wrapper, endpoints
│ │ ├── stripe/ # Stripe server/client helpers
│ │ ├── paypal/ # PayPal server/client helpers
│ │ ├── utils/ # Formatters, validators, constants
│ │ └── hooks/ # Shared TanStack Query hooks
│ ├── styles/ # Global CSS, Tailwind config extensions
│ └── types/ # Shared TypeScript interfaces
├── .github/workflows/ # CI/CD pipelines
├── tests/ # Playwright e2e specs
├── docker/ # Dockerfile, docker-compose.yml
├── next.config.ts
├── tailwind.config.ts
├── tsconfig.json
└── package.json

🛠 Getting Started

Prerequisites

  • Node.js ≥ 20 (LTS)
  • npm ≥ 10 (or pnpm/yarn)
  • Stripe account (test keys)
  • PayPal Developer account (sandbox)
  • Backend API (GraphQL/REST) — see Environment Variables

Installation

# 1️⃣ Clone
git clone https://github.com/MatthewCaples/flashcart.git
cd flashcart
# 2️⃣ Install deps
npm ci
# 3️⃣ Configure env
cp .env.example .env.local
# edit .env.local with your keys# 4️⃣ Run dev server
npm run dev

Open http://localhost:3000 🎉


⚙️ Environment Variables

VariableRequiredDescription
NEXT_PUBLIC_API_URLGraphQL/REST backend base URL
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEYStripe publishable key
STRIPE_SECRET_KEYStripe secret key (server-only)
STRIPE_WEBHOOK_SECRETwhsec_… from Stripe CLI / Dashboard
NEXT_PUBLIC_PAYPAL_CLIENT_IDPayPal client ID
PAYPAL_CLIENT_SECRETPayPal secret (server-only)
PAYPAL_WEBHOOK_IDPayPal webhook ID for verification
NEXT_PUBLIC_APP_URLCanonical frontend URL (for webhooks)
SENTRY_DSNError tracking (optional)
NEXT_PUBLIC_GA_IDGoogle Analytics 4 (optional)

Never commit real secrets. Use .env.local (git-ignored) locally; configure in Vercel / CI secrets for deployments.


🧪 Testing

# Unit / integration
npm run test# Watch mode
npm run test:watch
# Coverage
npm run test:coverage
# E2E (Playwright)
npm run test:e2e

📜 Available Scripts

CommandDescription
npm run devStart dev server (Turbopack)
npm run buildProduction build
npm run startRun production server
npm run lintESLint + Prettier check
npm run lint:fixAuto-fix lint issues
npm run type-checktsc --noEmit
npm run testVitest unit tests
npm run test:e2ePlaywright e2e tests
npm run formatPrettier write
npm run prepareHusky install (post-install)

🔐 Webhook Security

Both Stripe and PayPal webhooks are verified server-side:

// src/app/api/webhooks/stripe/route.tsimport{headers}from'next/headers';import{stripe}from'@/lib/stripe';import{Webhook}from'stripe';exportasyncfunctionPOST(req: Request){constbody=awaitreq.text();constsignature=headers().get('stripe-signature')!;letevent;try{event=stripe.webhooks.constructEvent(body,signature,process.env.STRIPE_WEBHOOK_SECRET!);}catch(err){returnnewResponse(`Webhook Error: ${err.message}`,{status: 400});}// Handle event.type → order.created, payment_intent.succeeded, etc.returnnewResponse(null,{status: 200});}

PayPal uses PAYPAL_WEBHOOK_ID + paypal-webhook-sdk verification.


🐳 Docker (Production)

# Build image
docker build -t flashcart -f docker/Dockerfile .# Run container
docker run -p 3000:3000 --env-file .env.production flashcart

docker-compose.yml spins up the app + a local Redis (for cart caching) for full-stack local dev.


🚢 Deployment (Vercel)

  1. Push to GitHub.
  2. Import project in VercelAdd Environment Variables (from table above).
  3. Deploy 🎉 — Preview on every PR, Production on main.

Edge Middleware rewrites /checkout/* to the Node runtime (required for Stripe/PayPal Node SDKs).


🤝 Contributing

  1. Fork → create feature branch (git checkout -b feat/amazing-feature)
  2. Commit with Conventional Commits (feat: add product quick-view)
  3. Push → open PR → CI must pass (lint, type-check, tests, build)
  4. Code review → squash merge

📄 License

MIT © MatthewCaples


🙏 Acknowledgements

About

A lightning-fast headless e-commerce storefront built with Next.js, TypeScript, Tailwind CSS, and Stripe/PayPal webhooks.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages