Welcome to the StellarSplit backend 🚀
This guide helps new developers set up and contribute to the NestJS backend service.
- Node.js v18+ (v20+ recommended)
- npm (comes with Node.js)
- Docker & Docker Compose
- PostgreSQL 14+
- Redis 7+
- Stellar Testnet account (for blockchain integration)
The backend is a standalone NestJS package (not a monorepo):
backend/
├── src/ # Source code
│ ├── analytics/ # Analytics module
│ ├── auth/ # Authentication module
│ ├── batch/ # Background jobs (Bull)
│ ├── common/ # Shared utilities
│ ├── compliance/ # Compliance features
│ ├── config/ # Configuration
│ ├── database/ # Database configuration
│ ├── email/ # Email service
│ ├── entities/ # Database entities
│ ├── export/ # Export functionality
│ ├── fraud-detection/ # ML fraud detection
│ ├── modules/ # Core modules (splits, items, etc.)
│ ├── ocr/ # OCR receipt processing
│ ├── payments/ # Stellar payments
│ ├── receipts/ # Receipt management
│ ├── realtime-analytics/ # Real-time analytics
│ ├── webhooks/ # Webhook handling
│ ├── app.module.ts # Root module
│ └── main.ts # Application entry point
├── test/ # E2E tests
├── docs/ # Additional documentation
├── scripts/ # Utility scripts
├── package.json # Dependencies & scripts
├── tsconfig.json # TypeScript config
└── jest.config.js # Jest test config
git clone https://github.com/patrickNwafo/StellarSplit.git
cd StellarSplit/backendnpm installCopy the example environment file and configure:
cp .env.example .envRequired environment variables:
# Application
NODE_ENV=development
PORT=3000
# Database
DB_HOST=localhost
DB_PORT=5432
DB_USERNAME=postgres
DB_PASSWORD=postgres
DB_NAME=stellarsplit_dev
DB_SYNCHRONIZE=true
DB_LOGGING=true
# Redis
REDIS_HOST=localhost
REDIS_PORT=6379
# JWT
JWT_SECRET=change-me
# Stellar
STELLAR_NETWORK=testnet
# Email (optional)
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USER=
MAIL_PASS=
# API Documentation
SWAGGER_PATH=/api/docs
SWAGGER_TITLE=StellarSplit API
SWAGGER_DESCRIPTION=API for StellarSplit - Split bills instantly with crypto
SWAGGER_VERSION=1.0.0Using Docker Compose:
cd ..
docker-compose up -d postgres redisThis starts PostgreSQL and Redis containers.
cd backend
npm run migration:runnpm run start:devThe API will be available at http://localhost:3000
| Command | Description |
|---|---|
npm run start |
Start production server |
npm run start:dev |
Start development server with hot reload |
npm run build |
Build for production |
npm run lint |
Run ESLint |
npm run dev |
Run with ts-node (no watch) |
npm run dev:watch |
Run with nodemon |
npm run test |
Run unit tests |
npm run test:watch |
Run tests in watch mode |
npm run test:coverage |
Run tests with coverage |
npm run migration:generate |
Generate TypeORM migration |
npm run migration:run |
Run pending migrations |
- TypeScript: Strict mode enabled
- Module Structure: Feature-based (each module has controller, service, entities, DTOs)
- Validation: All DTOs use
class-validatordecorators - Separation of Concerns: No business logic in controllers
- Service Layer: All external calls (Stellar, database, APIs) go through services
- Error Handling: Use NestJS built-in exceptions with proper HTTP status codes
- Logging: Use NestJS Logger service
Each module follows this pattern:
module-name/
├── module-name.module.ts # Module definition
├── module-name.controller.ts # HTTP endpoints
├── module-name.service.ts # Business logic
├── dto/ # Data transfer objects
│ ├── create-*.dto.ts
│ ├── update-*.dto.ts
│ └── *.response.dto.ts
├── entities/ # Database entities (if applicable)
└── *.spec.ts # Unit tests
- Create module directory in
src/ - Generate module files:
nest g module module-name
nest g controller module-name
nest g service module-name- Add DTOs in
dto/folder with validation decorators - Add entities (if needed) in
entities/folder - Register module in
src/app.module.ts - Add tests for controller and service
- Create feature branch from
main - Use conventional commits:
feat:,fix:,docs:,refactor:,test: - Keep PRs focused on a single feature/fix
- Ensure all tests pass before PR
- Update documentation for any API changes
npm run testnpm run test -- test/npm run test:coverage- Use
@stellar/stellar-sdkfor blockchain operations - Always validate transaction hash before updating database
- Confirm transaction success (not just submission)
- Handle network timeouts gracefully with retries
- Use testnet for development, mainnet for production
- Never store private keys in code - use environment variables
- Use TypeORM for all database operations
- Use transactions for multi-step operations
- Add indexes for frequently queried fields
- Use soft deletes where appropriate
- Always validate input before database operations
API documentation is auto-generated using Swagger:
npm run start:dev
# Visit http://localhost:3000/apiPort already in use:
# Kill process on port 3000
lsof -ti:3000 | xargs kill -9Database connection failed:
- Check PostgreSQL is running:
docker ps - Verify DATABASE_URL in .env
- Check database exists
Migration failed:
- Rollback:
npm run migration:revert - Check migration file for syntax errors
- Ensure database is up to date
- NestJS Documentation
- TypeORM Documentation
- Stellar Developer Documentation
- Stellar SDK
- Project README
StellarSplit aims to remove awkward money conversations by making crypto bill splitting instant and seamless using the Stellar blockchain.
Welcome to the team 💫