A comprehensive, enterprise-grade REST API for multi-tenant e-commerce platforms with advanced features including internationalization, content management, and AWS S3 integration.
- Tenant Isolation: Complete data separation between organizations
- Subdomain Routing: Automatic tenant detection via subdomains
- Scalable Design: Support for unlimited tenants with optimized queries
- Admin Panel: Cross-tenant administration and management
- JWT Authentication: Secure token-based authentication
- Role-Based Access Control (RBAC): Granular permission management
- Multi-Factor Authentication: Enhanced security options
- Session Management: Secure refresh token handling
- Multi-language Support: Dynamic language switching
- Content Translation: Database-level translation system
- Locale Management: Automated language detection
- Translation APIs: RESTful endpoints for content management
- Product Management: Complete product lifecycle
- Category Hierarchy: Nested categories with translations
- Inventory Tracking: Real-time stock management
- Price Management: Multi-currency support
- SEO Optimization: Meta tags and URL optimization
- Blog System: Full-featured blog with translations
- Page Management: Dynamic page creation and editing
- Media Library: Integrated file management
- Template System: Customizable content templates
- AWS S3 Integration: Scalable cloud storage
- Local Storage: Development-friendly file handling
- Image Processing: Automatic image optimization
- File Validation: Security-focused upload handling
- RESTful API: Complete REST API with OpenAPI documentation
- Database Migrations: Version-controlled schema management
- Comprehensive Logging: Structured logging with rotation
- Health Checks: Built-in monitoring endpoints
- Error Handling: Standardized error responses
- Rate Limiting: API protection and throttling
| Component | Version | Required |
|---|---|---|
| Node.js | 18.0+ | β Yes |
| npm/yarn | Latest | β Yes |
| PostgreSQL | 15.0+ | β Yes |
| Docker | 20.0+ | π Optional |
| Docker Compose | 2.0+ | π Optional |
# Clone the repository
git clone https://github.com/yourusername/catalog-api.git
cd catalog-api
# Install dependencies
npm installCopy the environment template and configure your settings:
cp .env.example .envImportant Configuration Notes:
DB_HOST: Uselocalhostfor local development,db-postgresfor DockerJWT_SECRET: Generate a secure random string (minimum 32 characters)AWS_S3_*: Configure AWS credentials for file storage
# Start all services
docker-compose up -d
# Check service status
docker-compose ps
# View logs
docker-compose logs -f apiService Access:
- API Server: http://localhost:8000
- Swagger Documentation: http://localhost:8000/api/docs
- pgAdmin: http://localhost:5050 (admin@example.com / admin)
# Start PostgreSQL (ensure it's running locally)
# Update .env with local database settings
# Run database migrations
npm run migration:run
# Seed the database with sample data
npm run seed
# Start the development server
npm run start:devcatalog-api/
βββ src/
β βββ auth/ # Authentication & Authorization
β βββ common/ # Shared utilities & decorators
β βββ database/ # Database configuration & migrations
β βββ modules/ # Feature modules
β β βββ categories/ # Category management
β β βββ products/ # Product management
β β βββ files/ # File upload & management
β β βββ content/ # CMS functionality
β β βββ tenants/ # Multi-tenant management
β β βββ users/ # User management
β βββ i18n/ # Internationalization
β βββ main.ts # Application entry point
βββ migrations/ # Database migrations
βββ seeds/ # Database seed files
βββ docker/ # Docker configuration
βββ docs/ # Project documentation
βββ test/ # Test files
auth/
βββ controllers/ # Auth endpoints
βββ services/ # Business logic
βββ guards/ # Route protection
βββ strategies/ # JWT & local strategies
βββ dto/ # Data transfer objects
modules/
βββ [module-name]/
β βββ entities/ # TypeORM entities
β βββ dto/ # Request/response DTOs
β βββ controllers/ # REST endpoints
β βββ services/ # Business logic
β βββ [module].module.ts # Module configuration
common/
βββ decorators/ # Custom decorators
βββ filters/ # Exception filters
βββ guards/ # Authorization guards
βββ interceptors/ # Request/response interceptors
βββ pipes/ # Validation pipes
βββ utils/ # Helper functions
- Users & Authentication:
users,roles,permissions,refresh_tokens - Multi-tenant:
tenants,tenant_users,tenant_settings - Products:
products,categories,product_categories - Content:
blog_posts,pages,content_blocks - Files:
files,file_uploads - i18n:
languages,translations
Multi-language support is implemented through dedicated translation tables:
categoriesβcategories_translationsproductsβproducts_translationsblog_postsβblog_posts_translationspagesβpages_translations
# Generate a new migration
npm run migration:generate -- -n MigrationName
# Run pending migrations
npm run migration:run
# Revert the last migration
npm run migration:revert
# Show migration status
npm run migration:show# Run all seeders
npm run seed
# Run specific seeder
npm run seed:specific -- --seed=UserSeeder
# Reset database and reseed
npm run seed:refresh-- Every tenant-specific table includes tenant_id
CREATE TABLE products (
id SERIAL PRIMARY KEY,
tenant_id INTEGER NOT NULL REFERENCES tenants(id),
name VARCHAR(255) NOT NULL,
-- ... other fields
CONSTRAINT unique_product_per_tenant UNIQUE(tenant_id, id)
);-- Base entity
CREATE TABLE categories (
id SERIAL PRIMARY KEY,
tenant_id INTEGER NOT NULL,
slug VARCHAR(255) NOT NULL
);
-- Translation table
CREATE TABLE categories_translations (
id SERIAL PRIMARY KEY,
category_id INTEGER REFERENCES categories(id),
language_code VARCHAR(5) NOT NULL,
name VARCHAR(255) NOT NULL,
description TEXT
);-- All entities include audit fields
CREATE TABLE example_entity (
id SERIAL PRIMARY KEY,
created_at TIMESTAMP DEFAULT NOW(),
updated_at TIMESTAMP DEFAULT NOW(),
created_by INTEGER REFERENCES users(id),
updated_by INTEGER REFERENCES users(id)
);- Local Development: http://localhost:8000/api
- Swagger UI: http://localhost:8000/api/docs
POST /api/auth/login # User login
POST /api/auth/register # User registration
POST /api/auth/refresh # Refresh access token
POST /api/auth/logout # User logout
GET /api/auth/profile # Get user profile
PUT /api/auth/profile # Update user profileGET /api/products # List products (with pagination)
POST /api/products # Create new product
GET /api/products/:id # Get product details
PUT /api/products/:id # Update product
DELETE /api/products/:id # Delete product
GET /api/products/:id/translations # Get product translationsGET /api/categories # List categories (hierarchical)
POST /api/categories # Create category
GET /api/categories/:id # Get category details
PUT /api/categories/:id # Update category
DELETE /api/categories/:id # Delete categoryGET /api/blog-posts # List blog posts
POST /api/blog-posts # Create blog post
GET /api/blog-posts/:slug # Get blog post by slug
PUT /api/blog-posts/:id # Update blog post
DELETE /api/blog-posts/:id # Delete blog postPOST /api/files/upload # Upload single file
POST /api/files/upload-multiple # Upload multiple files
GET /api/files/:id # Get file details
DELETE /api/files/:id # Delete fileGET /api/tenants # List tenants (admin only)
POST /api/tenants # Create tenant (admin only)
GET /api/tenants/:id # Get tenant details
PUT /api/tenants/:id # Update tenant settings{
"email": "user@example.com",
"password": "securepassword123",
"tenantSlug": "demo-tenant"
}{
"name": "Premium Widget",
"slug": "premium-widget",
"description": "High-quality widget for professional use",
"price": 99.99,
"categoryIds": [1, 2],
"status": "active",
"translations": {
"en": {
"name": "Premium Widget",
"description": "High-quality widget for professional use"
},
"es": {
"name": "Widget Premium",
"description": "Widget de alta calidad para uso profesional"
}
}
}# Run unit tests
npm run test
# Run integration tests
npm run test:e2e
# Run tests with coverage
npm run test:cov
# Run tests in watch mode
npm run test:watch
# Run specific test file
npm run test -- auth.service.spec.ts# Lint code
npm run lint
# Fix linting issues
npm run lint:fix
# Format code
npm run format
# Type checking
npm run type-check# Build the application
npm run build
# Start production server
npm run start:prod# Build production image
docker build -t catalog-api:latest .
# Run with production environment
docker run -d \
--name catalog-api \
-p 8000:8000 \
--env-file .env.production \
catalog-api:latestNODE_ENV=production
PORT=8000
DB_HOST=your-production-db-host
DB_PORT=5432
DB_USERNAME=your-db-user
DB_PASSWORD=your-secure-password
DB_NAME=your-production-db
JWT_SECRET=your-super-secure-jwt-secret
AWS_ACCESS_KEY_ID=your-aws-key
AWS_SECRET_ACCESS_KEY=your-aws-secret
AWS_S3_BUCKET_NAME=your-s3-bucket# Generate module structure
nest generate module modules/new-feature
nest generate controller modules/new-feature
nest generate service modules/new-feature// entities/new-feature.entity.ts
@Entity('new_features')
export class NewFeature extends BaseEntity {
@Column()
name: string;
@Column()
tenantId: number;
// Add translation support
@OneToMany(() => NewFeatureTranslation, translation => translation.newFeature)
translations: NewFeatureTranslation[];
}npm run migration:generate -- -n CreateNewFeatureTable
npm run migration:run// Add to translation entity
@Entity('new_features_translations')
export class NewFeatureTranslation extends BaseTranslationEntity {
@ManyToOne(() => NewFeature, feature => feature.translations)
newFeature: NewFeature;
@Column()
name: string;
@Column('text', { nullable: true })
description: string;
}# Create feature branch
git checkout -b feature/new-feature-name
# Make changes and commit
git add .
git commit -m "feat: add new feature functionality"
# Push and create pull request
git push origin feature/new-feature-name
# After review, merge to main
git checkout main
git pull origin main
git merge feature/new-feature-name- Use strict TypeScript configurations
- Implement proper type definitions for all entities
- Utilize decorators for validation and transformation
- Follow naming conventions (PascalCase for classes, camelCase for variables)
- RESTful resource naming
- Consistent HTTP status codes
- Proper error handling and messaging
- Comprehensive request/response validation
- OpenAPI documentation for all endpoints
- Use migrations for schema changes
- Implement proper indexing strategies
- Follow naming conventions (snake_case for tables/columns)
- Ensure data integrity with constraints
- Implement soft deletes where appropriate
- π Installation Guide - Detailed setup instructions
- π§ Configuration Guide - Environment setup
- ποΈ Architecture Guide - System design details
- π API Reference - Complete API documentation
- π§ͺ Testing Guide - Testing strategies and examples
- π Deployment Guide - Production deployment
- π€ Contributing Guide - Development guidelines
- π Issues: Create an issue on GitHub
- π¬ Discussions: GitHub Discussions
- π§ Email: support@yourcompany.com
- π Releases: GitHub Releases
- π Roadmap: Project Roadmap
- π― Milestones: Development Milestones
- RAM: 4GB minimum, 8GB recommended
- Storage: 10GB available space
- CPU: 2 cores minimum, 4+ cores recommended
- Network: High-speed internet for cloud services
# Install required global packages
npm install -g @nestjs/cli
npm install -g typescript
npm install -g ts-node
# Verify installations
node --version # Should be 18.0+
npm --version # Should be latest
nest --version # Should be 10.0+This project is licensed under the MIT License - see the LICENSE file for details.
We welcome contributions! Please see our Contributing Guide for details on:
- Code of Conduct
- Development setup
- Pull request process
- Coding standards
- Testing requirements
- NestJS Team - For the incredible framework
- TypeORM Team - For the robust ORM solution
- PostgreSQL Community - For the reliable database system
- Contributors - Thank you to all who have contributed to this project
Built with β€οΈ using NestJS, TypeScript, and PostgreSQL