MVP Technical Specification v1.0

Bakery E-Commerce
Full-Stack Blueprint

Complete technical specification for building a modern bakery website with online payments, real-time delivery tracking, and comprehensive admin tools.

Technology Stack

Modern, scalable, and production-ready

Next.js 14
Frontend
Express
Backend
PostgreSQL
Database
Stripe
Payments
Socket.io
Real-time
Vercel
Deployment

System Architecture

Frontend Layer
Next.js App
Pages & Components
Zustand State
React Query
Stripe Elements
Backend Layer
Express API
REST Endpoints
JWT Auth
Prisma ORM
Socket.io Server
Data & Services
PostgreSQL
Stripe API
Cloudinary
Redis Cache

Data Model

Users
id UUID PK
email String
password_hash String
name String
phone String?
role Enum
created_at DateTime
Products
id UUID PK
name String
slug String
description Text
base_price Decimal
category_id UUID FK
images Json
is_active Boolean
ProductVariations
id UUID PK
product_id UUID FK
size String
flavor String?
price_modifier Decimal
sku String
stock Int
Orders
id UUID PK
order_number String
user_id UUID FK?
status Enum
subtotal Decimal
delivery_fee Decimal
total Decimal
delivery_address Json
Deliveries
id UUID PK
order_id UUID FK
driver_name String?
status Enum
current_location Json?
eta DateTime?
delivered_at DateTime?
Payments
id UUID PK
order_id UUID FK
stripe_payment_id String
amount Decimal
status Enum
method String
paid_at DateTime?

API Contract

Authentication
JWT Bearer Token
POST /api/auth/register Create account
POST /api/auth/login Login, returns JWT
POST /api/auth/refresh Refresh token
Products
Public + Admin
GET /api/products List with filters
GET /api/products/:slug Product detail
POST /api/admin/products Create product 🔒
PUT /api/admin/products/:id Update product 🔒
Orders
Authenticated
POST /api/orders Create order
GET /api/orders/:id Order details
GET /api/orders/:id/track Live tracking
POST /api/checkout/session Create Stripe session

Core Screens

Home
Hero, featured items
Catalog
Categories, grid view
Product
Details, variations
Cart
Items, totals
Checkout
Address, payment
Tracking
Status, map, ETA
Account
Profile, orders
Admin
Dashboard, CRUD

MVP Timeline

1

Foundation

Week 1-2

Project setup, database design, authentication system

Next.js setup Prisma schema JWT auth User CRUD
2

Product Catalog

Week 3-4

Categories, products, variations, image handling

Product API Catalog UI Cloudinary Search
3

Cart & Checkout

Week 5-6

Shopping cart, Stripe integration, order creation

Cart state Stripe Elements Webhooks Order flow
4

Delivery Tracking

Week 7-8

Real-time status updates, driver location, ETA

Socket.io Status UI Map integration Notifications
5

Admin & Polish

Week 9-10

Admin panel, testing, performance, deployment

Admin dashboard E2E tests SEO CI/CD

Code Snippets

Product Listing API products.controller.ts
export const getProducts = async (req, res) => {
  const { category, search, page = 1, limit = 12 } = req.query;
  
  const where = {
    isActive: true,
    ...(category && { category: { slug: category } }),
    ...(search && {
      OR: [
        { name: { contains: search, mode: 'insensitive' } },
        { description: { contains: search, mode: 'insensitive' } }
      ]
    })
  };

  const [products, total] = await Promise.all([
    prisma.product.findMany({
      where,
      include: {
        category: true,
        variations: true,
        images: { orderBy: { order: 'asc' } }
      },
      skip: (page - 1) * limit,
      take: limit,
      orderBy: { createdAt: 'desc' }
    }),
    prisma.product.count({ where })
  ]);

  return res.json({
    products,
    pagination: {
      page: Number(page),
      limit: Number(limit),
      total,
      pages: Math.ceil(total / limit)
    }
  });
};
Stripe Checkout checkout.controller.ts
export const createCheckoutSession = async (req, res) => {
  const { items, deliveryAddress } = req.body;
  
  const lineItems = items.map(item => ({
    price_data: {
      currency: 'usd',
      product_data: {
        name: item.name,
        images: [item.image],
        metadata: { productId: item.id }
      },
      unit_amount: Math.round(item.price * 100)
    },
    quantity: item.quantity
  }));

  const session = await stripe.checkout.sessions.create({
    mode: 'payment',
    payment_method_types: ['card'],
    line_items: lineItems,
    success_url: `${process.env.FRONTEND_URL}/order/success?session_id={CHECKOUT_SESSION_ID}`,
    cancel_url: `${process.env.FRONTEND_URL}/cart`,
    metadata: {
      userId: req.user?.id,
      deliveryAddress: JSON.stringify(deliveryAddress)
    }
  });

  return res.json({ sessionId: session.id, url: session.url });
};
Real-time Delivery Tracking delivery.socket.ts
// Server-side Socket.io handler
io.on('connection', (socket) => {
  socket.on('subscribe:order', async (orderId) => {
    socket.join(`order:${orderId}`);
    
    const delivery = await prisma.delivery.findFirst({
      where: { orderId },
      include: { order: true }
    });
    
    socket.emit('delivery:status', {
      status: delivery?.status || 'pending',
      eta: delivery?.eta,
      driverName: delivery?.driverName,
      currentLocation: delivery?.currentLocation
    });
  });

  socket.on('driver:location', async ({ orderId, location }) => {
    await prisma.delivery.update({
      where: { orderId },
      data: { currentLocation: location, updatedAt: new Date() }
    });
    
    io.to(`order:${orderId}`).emit('delivery:location', location);
  });
});

// Client-side React hook
const useDeliveryTracking = (orderId: string) => {
  const [status, setStatus] = useState<DeliveryStatus>(null);
  
  useEffect(() => {
    const socket = io(process.env.NEXT_PUBLIC_WS_URL);
    socket.emit('subscribe:order', orderId);
    socket.on('delivery:status', setStatus);
    socket.on('delivery:location', (loc) => setStatus(prev => ({ ...prev, currentLocation: loc })));
    return () => socket.disconnect();
  }, [orderId]);
  
  return status;
};

Non-Functional Requirements

Performance
  • LCP < 2.5s on 3G
  • API response < 200ms p95
  • Image optimization via CDN
  • Redis caching for catalog
Accessibility
  • WCAG 2.1 AA compliant
  • Keyboard navigation
  • Screen reader support
  • Color contrast 4.5:1+
SEO & Social
  • SSR/SSG for pages
  • Open Graph meta tags
  • Structured data (JSON-LD)
  • Sitemap generation