A full-stack, production-ready e-commerce platform similar to Amazon, built with modern technologies and comprehensive security features.
-
β User Authentication & Authorization
- JWT-based authentication (access + refresh tokens)
- Email verification
- Password reset functionality
- Two-factor authentication (2FA) with TOTP
- OAuth2 integration (Google, Facebook)
- Role-based access control (Customer, Seller, Admin)
-
β Product Management
- Complete CRUD operations
- Advanced search and filtering
- Product variants (size, color, etc.)
- Inventory tracking
- Product recommendations
- Recently viewed products
- Image management
-
β Shopping Experience
- Persistent shopping cart
- Wishlist functionality
- Product reviews and ratings
- Real-time stock availability
-
β Order Management
- Complete checkout process
- Order tracking
- Order history
- Cancel/refund support
- Invoice generation
-
β Payment Integration
- Stripe payment processing
- Webhook handling
- Secure payment flow
- Refund management
-
β Admin Dashboard
- User management
- Product management
- Order management
- Analytics and statistics
- Framework: Node.js with Express.js
- Language: TypeScript
- Database: PostgreSQL
- ORM: Prisma
- Cache/Session: Redis
- Authentication: JWT (jsonwebtoken)
- Security: Helmet, CORS, Rate Limiting
- Validation: Zod
- Documentation: Swagger/OpenAPI
- Payment: Stripe
- Framework: Next.js 14+ (App Router)
- Language: TypeScript
- Styling: Tailwind CSS
- UI Components: shadcn/ui
- State Management: Zustand
- Forms: React Hook Form + Zod
- HTTP Client: Axios
- Payment UI: Stripe Elements
- Containerization: Docker & Docker Compose
- Database: PostgreSQL 15
- Cache: Redis 7
- Process Manager: PM2 (optional)
ecommerce-platform/
βββ backend/
β βββ src/
β β βββ config/ # Configuration files
β β βββ controllers/ # Route controllers
β β βββ middleware/ # Custom middleware
β β β βββ auth.middleware.ts
β β β βββ rateLimiter.middleware.ts
β β β βββ validation.middleware.ts
β β β βββ errorHandler.middleware.ts
β β β βββ auditLog.middleware.ts
β β βββ routes/ # API routes
β β βββ services/ # Business logic
β β β βββ auth.service.ts
β β β βββ product.service.ts
β β β βββ cart.service.ts
β β β βββ order.service.ts
β β β βββ payment.service.ts
β β βββ utils/ # Utility functions
β β β βββ encryption.ts
β β β βββ jwt.ts
β β β βββ email.ts
β β β βββ logger.ts
β β β βββ validators.ts
β β βββ prisma/ # Prisma schema
β β βββ server.ts # Main server file
β βββ .env.example
β βββ Dockerfile
β βββ package.json
β βββ tsconfig.json
βββ frontend/
β βββ src/
β β βββ app/ # Next.js pages (App Router)
β β βββ components/ # React components
β β βββ lib/ # Utilities and configs
β β βββ hooks/ # Custom React hooks
β β βββ services/ # API services
β β βββ utils/ # Helper functions
β βββ public/ # Static assets
β βββ Dockerfile
β βββ next.config.js
β βββ tailwind.config.ts
β βββ package.json
β βββ tsconfig.json
βββ docker-compose.yml
βββ README.md
- β bcrypt password hashing (cost factor 12)
- β JWT with short-lived access tokens (15 min) + long-lived refresh tokens (7 days)
- β HTTP-only secure cookies for token storage
- β Token rotation on refresh
- β Account lockout after failed login attempts
- β Two-factor authentication (2FA) with TOTP
- β Logout from all devices functionality
- β Helmet.js for security headers
- β Rate limiting with Redis store (per IP and per user)
- β CORS configuration with whitelisted origins
- β Request validation with Zod
- β Input sanitization to prevent XSS
- β Parameterized queries to prevent SQL injection
- β API versioning (v1)
- β Encryption at rest for sensitive data (AES-256-GCM)
- β TLS/SSL for data in transit
- β Environment variables for secrets
- β Audit logging for critical operations
- β CSRF protection
- β Content Security Policy (CSP)
- β XSS protection
- β Secure session management
- β NoSQL injection prevention
- β HPP (HTTP Parameter Pollution) prevention
- β Secure file upload validation
- β Docker containerization with non-root users
- β Health check endpoints
- β Winston logging (no sensitive data in logs)
- β Error handling without exposing stack traces in production
- Node.js 18+
- Docker & Docker Compose
- PostgreSQL 15+ (if not using Docker)
- Redis 7+ (if not using Docker)
- Stripe account (for payments)
git clone <repository-url>
cd e-com_appBackend:
cd backend
cp .env.example .envEdit .env and configure your environment variables:
# Database
DATABASE_URL="postgresql://postgres:postgres123@localhost:5432/ecommerce?schema=public"
# JWT Secrets (MUST be changed in production!)
JWT_ACCESS_SECRET=your-super-secret-jwt-access-key-change-in-production-min-32-chars
JWT_REFRESH_SECRET=your-super-secret-jwt-refresh-key-change-in-production-min-32-chars
# Redis
REDIS_URL=redis://localhost:6379
# Stripe
STRIPE_SECRET_KEY=sk_test_your_stripe_secret_key
STRIPE_PUBLISHABLE_KEY=pk_test_your_stripe_publishable_key
STRIPE_WEBHOOK_SECRET=whsec_your_webhook_secret
# Email (Gmail example)
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_USER=your-email@gmail.com
SMTP_PASSWORD=your-app-password
# Frontend URL
FRONTEND_URL=http://localhost:3000Frontend:
cd frontendCreate .env.local:
NEXT_PUBLIC_API_URL=http://localhost:5000/api/v1
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_your_stripe_publishable_key# From project root
docker-compose up -dThis will start:
- PostgreSQL on port 5432
- Redis on port 6379
- Backend API on port 5000
- Frontend on port 3000
- PgAdmin on port 5050 (optional)
Backend:
cd backend
# Install dependencies
npm install
# Generate Prisma client
npx prisma generate
# Run database migrations
npx prisma migrate dev
# Start development server
npm run devFrontend:
cd frontend
# Install dependencies
npm install
# Start development server
npm run devcd backend
npx prisma migrate devnpx prisma studioAccess at http://localhost:5555
Once the backend is running, access Swagger documentation at:
http://localhost:5000/api-docs
Backend:
cd backend
npm test
npm run test:coverageFrontend:
cd frontend
npm test- User: Customer, Seller, Admin with RBAC
- Product: With variants, images, and inventory
- Category: Hierarchical categories
- Cart: Persistent shopping cart
- Order: Order management with status tracking
- Payment: Stripe integration
- Review: Product reviews and ratings
- Wishlist: User wishlists
- Address: Shipping and billing addresses
- Session: User sessions
- AuditLog: Security audit trail
POST /api/v1/auth/register- Register userPOST /api/v1/auth/login- Login userPOST /api/v1/auth/logout- Logout userPOST /api/v1/auth/refresh- Refresh access tokenPOST /api/v1/auth/verify-email- Verify emailPOST /api/v1/auth/forgot-password- Request password resetPOST /api/v1/auth/reset-password- Reset passwordPOST /api/v1/auth/2fa/setup- Setup 2FAPOST /api/v1/auth/2fa/verify- Verify 2FAGET /api/v1/auth/me- Get current user
GET /api/v1/products- Get all productsGET /api/v1/products/:id- Get product by IDPOST /api/v1/products- Create product (Admin/Seller)PUT /api/v1/products/:id- Update productDELETE /api/v1/products/:id- Delete productGET /api/v1/products/search- Search productsGET /api/v1/products/featured- Get featured products
GET /api/v1/cart- Get user cartPOST /api/v1/cart/items- Add to cartPATCH /api/v1/cart/items/:id- Update cart itemDELETE /api/v1/cart/items/:id- Remove from cart
POST /api/v1/orders- Create orderGET /api/v1/orders- Get user ordersGET /api/v1/orders/:id- Get order by IDPOST /api/v1/orders/:id/cancel- Cancel order
POST /api/v1/payments/create-intent- Create payment intentPOST /api/v1/payments/webhook- Stripe webhookGET /api/v1/payments/order/:orderId- Get payment
- Home page with featured products
- Product listing with filters
- Product detail page
- Shopping cart
- Checkout
- Order history
- User profile
- Admin dashboard
- Responsive navigation
- Product cards
- Shopping cart widget
- Search bar with autocomplete
- Authentication forms
- Payment forms (Stripe Elements)
# Linting
npm run lint
# Type checking
npm run type-check
# Format code
npm run formatBackend:
cd backend
npm run build
npm startFrontend:
cd frontend
npm run build
npm start- Change all default passwords
- Use strong JWT secrets (min 32 characters)
- Enable HTTPS/TLS
- Configure proper CORS origins
- Set up proper firewall rules
- Enable rate limiting
- Set up monitoring and alerts
- Configure backup strategy
- Enable audit logging
- Review and update security headers
- Set secure cookie flags
- Disable debug mode
| Variable | Description | Required | Default |
|---|---|---|---|
| NODE_ENV | Environment mode | No | development |
| PORT | Server port | No | 5000 |
| DATABASE_URL | PostgreSQL connection string | Yes | - |
| JWT_ACCESS_SECRET | JWT access token secret | Yes | - |
| JWT_REFRESH_SECRET | JWT refresh token secret | Yes | - |
| REDIS_URL | Redis connection string | Yes | - |
| STRIPE_SECRET_KEY | Stripe secret key | Yes | - |
See .env.example for full list.
| Variable | Description | Required |
|---|---|---|
| NEXT_PUBLIC_API_URL | Backend API URL | Yes |
| NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY | Stripe publishable key | Yes |
Database connection fails:
- Ensure PostgreSQL is running
- Check DATABASE_URL in .env
- Verify database exists
Redis connection fails:
- Ensure Redis is running
- Check REDIS_URL in .env
JWT errors:
- Ensure JWT secrets are at least 32 characters
- Check token expiration settings
This project is licensed under the MIT License.
Contributions are welcome! Please read the contributing guidelines first.
Built with β€οΈ using modern web technologies