Skip to content

bukizz-store/bukizz_node_server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

194 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Bukizz School E-commerce Backend API

A comprehensive Node.js/Express backend API for the Bukizz school supplies e-commerce platform with MySQL/Supabase integration.

πŸš€ Features

  • 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

πŸ“ Project Structure

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

πŸ› οΈ Installation

Prerequisites

  • Node.js 18+
  • MySQL 8.0+ or Supabase account
  • Redis (optional, for caching)

Local Development

  1. Clone and setup:
cd server
cp .env.example .env
# Edit .env with your configuration
  1. Install dependencies:
npm install
  1. Database setup:
# For MySQL, create database and run migrations
npm run db:migrate
npm run db:seed
  1. Start development server:
npm run dev

Docker Development

# Build and run with Docker Compose
docker-compose up --build

# Or run individual services
docker-compose up mysql redis
npm run dev

πŸ”§ Configuration

Environment Variables

Copy .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

Database Options

Option 1: MySQL

DB_HOST=localhost
DB_PORT=3306
DB_NAME=bukizz_db
DB_USER=your_username
DB_PASSWORD=your_password

Option 2: Supabase

SUPABASE_URL=your_supabase_url
SUPABASE_ANON_KEY=your_supabase_anon_key

πŸ“š API Documentation

Base URL

Development: http://localhost:3000/api/v1
Production: https://api.bukizz.com/api/v1

Authentication Endpoints

  • POST /auth/register - Register new user
  • POST /auth/login - User login
  • POST /auth/refresh - Refresh access token
  • POST /auth/logout - User logout
  • GET /auth/me - Get current user profile
  • POST /auth/forgot-password - Request password reset
  • POST /auth/reset-password - Reset password

Product Endpoints

  • GET /products - Search products with filters
  • GET /products/:id - Get product details
  • GET /products/featured - Get featured products
  • GET /products/type/:type - Get products by type
  • GET /products/school/:schoolId - Get school products
  • POST /products - Create product (admin)
  • PUT /products/:id - Update product (admin)

School Endpoints

  • GET /schools - Search schools
  • GET /schools/:id - Get school details
  • GET /schools/city/:city - Get schools by city
  • GET /schools/popular - Get popular schools
  • POST /schools - Create school (admin)
  • PUT /schools/:id - Update school (admin)

Order Endpoints

  • POST /orders - Create new order
  • GET /orders/my-orders - Get user orders
  • GET /orders/:id - Get order details
  • POST /orders/:id/cancel - Cancel order
  • PUT /orders/:id/status - Update order status (admin)
  • POST /orders/calculate-summary - Calculate order summary

User Endpoints

  • GET /users/:userId - Get user profile
  • PUT /users/:userId - Update user profile
  • GET /users/:userId/addresses - Get user addresses
  • POST /users/:userId/addresses - Add user address

πŸ”’ Security Features

  • 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

πŸ§ͺ Testing

# Run all tests
npm test

# Run tests in watch mode
npm run test:watch

# Generate coverage report
npm run test:coverage

πŸ“ Scripts

npm 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

πŸš€ Deployment

Docker Deployment

# Build and deploy
docker build -t bukizz-server .
docker run -p 3000:3000 bukizz-server

Production Considerations

  1. Environment: Set NODE_ENV=production
  2. Database: Use managed database service
  3. Logging: Configure log aggregation
  4. Monitoring: Set up health checks and metrics
  5. SSL: Enable HTTPS in production
  6. Scaling: Use load balancer for multiple instances

πŸ—οΈ Architecture

Layered Architecture

  1. Routes Layer: HTTP routing and middleware
  2. Controllers Layer: Request/response handling
  3. Services Layer: Business logic
  4. Repository Layer: Database access
  5. Database Layer: MySQL/Supabase integration

Design Patterns

  • Dependency Injection: Modular service initialization
  • Repository Pattern: Database abstraction
  • Middleware Pattern: Request processing pipeline
  • Error Handling: Centralized error management

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make changes and add tests
  4. Run linting and tests
  5. Submit a pull request

πŸ“„ License

MIT License - see LICENSE file for details

πŸ†˜ Support

  • Create an issue for bug reports
  • Check existing issues for known problems
  • Contact: support@bukizz.com

About

This is the main bukizz server for all the API's of bukizz.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors