StarShop Backend is a robust and scalable API built with NestJS that provides comprehensive functionality for an e-commerce platform integrated with Stellar blockchain technology. The system includes wallet-based authentication, product management, shopping cart, orders, coupons, real-time notifications, and more.
- Web3 Authentication: Stellar wallet-based authentication system with cryptographic verification
- Product Management: Complete CRUD for products, variants, and product types
- Shopping Cart: Cart management with persistence and validations
- Order System: Complete order processing with status tracking
- Coupons & Discounts: Flexible coupon system with validations
- Real-time Notifications: Pusher integration for push notifications
- File Management: File upload to AWS S3 and Cloudinary
- Review System: Product review management
- Wishlist: Wishlist functionality for users
- Role-Based Access Control: RBAC with buyer, seller, and admin roles
- RESTful API: Well-documented endpoints with OpenAPI/Swagger
- Database: PostgreSQL with TypeORM for ORM
- Testing: Complete coverage with Jest for unit and e2e tests
- Stellar wallet-based authentication
- Cryptographic signature verification
- JWT tokens with HttpOnly cookies
- Role-based access control (RBAC)
- User and profile management
- Complete user CRUD operations
- Profile and personal information management
- Data validation and permissions
- Complete product management
- Categorization and organization
- Advanced search and filtering
- Product categorization
- Type hierarchy and subcategories
- Variant management (size, color, etc.)
- Customizable attributes
- Inventory control per variant
- Dynamic attribute system
- Customizable attribute values
- Association with products and variants
- Shopping cart management
- Item persistence
- Stock and price validations
- Complete order processing
- Order statuses (pending, confirmed, shipped, etc.)
- Purchase history
- Coupon and discount system
- Date and usage validations
- Different discount types
- Wishlist management
- Add/remove products
- List of desired items
- Product review system
- Ratings and comments
- Previous purchase validation
- File upload to AWS S3
- Cloudinary integration
- Image and document management
- Real-time notifications with Pusher
- Different notification types
- Subscription management
- Framework: NestJS (Node.js)
- Language: TypeScript
- Database: PostgreSQL with TypeORM (Supabase ready)
- Authentication: JWT + Stellar SDK
- Storage: AWS S3 + Cloudinary
- Notifications: Pusher
- Testing: Jest + Supertest
- Documentation: OpenAPI/Swagger
- Validation: class-validator + class-transformer
- Rate Limiting: express-rate-limit
- Logging: Winston
- Supabase: Supabase client for authentication, storage and other services
- Node.js (v18 or higher)
- Docker and Docker Compose
- npm or yarn
git clone https://github.com/StarShopCr/StarShop-Backend.git
cd StarShop-Backend
npm install
# Start PostgreSQL database using Docker Compose
docker-compose up -d postgres
This will start a PostgreSQL database with the following default configuration:
- Host: localhost
- Port: 5432
- Username: user
- Password: password
- Database: starshop
Create a .env
file in the root directory:
touch .env
Add the following configuration to your .env
file:
# Database (Docker Compose defaults)
DB_HOST=localhost
DB_PORT=5432
DB_USERNAME=user
DB_PASSWORD=password
DB_DATABASE=starshop
# JWT
JWT_SECRET=your-super-secret-jwt-key-change-this-in-production
JWT_EXPIRATION_TIME=1h
# AWS S3 (Optional - for file uploads)
AWS_ACCESS_KEY_ID=your_access_key
AWS_SECRET_ACCESS_KEY=your_secret_key
AWS_REGION=us-east-1
AWS_S3_BUCKET=your_bucket_name
# Cloudinary (Optional - for image uploads)
CLOUDINARY_CLOUD_NAME=your_cloud_name
CLOUDINARY_API_KEY=your_api_key
CLOUDINARY_API_SECRET=your_api_secret
# Pusher (Optional - for real-time notifications)
PUSHER_APP_ID=your_app_id
PUSHER_KEY=your_key
PUSHER_SECRET=your_secret
PUSHER_CLUSTER=your_cluster
# Application
NODE_ENV=development
PORT=3000
# Run migrations to create database tables
# dist/data-source.js is your file data-source in dist directory
npm run typeorm migration:run -d dist/data-source.js
# or
# dist/data-source.js is your file data-source in dist directory
# The --fake flag tells TypeORM to mark the migration as executed without actually running it.
npm run typeorm migration:run -d dist/data-source.js --fake
Warning
Is important that you have dist file to use migrations
# Development mode with hot reload
npm run dev
# Or start in production mode
npm run build
npm run start:prod
The application will be available at http://localhost:3000
If you prefer to run the entire application with Docker:
# Build the application image
docker build -t starshop-backend .
# Start both database and application
docker-compose up -d
The project includes a docker-compose.yml
file that sets up the PostgreSQL database:
# Start only the database
docker-compose up -d postgres
# Start all services (if you add the app service to docker-compose.yml)
docker-compose up -d
# Stop all services
docker-compose down
# Stop and remove volumes (this will delete all data)
docker-compose down -v
# View database logs
docker-compose logs postgres
# Access database directly
docker exec -it starshop-db psql -U user -d starshop
# Backup database
docker exec starshop-db pg_dump -U user starshop > backup.sql
# Restore database
docker exec -i starshop-db psql -U user -d starshop < backup.sql
# Development
npm run dev # Start in development mode
npm run start:dev # Start with watch mode
npm run start:debug # Start in debug mode
# Production
npm run build # Compile TypeScript
npm run start # Start application
npm run start:prod # Start in production mode
# Testing
npm run test # Run unit tests
npm run test:watch # Tests in watch mode
npm run test:coverage # Tests with coverage
npm run test:e2e # End-to-end tests
# Linting and Formatting
npm run lint # Check linting
npm run lint:fix # Fix linting errors
npm run format # Format code
# Documentation
npm run docs:validate # Validate OpenAPI schema
npm run docs:build # Generate static documentation
- Start the server:
npm run dev
- Visit:
http://localhost:3000/docs
All endpoints follow RESTful patterns and are versioned:
- Prefix:
/api/v1
- Format:
GET /api/v1/resource
- Responses: JSON with consistent structure
{
"success": true,
"data": {
// Response data
},
"message": "Operation successful"
}
{
"success": false,
"message": "Error description",
"error": "Specific error code"
}
-
Generate Challenge:
POST /api/v1/auth/challenge { "walletAddress": "GDRXE2BQUC3AZ6H4YOVGJK2D5SUKZMAWDVSTXWF3SZEUZ6EWERVC7ESE" }
-
Register/Login:
POST /api/v1/auth/register { "walletAddress": "GDRXE2BQUC3AZ6H4YOVGJK2D5SUKZMAWDVSTXWF3SZEUZ6EWERVC7ESE", "signature": "MEUCIQDexample==", "message": "StarShop Authentication Challenge - ...", "name": "John Doe", "email": "john@example.com" }
- buyer: Buyer user (default role)
- seller: Seller with product management permissions
- admin: Administrator with full system access
# Unit tests
npm run test
# Tests with coverage
npm run test:coverage
# End-to-end tests
npm run test:e2e
# Specific tests
npm test -- --testPathPattern=auth
src/modules/
βββ auth/
β βββ tests/
β βββ auth.service.spec.ts
βββ coupons/
β βββ tests/
β βββ coupon.controller.spec.ts
β βββ coupon.service.spec.ts
β βββ coupon.integration.spec.ts
βββ files/
βββ tests/
βββ file.controller.spec.ts
βββ file.service.spec.ts
src/
βββ config/ # Configurations
β βββ database.ts # Database configuration
β βββ index.ts # General configuration
βββ modules/ # Application modules
β βββ auth/ # Authentication and authorization
β βββ users/ # User management
β βββ products/ # Product management
β βββ cart/ # Shopping cart
β βββ orders/ # Order management
β βββ coupons/ # Coupon system
β βββ reviews/ # Review system
β βββ files/ # File management
β βββ notifications/ # Real-time notifications
β βββ shared/ # Shared components
βββ middleware/ # Custom middlewares
βββ utils/ # Utilities and helpers
βββ types/ # TypeScript type definitions
βββ main.ts # Application entry point
# Start database only (recommended for development)
docker-compose up -d postgres
# Build and run application with Docker
docker build -t starshop-backend .
docker run -p 3000:3000 --env-file .env starshop-backend
# Or use Docker Compose for both (if you extend docker-compose.yml)
docker-compose up -d
# Create new migration
npm run typeorm migration:create -- -n CreateNewTable
# Run migrations
npm run typeorm migration:run
# Revert last migration
npm run typeorm migration:revert
# Generate migration from entity changes
npm run typeorm migration:generate -- -n MigrationName
- Start Database:
docker-compose up -d postgres
- Install Dependencies:
npm install
- Setup Environment: Create
.env
file - Run Migrations:
npm run typeorm migration:run
- Start Development Server:
npm run dev
- Access API:
http://localhost:3000
- View Documentation:
http://localhost:3000/docs
- Language: TypeScript
- Formatting: Prettier + ESLint
- Naming:
camelCase
for variables and functionsPascalCase
for classes and interfacesUPPER_SNAKE_CASE
for constantskebab-case
for API routes
Format: [Type] [Scope]: [Description]
Examples:
feat: Add user authentication system
fix: Resolve database connection issue
docs: Update API documentation
test: Add unit tests for auth service
- Create branch from
develop
- Implement changes with tests
- Run linting and tests
- Create PR with detailed description
- Wait for review and approval
# Build application
npm run build
# Start in production
npm run start:prod
NODE_ENV=production
PORT=3000
JWT_SECRET=your-production-secret
DB_HOST=your-production-db-host
# ... other production configurations
- Fork the project
- Create your feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
- Follow established coding standards
- Add tests for new features
- Update documentation when necessary
- Ensure all tests pass before PR
This project is licensed under the ISC License. See the LICENSE
file for details.
For technical support or questions:
- Create an issue on GitHub
- Review documentation in
/docs
- Check tests for usage examples
- Telegram: @Villarley