⚠️ IMPORTANT: This is an ARCHIVED REFERENCE
This backend implementation is NOT currently used in the CodeBook e-commerce project.
The current project uses AWS Lambda functions with AWS API Gateway (seecodebook/aws-lambda/).
This directory is kept for reference and learning purposes only.
This Vercel Serverless Functions implementation was an intermediate backend for the CodeBook project during migration from mock server to full serverless architecture. It has been replaced by a more robust AWS-native solution using:
- AWS Lambda Functions - Direct Lambda deployment (not via Vercel)
- AWS API Gateway HTTP API - Native AWS API routing
- AWS DynamoDB - NoSQL database (same as this reference)
- AWS SAM (Serverless Application Model) - Infrastructure as code
- JWT Authentication - Custom authentication system
Current Backend Location: codebook/aws-lambda/
Current Backend Documentation: See codebook/aws-lambda/README.md
This archived reference is maintained for:
- Learning purposes - Understanding Vercel serverless functions
- Reference - Comparing Vercel vs AWS Lambda approaches
- Educational value - Demonstrating different serverless patterns
- Migration history - Documenting the evolution of the backend architecture
- Runtime: Vercel Serverless Functions (Node.js 20.x)
- Database: AWS DynamoDB
- Authentication: JWT (JSON Web Tokens)
- Deployment: Vercel
cd codebook
npm installCreate a .env file in codebook/:
# AWS Credentials
AWS_ACCESS_KEY_ID=your-access-key
AWS_SECRET_ACCESS_KEY=your-secret-key
AWS_REGION=eu-north-1
# JWT Secret (change this in production!)
JWT_SECRET=your-super-secret-jwt-key-change-this
# Frontend URL (for CORS if needed)
REACT_APP_HOST=http://localhost:3000Run the table creation script:
node scripts/create-tables.jsThis will create:
codebook-productscodebook-featured-productscodebook-orderscodebook-users
Seed DynamoDB with initial data from db.json:
node scripts/migrate-dynamodb.jsAll endpoints are prefixed with /api:
POST /api/login- User loginPOST /api/register- User registrationGET /api/444/products- Get all products (with optional?name_like=search)GET /api/444/products/:id- Get product by IDGET /api/444/featured_products- Get featured products
GET /api/600/users/:id- Get user by IDGET /api/660/orders?user.id=:userId- Get user ordersPOST /api/660/orders- Create new order
Include the JWT token in the Authorization header:
Authorization: Bearer <token># Install Vercel CLI globally
npm install -g vercel
# Run locally
vercel devThe API will be available at http://localhost:3000/api/*
-
Set Environment Variables in Vercel Dashboard:
- Go to your project settings
- Add all environment variables from
.env.local
-
Deploy:
vercel deploy
Or connect your GitHub repo to Vercel for automatic deployments.
Update codebook/.env:
REACT_APP_HOST=https://your-vercel-app.vercel.app
REACT_APP_GUEST_LOGIN=test@example.com
REACT_APP_GUEST_PASSWORD=12345678api/
├── 444/
│ ├── products.js # Public product endpoints
│ └── featured_products.js
├── 600/
│ └── users/
│ └── [id].js # Protected user endpoints
├── 660/
│ └── orders.js # Protected order endpoints
├── login.js # Login endpoint
└── register.js # Registration endpoint
lib/
├── dynamodb.js # DynamoDB client setup
├── auth.js # JWT authentication utilities
├── response.js # Response helpers
├── products.js # Product data access
├── users.js # User data access
└── orders.js # Order data access
scripts/
├── create-tables.js # DynamoDB table creation
└── migrate-dynamodb.js # Data migration- The number prefixes (444, 600, 660) match the original json-server-auth access codes for compatibility
- DynamoDB uses on-demand billing (free tier eligible)
- JWT tokens expire after 7 days
- Passwords are hashed using bcrypt
Frontend (React)
↓
Vercel Serverless Functions (/api/*)
↓
AWS DynamoDBCharacteristics:
- ✅ Serverless - no server management
- ✅ Easy deployment via Vercel
- ✅ Integrated with Vercel frontend hosting
- ✅ DynamoDB for persistent storage
- ✅ JWT authentication
⚠️ Vercel function execution limits⚠️ Vendor lock-in to Vercel⚠️ Limited AWS service integration⚠️ Function timeout constraints
Frontend (React on Vercel)
↓
AWS API Gateway (HTTP API)
↓
AWS Lambda Functions (Serverless)
↓
AWS DynamoDBCharacteristics:
- ✅ Full AWS ecosystem integration
- ✅ No vendor lock-in
- ✅ More flexible function configuration
- ✅ Better cost control (AWS Free Tier)
- ✅ Advanced features (Stripe, Brevo, Shippo)
- ✅ Infrastructure as code (SAM template)
- ✅ Better monitoring and logging (CloudWatch)
- ✅ Production-ready scalability
The project migrated from Vercel Serverless Functions to AWS Lambda for:
- AWS Native Integration - Direct access to AWS services (S3, SES, etc.)
- Better Control - More configuration options (timeout, memory, etc.)
- Cost Efficiency - AWS Free Tier provides more generous limits
- Feature Rich - Easier integration with Stripe, Brevo, Shippo APIs
- Infrastructure as Code - SAM template for version-controlled infrastructure
- Flexibility - Not tied to Vercel's function execution model
- Scalability - Better handling of high-traffic scenarios
Use Vercel Serverless Functions (This Reference):
- Simple serverless APIs
- Frontend and backend on same platform (Vercel)
- Quick prototyping with Vercel
- Small to medium projects
- When you want integrated frontend/backend deployment
Use AWS Lambda (Current):
- Production applications requiring AWS services
- Complex integrations (payments, emails, shipping)
- Need for infrastructure as code
- Better cost optimization with AWS Free Tier
- Enterprise-grade scalability requirements
- Multi-cloud or AWS-first strategy
The CodeBook Serverless API using Vercel Serverless Functions was a valuable intermediate step in the project's evolution. It demonstrated serverless architecture patterns and provided a bridge between the mock server and the current AWS Lambda implementation.
Note: While this Vercel serverless functions implementation is archived and no longer used in the active CodeBook project, it remains a valuable reference for understanding:
- Vercel Serverless Functions patterns
- Serverless API architecture
- DynamoDB integration in serverless functions
- JWT authentication in serverless environments
- Backend architecture evolution
For the current production backend, see codebook/aws-lambda/README.md.