A decentralized multi-vendor e-commerce marketplace backend built with NestJS and Stellar blockchain integration.
Kosmos API is the backend service powering KosmosShop, a trustless, transparent marketplace where sellers can launch shops and buyers enjoy secure transactions via Stellar blockchain.
- Multi-Vendor Marketplace - Sellers can create and manage multiple shops
- Stellar Integration - Native blockchain payments with XLM and stablecoins
- Smart Escrow - Soroban smart contracts secure all transactions
- Order Management - Full order lifecycle from creation to fulfillment
- Review System - Immutable, transparent product and seller reviews
- Dispute Resolution - Built-in arbitration for buyer protection
- Real-time Updates - WebSocket support for live order tracking
- Multi-token Support - Accept payments in XLM, USDC, and other Stellar assets
- Analytics - Seller dashboards with sales metrics and insights
- Role-Based Access - Different permissions for buyers, sellers, and admins
- Framework: NestJS (Node.js)
- Language: TypeScript
- Database: PostgreSQL with TypeORM
- Blockchain: Stellar SDK + Soroban Smart Contracts
- Storage: IPFS (Pinata/Estuary)
- Caching: Redis
- Real-time: Socket.io
- Authentication: JWT + Stellar Wallet
- API Docs: Swagger/OpenAPI
- Testing: Jest + Supertest
- Containerization: Docker
- Node.js >= 18.0.0
- npm >= 9.0.0 or yarn
- PostgreSQL >= 14
- Redis >= 6.0
- Docker & Docker Compose (optional, for local development)
- Stellar testnet account
- IPFS pinning service account (Pinata/Estuary)
git clone https://github.com/yourusername/kosmos-api.git
cd kosmos-apicp .env.example .envEdit .env with your configuration:
# Application
NODE_ENV=development
PORT=3000
API_URL=http://localhost:3000
# Database
DATABASE_HOST=localhost
DATABASE_PORT=5432
DATABASE_USER=postgres
DATABASE_PASSWORD=your_password
DATABASE_NAME=kosmos_db
# Redis
REDIS_HOST=localhost
REDIS_PORT=6379
# JWT
JWT_SECRET=your_super_secret_key
JWT_EXPIRATION=7d
# Stellar
STELLAR_NETWORK=testnet
STELLAR_HORIZON_URL=https://horizon-testnet.stellar.org
STELLAR_CONTRACT_ID=your_contract_id
# IPFS
IPFS_PINATA_API_KEY=your_pinata_api_key
IPFS_PINATA_API_SECRET=your_pinata_api_secret
# Admin Wallet
ADMIN_WALLET_ADDRESS=your_admin_wallet_address
ADMIN_WALLET_SECRET=your_admin_wallet_secretnpm installnpx typeorm migration:generate -n InitialMigration
npx typeorm migration:run
npm run seednpm run start:devServer runs at http://localhost:3000
API documentation at http://localhost:3000/api/docs
docker-compose up -dThis starts:
- NestJS API on port 3000
- PostgreSQL on port 5432
- Redis on port 6379
# View logs
docker-compose logs -f api
# Stop services
docker-compose downsrc/
βββ auth/ # Authentication & JWT
βββ users/ # User profiles & KYC
βββ shops/ # Shop management
βββ products/ # Product listings
βββ orders/ # Order processing
βββ payments/ # Payment handling
βββ escrow/ # Escrow smart contract
βββ reviews/ # Reviews & ratings
βββ disputes/ # Dispute resolution
βββ stellar/ # Stellar blockchain integration
βββ storage/ # IPFS integration
βββ websocket/ # Real-time updates
βββ common/ # Decorators, guards, pipes
βββ app.module.ts # Root module
βββ main.ts # Entry point
The API uses Stellar wallet-based authentication:
- Request Challenge - User requests a challenge to sign
- Sign Challenge - User signs the challenge with their wallet
- Verify Signature - Backend verifies the signature and issues JWT
- Get Token - Returns access and refresh tokens
- Use Token - Include JWT in Authorization header for all requests
Authentication endpoints handle wallet validation and token management.
POST /auth/request-challenge- Get challenge to signPOST /auth/verify-signature- Verify wallet signaturePOST /auth/refresh-token- Refresh access token
GET /users/profile- Get current userPUT /users/profile- Update profileGET /users/:userId- Get public profile
POST /shops- Create shopGET /shops- List shops with filtersGET /shops/:shopId- Get shop detailsPUT /shops/:shopId- Update shopDELETE /shops/:shopId- Delete shopGET /shops/:shopId/analytics- Shop analyticsPOST /shops/:shopId/follow- Follow shop
POST /products- Create productGET /products- List products (search, filter)GET /products/:productId- Get product detailsPUT /products/:productId- Update productDELETE /products/:productId- Delete productPUT /products/:productId/inventory- Update stock
POST /orders- Create orderGET /orders- List user ordersGET /orders/:orderId- Get order detailsPUT /orders/:orderId/status- Update statusPOST /orders/:orderId/confirm-delivery- Confirm delivery
GET /payments/:orderId- Get payment infoPOST /payments/webhook/stellar- Stellar webhook
GET /escrow/:orderId- Get escrow detailsPOST /escrow/:orderId/release- Release fundsPOST /escrow/:orderId/refund- Refund buyer
POST /reviews- Create reviewGET /products/:productId/reviews- Get reviewsPUT /reviews/:reviewId- Update reviewDELETE /reviews/:reviewId- Delete review
POST /disputes- Create disputeGET /disputes- List disputesGET /disputes/:disputeId- Get dispute detailsPOST /disputes/:disputeId/evidence- Submit evidencePOST /disputes/:disputeId/resolve- Resolve dispute
# Run all tests
npm run test
# Run specific test file
npm run test src/auth/auth.service.spec.ts
# Watch mode
npm run test:watch
# Coverage
npm run test:cov
# E2E tests
npm run test:e2enpm run buildnpm run start:prodThe API connects to Stellar blockchain for:
- Smart contract interaction via Soroban
- Payment processing and verification
- Transaction building and submission
- Wallet balance checking
- Event listening for blockchain updates
Real-time updates are sent via Socket.io for:
- Order creation and status changes
- Payment confirmations
- Dispute notifications
- Review submissions
- New messages
- Input Validation - All DTOs validated using class-validator
- Rate Limiting - API endpoints protected against abuse
- JWT Expiration - Short-lived access tokens for security
- CORS - Restricted to authorized frontend domains
- SQL Injection Prevention - Using parameterized queries via TypeORM
- Helmet - Security headers on all responses
- Environment Variables - Sensitive data never committed to version control
# Generate migration
npm run typeorm migration:generate -- -n MigrationName
# Run migrations
npm run typeorm migration:run
# Revert last migration
npm run typeorm migration:revertDEBUG=kosmos:*# Production logs
npm run start:prod | grep "error\|warn"
# Docker logs
docker-compose logs -f api- Create feature branch:
git checkout -b feature/amazing-feature - Commit changes:
git commit -m 'Add amazing feature' - Push to branch:
git push origin feature/amazing-feature - Open Pull Request
MIT License - see LICENSE file for details
For issues and questions:
- Open GitHub issue
- Check existing documentation