A robust NestJS backend for StellarSwipe, integrating Stellar's blockchain infrastructure with Soroban smart contract support.
src/
├── config/ # Configuration modules
│ ├── stellar.config.ts # Stellar blockchain configuration
│ ├── stellar.service.ts # Stellar configuration service
│ ├── database.config.ts # Database and Redis configuration
│ └── app.config.ts # Application configuration
├── common/ # Shared utilities
│ ├── constants/ # Application constants
│ ├── decorators/ # Custom decorators (IsPublic, RateLimit)
│ ├── filters/ # Global exception filter
│ └── interceptors/ # Logging and transform interceptors
├── main.ts # Application bootstrap
└── app.module.ts # Root module
- Node.js 18+
- npm 9+
- Docker & Docker Compose (optional, for containerized development)
- PostgreSQL (or use Docker)
- Redis (or use Docker)
- Clone the repository:
git clone <repository-url>
cd stellarswipe-backend- Install dependencies:
npm install- Configure environment variables:
cp .env.example .env
# Edit .env with your configurationKey environment variables:
NODE_ENV: development | productionPORT: Server port (default: 3000)HOST: Server host (default: 0.0.0.0)LOG_LEVEL: debug | info | warn | error
DATABASE_HOST: Database hostDATABASE_PORT: Database port (default: 5432)DATABASE_USER: Database userDATABASE_PASSWORD: Database passwordDATABASE_NAME: Database name
REDIS_HOST: Redis hostREDIS_PORT: Redis port (default: 6379)REDIS_PASSWORD: Redis password (optional)
STELLAR_NETWORK: testnet | mainnet (default: testnet)STELLAR_HORIZON_URL: Horizon API URLSTELLAR_SOROBAN_RPC_URL: Soroban RPC endpointSTELLAR_NETWORK_PASSPHRASE: Network passphrase for signingSTELLAR_API_TIMEOUT: API timeout in ms (default: 30000)STELLAR_MAX_RETRIES: Max API retries (default: 3)
CORS_ORIGIN: Comma-separated allowed originsCORS_CREDENTIALS: Enable credentials (default: true)
Start development server:
npm run start:devThe API will be available at http://localhost:3000/api/v1
Start all services:
docker-compose up -dThis starts:
- PostgreSQL: Port 5432
- Redis: Port 6379
- NestJS App: Port 3000
View logs:
docker-compose logs -f appStop services:
docker-compose down# Development
npm run start:dev # Watch mode
npm run start:debug # Debug mode
npm start # Production mode
# Build
npm run build # Compile TypeScript
# Code Quality
npm run lint # Run ESLint
npm run lint:fix # Fix linting issues
npm run format # Format code with Prettier
# Testing
npm test # Run tests
npm run test:watch # Watch mode
npm run test:cov # Coverage report
npm run test:debug # Debug testshttps://horizon-testnet.stellar.org
https://soroban-testnet.stellar.org:443
Testnet (default):
- Network Passphrase:
Test SDF Network ; September 2015 - Horizon:
https://horizon-testnet.stellar.org - Soroban RPC:
https://soroban-testnet.stellar.org:443
Mainnet (when ready):
- Network Passphrase:
Public Global Stellar Network ; September 2015 - Horizon:
https://horizon.stellar.org - Soroban RPC:
https://soroban-mainnet.stellar.org:443
- Global Prefix:
/api/v1 - Exception Filter: Catches all errors and formats responses
- Interceptors: Logging and response transformation
- Validation: Automatic DTO validation
Success response:
{
"success": true,
"data": {
/* response data */
},
"timestamp": "2026-01-19T12:00:00.000Z"
}Error response:
{
"statusCode": 400,
"message": "Error message",
"timestamp": "2026-01-19T12:00:00.000Z",
"path": "/api/v1/endpoint"
}- TypeScript strict mode enabled
- No unused variables allowed
- Prettier integration for automatic formatting
- Semi-colons enabled
- Single quotes
- 80 character line width
- 2-space indentation
Check formatting:
npm run lint
npm run format- Configured with PostgreSQL
- Migrations support
- Automatic synchronization in development
- SSL support for production
Create migration:
npm run typeorm migration:create src/migrations/CreateUsersTableRun migrations:
npm run typeorm migration:run- TypeScript support via
ts-jest - Coverage reporting
Run tests:
npm test
npm run test:watch
npm run test:covnpm run builddocker build -t stellarswipe-backend:latest .
docker run -p 3000:3000 --env-file .env stellarswipe-backend:latest- Set
NODE_ENV=production - Configure all required environment variables
- Use strong database password
- Set Redis password
- Configure CORS appropriately
- Ensure PostgreSQL is running on configured host/port
- Ensure Redis is running and accessible
- Check network connectivity to Stellar endpoints
npm install
npm run build# Change PORT in .env or kill existing process
lsof -i :3000
kill -9 <PID>- Create feature branch:
git checkout -b feature/new-feature - Commit changes:
git commit -am 'Add new feature' - Push to branch:
git push origin feature/new-feature - Submit Pull Request
- @nestjs/common: NestJS core functionality
- @nestjs/config: Environment configuration management
- @stellar/stellar-sdk: Stellar blockchain SDK
- @soroban-js/stellar-sdk: Soroban smart contract SDK
- typeorm: ORM for database operations
- ioredis: Redis client
- class-validator: DTO validation
- typescript: 5.3.3
- @nestjs/cli: NestJS CLI tools
- eslint: Code linting
- prettier: Code formatting
- jest: Testing framework
MIT