A comprehensive Node.js/Express backend API for the Bukizz school supplies e-commerce platform with MySQL/Supabase integration.
- Authentication & Authorization: JWT-based auth with role-based access control
- User Management: Registration, profile management, address management
- Product Catalog: Product management with categories, variants, and school associations
- School Management: School profiles with product associations by grade
- Order Management: Complete order lifecycle management
- Security: Rate limiting, input validation, security middleware
- Database: MySQL with Supabase support
- Logging: Structured logging with Winston
- Testing: Jest test framework setup
- Docker: Containerized deployment ready
server/
βββ src/
β βββ config/ # Configuration files
β βββ controllers/ # Request handlers
β βββ services/ # Business logic
β βββ repositories/ # Database access layer
β βββ models/ # Validation schemas
β βββ middleware/ # Express middleware
β βββ utils/ # Utility functions
β βββ routes/ # Route definitions
β βββ db/ # Database connection
βββ tests/ # Test files
βββ .env.example # Environment template
βββ package.json # Dependencies and scripts
βββ Dockerfile # Docker configuration
βββ docker-compose.yml # Multi-service setup
βββ README.md # Documentation
- Node.js 18+
- MySQL 8.0+ or Supabase account
- Redis (optional, for caching)
- Clone and setup:
cd server
cp .env.example .env
# Edit .env with your configuration- Install dependencies:
npm install- Database setup:
# For MySQL, create database and run migrations
npm run db:migrate
npm run db:seed- Start development server:
npm run dev# Build and run with Docker Compose
docker-compose up --build
# Or run individual services
docker-compose up mysql redis
npm run devCopy .env.example to .env and configure:
- Database: MySQL or Supabase credentials
- JWT: Secret keys and expiration times
- Security: CORS origins, rate limits
- External: Payment gateway, email service
Option 1: MySQL
DB_HOST=localhost
DB_PORT=3306
DB_NAME=bukizz_db
DB_USER=your_username
DB_PASSWORD=your_passwordOption 2: Supabase
SUPABASE_URL=your_supabase_url
SUPABASE_ANON_KEY=your_supabase_anon_keyDevelopment: http://localhost:3000/api/v1
Production: https://api.bukizz.com/api/v1
POST /auth/register- Register new userPOST /auth/login- User loginPOST /auth/refresh- Refresh access tokenPOST /auth/logout- User logoutGET /auth/me- Get current user profilePOST /auth/forgot-password- Request password resetPOST /auth/reset-password- Reset password
GET /products- Search products with filtersGET /products/:id- Get product detailsGET /products/featured- Get featured productsGET /products/type/:type- Get products by typeGET /products/school/:schoolId- Get school productsPOST /products- Create product (admin)PUT /products/:id- Update product (admin)
GET /schools- Search schoolsGET /schools/:id- Get school detailsGET /schools/city/:city- Get schools by cityGET /schools/popular- Get popular schoolsPOST /schools- Create school (admin)PUT /schools/:id- Update school (admin)
POST /orders- Create new orderGET /orders/my-orders- Get user ordersGET /orders/:id- Get order detailsPOST /orders/:id/cancel- Cancel orderPUT /orders/:id/status- Update order status (admin)POST /orders/calculate-summary- Calculate order summary
GET /users/:userId- Get user profilePUT /users/:userId- Update user profileGET /users/:userId/addresses- Get user addressesPOST /users/:userId/addresses- Add user address
- JWT Authentication: Secure token-based authentication
- Rate Limiting: Configurable rate limits per endpoint
- Input Validation: Joi schema validation for all inputs
- SQL Injection Protection: Parameterized queries
- CORS Configuration: Configurable cross-origin requests
- Security Headers: Helmet.js security middleware
- Password Hashing: bcryptjs for secure password storage
# Run all tests
npm test
# Run tests in watch mode
npm run test:watch
# Generate coverage report
npm run test:coveragenpm start # Start production server
npm run dev # Start development server with nodemon
npm test # Run tests
npm run lint # Run ESLint
npm run docker:build # Build Docker image
npm run docker:run # Run Docker container# Build and deploy
docker build -t bukizz-server .
docker run -p 3000:3000 bukizz-server- Environment: Set
NODE_ENV=production - Database: Use managed database service
- Logging: Configure log aggregation
- Monitoring: Set up health checks and metrics
- SSL: Enable HTTPS in production
- Scaling: Use load balancer for multiple instances
- Routes Layer: HTTP routing and middleware
- Controllers Layer: Request/response handling
- Services Layer: Business logic
- Repository Layer: Database access
- Database Layer: MySQL/Supabase integration
- Dependency Injection: Modular service initialization
- Repository Pattern: Database abstraction
- Middleware Pattern: Request processing pipeline
- Error Handling: Centralized error management
- Fork the repository
- Create a feature branch
- Make changes and add tests
- Run linting and tests
- Submit a pull request
MIT License - see LICENSE file for details
- Create an issue for bug reports
- Check existing issues for known problems
- Contact: support@bukizz.com