A modern, high-performance e-commerce backend platform built with Go, designed for scalability, reliability, and maintainability. This platform provides a comprehensive API for managing users, products, shopping carts, orders, payments, and notifications.
- User Management: Registration, authentication, and profile management
- Product Catalog: Full CRUD operations for product management
- Shopping Cart: Add, update, and manage cart items
- Order Processing: Complete order lifecycle management
- Payment Integration: Stripe payment processing with webhook support
- Notification System: Email notifications via SendGrid
- RESTful API: Well-documented API endpoints with Swagger/OpenAPI
- JWT Authentication: Secure token-based authentication
- Database Integration: PostgreSQL with optimized queries
- Redis Caching: High-performance caching layer
- Rate Limiting: Built-in request rate limiting
- Health Checks: Comprehensive health monitoring endpoints
- Observability: OpenTelemetry integration for tracing and metrics
- Docker Support: Containerized deployment ready
- Cross-Platform Builds: Support for Linux, macOS, and Windows
- Prerequisites
- Installation
- Configuration
- Running the Application
- API Documentation
- Development
- Testing
- Deployment
- Contributing
- License
- Go: Version 1.22 or higher
- PostgreSQL: Version 12 or higher
- Redis: Version 6 or higher
- Docker (optional): For containerized deployment
- Make: For using the provided Makefile commands
git clone https://github.com/aaravmahajanofficial/Scalable-Ecommerce-Platform.git
cd Scalable-Ecommerce-Platformmake depsmake tools-installCreate a configuration file or set the following environment variables:
# Application Environment
ENV=development
# Database Configuration
PG_HOST=localhost
PG_PORT=5432
PG_USER=your_db_user
PG_PASSWORD=your_db_password
PG_DBNAME=ecommerce_db
PG_SSLMODE=disable
# Redis Configuration
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_USER=your_redis_user
REDIS_PASSWORD=your_redis_password
# Security
JWT_KEY=your_super_secret_jwt_key
JWT_EXPIRY_HOURS=24
# Stripe Configuration
STRIPE_API_KEY=sk_test_your_stripe_secret_key
STRIPE_WEBHOOK_SECRET=whsec_your_webhook_secret
STRIPE_SUPPORTED_CURRENCIES=inr,usd,eur
# SendGrid Configuration
API_KEY=your_sendgrid_api_key
[email protected]
FROM_NAME=Your Company Name
SMSENABLED=false# HTTP Server Configuration
HTTP_ADDRESS=:8085
HTTP_READ_TIMEOUT=30s
HTTP_WRITE_TIMEOUT=30s
HTTP_IDLE_TIMEOUT=120s
# OpenTelemetry Configuration
OTEL_SERVICE_NAME=scalable-ecommerce-platform
OTEL_EXPORTER_ENDPOINT=http://localhost:4318/v1/traces
OTEL_TRACES_SAMPLER_ARG=1.0
# Cache Configuration
CACHE_DEFAULT_TTL=5m
# Rate Limiting
RATE_LIMIT_REQUESTS=100
RATE_LIMIT_WINDOW=1mAlternatively, create a YAML configuration file (e.g., config/local.yaml):
env: development
http_server:
ADDRESS: ":8085"
READ_TIMEOUT: 30s
WRITE_TIMEOUT: 30s
IDLE_TIMEOUT: 120s
SHUTDOWN_TIMEOUT: 30s
GRACEFUL_SHUTDOWN_TIMEOUT: 5s
database:
PG_HOST: localhost
PG_PORT: "5432"
PG_USER: your_db_user
PG_PASSWORD: your_db_password
PG_DBNAME: ecommerce_db
PG_SSLMODE: disable
redis:
REDIS_HOST: localhost
REDIS_PORT: "6379"
REDIS_USER: your_redis_user
REDIS_PASSWORD: your_redis_password
security:
JWT_KEY: your_super_secret_jwt_key
JWT_EXPIRY_HOURS: 24
stripe:
API_KEY: sk_test_your_stripe_secret_key
WEBHOOK_SECRET: whsec_your_webhook_secret
SUPPORTED_CURRENCIES: ["inr", "usd", "eur"]
sendgrid:
API_KEY: your_sendgrid_api_key
FROM_EMAIL: [email protected]
FROM_NAME: Your Company Name
SMSENABLED: false
otel:
SERVICE_NAME: scalable-ecommerce-platform
EXPORTER_ENDPOINT: http://localhost:4318/v1/traces
SAMPLER_RATIO: 1.0
cache:
default_ttl: 5m- Start dependencies (PostgreSQL and Redis)
- Run the application:
# Using Make
make run
# Or directly with Go
go run ./cmd/scalable-ecommerce-platform --config config/local.yaml# Build and run with Docker
make docker-build
make docker-run
# Or using docker-compose (if available)
docker-compose up# View all available commands
make help
# Common commands
make build # Build the application
make test # Run tests
make test-coverage # Generate test coverage report
make lint # Run linter
make fmt # Format code
make docs # Generate API documentation
make clean # Clean build artifactsOnce the application is running, access the interactive API documentation at:
http://localhost:8085/swagger/index.html
- Liveness:
GET /livez- Check if the application is alive - Readiness:
GET /readyz- Check if the application is ready to serve traffic
POST /api/v1/users/register- Register a new userPOST /api/v1/users/login- User loginGET /api/v1/users/profile- Get user profile (authenticated)
POST /api/v1/products- Create a new product (authenticated)GET /api/v1/products/{id}- Get product by ID (authenticated)GET /api/v1/products- List products with pagination (authenticated)PUT /api/v1/products/{id}- Update product (authenticated)DELETE /api/v1/products/{id}- Delete product (authenticated)
POST /api/v1/carts- Add item to cart (authenticated)GET /api/v1/carts- Get user's cart (authenticated)PUT /api/v1/carts/{id}- Update cart item (authenticated)DELETE /api/v1/carts/{id}- Remove item from cart (authenticated)
POST /api/v1/orders- Create a new order (authenticated)GET /api/v1/orders/{id}- Get order by ID (authenticated)GET /api/v1/orders- List user's orders (authenticated)
POST /api/v1/payments/process- Process payment (authenticated)POST /api/v1/payments/webhook- Stripe webhook endpoint
βββ cmd/
β βββ scalable-ecommerce-platform/ # Application entry point
βββ internal/
β βββ api/
β β βββ handlers/ # HTTP handlers
β β βββ middleware/ # HTTP middleware
β βββ cache/ # Caching layer
β βββ config/ # Configuration management
β βββ errors/ # Error definitions
β βββ health/ # Health check handlers
β βββ metrics/ # Metrics collection
β βββ models/ # Data models
β βββ repositories/ # Data access layer
β βββ services/ # Business logic
β βββ utils/ # Utility functions
βββ pkg/
β βββ sendgrid/ # SendGrid integration
β βββ stripe/ # Stripe integration
βββ docs/ # API documentation
βββ prometheus/ # Prometheus configuration
Generate mocks and other generated code:
make generate
make mock# Format code
make fmt
# Run linter
make lint
# Run go vet
make vetDatabase schema is managed through the application. The database tables will be created automatically when the application starts if they don't exist.
# Run all tests
make test
# Run tests with coverage
make test-coverage
# Run integration tests
make test-integration
# Run benchmarks
make benchmarkThe project maintains high test coverage across all modules:
- Handlers: ~97.6%
- Services: ~96.2%
- Cache: 100%
- Repositories: ~81.9%
- Build the Docker image:
make docker-build- Run the container:
make docker-run- Push to registry:
make docker-pushFor production deployments:
- Use environment variables for sensitive configuration
- Enable SSL/TLS termination
- Configure proper logging levels
- Set up monitoring and alerting
- Use a reverse proxy (nginx, HAProxy)
- Configure database connection pooling
- Set up Redis clustering for high availability
# Build for different platforms
make build-linux # Linux
make build-mac # macOS
make build-windows # Windows
make build-all # All platforms- JWT Authentication: Secure token-based authentication
- Input Validation: Comprehensive input validation using go-playground/validator
- SQL Injection Protection: Parameterized queries with sqlx
- XSS Protection: HTML sanitization with bluemonday
- Rate Limiting: Built-in request rate limiting
- CORS Support: Configurable CORS policies
- Keep dependencies updated
- Use HTTPS in production
- Rotate JWT secrets regularly
- Monitor for security vulnerabilities
- Implement proper logging and monitoring
- Use environment variables for secrets
The application exposes Prometheus metrics at /metrics endpoint, including:
- HTTP request duration and count
- Database connection metrics
- Redis connection metrics
- Custom business metrics
OpenTelemetry integration provides distributed tracing:
- HTTP request tracing
- Database query tracing
- External service call tracing
Structured logging using Go's slog package with different log levels and contextual information.
We welcome contributions! Please follow these guidelines:
- Fork the repository
- Create a feature branch:
git checkout -b feature/your-feature-name - Make your changes
- Run tests:
make test - Run linters:
make lint - Commit your changes:
git commit -am 'Add some feature' - Push to the branch:
git push origin feature/your-feature-name - Create a Pull Request
- Follow Go conventions and best practices
- Write comprehensive tests for new features
- Update documentation as needed
- Use meaningful commit messages
- Ensure all CI checks pass
Please use the GitHub issue tracker to report bugs or request features. Include:
- Detailed description of the issue
- Steps to reproduce
- Expected vs actual behavior
- Environment details
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
- Author: Aarav Mahajan
- Email: [email protected]
- GitHub: @aaravmahajanofficial
- Built with Go
- Uses Stripe for payment processing
- Uses SendGrid for email notifications
- API documentation with Swagger
- Observability with OpenTelemetry
Happy Coding! π