This guide provides detailed steps for setting up the StellarSplit backend for local development.
- Node.js: v18+ (v20+ recommended)
- Download: https://nodejs.org/
- Verify:
node --versionshould show v18 or higher
- npm: Comes with Node.js
- Verify:
npm --version
- Verify:
- Docker & Docker Compose: For running PostgreSQL and Redis
- Download: https://www.docker.com/products/docker-desktop
- Verify:
docker --versionanddocker-compose --version
- Git: For version control
- Verify:
git --version
- Verify:
For experienced developers, here's the fastest way to get started:
# Clone and navigate
git clone https://github.com/patrickNwafo/StellarSplit.git
cd StellarSplit/backend
# Install dependencies
npm install
# Setup environment
cp .env.example .env
# Edit .env with your configuration
# Start infrastructure
cd ..
docker-compose up -d postgres redis
cd backend
# Run migrations
npm run migration:run
# Start development server
npm run start:devThe API will be available at http://localhost:3000
git clone https://github.com/patrickNwafo/StellarSplit.git
cd StellarSplit/backendnpm installThis installs all dependencies defined in package.json including:
- NestJS framework
- TypeORM for database operations
- Stellar SDK for blockchain integration
- Other required packages
Copy the example environment file:
cp .env.example .envEdit .env with your configuration. Required variables:
# Application Configuration
NODE_ENV=development
PORT=3000
# Database Configuration
DB_HOST=localhost
DB_PORT=5432
DB_USERNAME=postgres
DB_PASSWORD=postgres
DB_NAME=stellarsplit_dev
DB_SYNCHRONIZE=true
DB_LOGGING=true
# Redis Configuration
REDIS_HOST=localhost
REDIS_PORT=6379
# JWT Authentication
JWT_SECRET=change-me-in-production
# Stellar Blockchain Configuration
STELLAR_NETWORK=testnet
# Email Configuration (optional, for notifications)
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.0The backend requires PostgreSQL and Redis. Use Docker Compose:
cd ..
docker-compose up -d postgres redisVerify services are running:
docker psYou should see postgres and redis containers running.
Run database migrations:
cd backend
npm run migration:runThis will create all necessary tables and relationships.
npm run start:devThe server will start with hot-reload enabled. You should see:
[Nest] 12345 - [NestFactory] Starting Nest application...
[InstanceLoader] AppModule dependencies initialized +123ms
[InstanceLoader] AuthModule dependencies initialized +45ms
...
Application is running on: http://localhost:3000
Visit the following URLs to verify:
- API Root: http://localhost:3000
- Swagger Documentation: http://localhost:3000/api
- Health Check: http://localhost:3000/health (if available)
# Run all unit tests
npm run test
# Run tests in watch mode
npm run test:watch
# Run tests with coverage
npm run test:coverage# Run ESLint
npm run lint
# Auto-fix linting issues
npm run lint -- --fix# Build the project
npm run build
# The compiled files will be in the dist/ directory# Generate a new migration
npm run migration:generate -- -d src/database/data-source.ts -- -n MigrationName
# Run pending migrations
npm run migration:run
# Revert the last migration
npm run migration:revertIf you get an error that port 3000 is already in use:
# Find and kill the process
lsof -ti:3000 | xargs kill -9
# Or use a different port by setting PORT in .env
PORT=3001 npm run start:devIf you can't connect to PostgreSQL:
- Check Docker containers:
docker ps- Check PostgreSQL logs:
docker logs postgres- Verify DATABASE_URL in .env matches Docker configuration:
# Should match docker-compose.yml postgres configuration
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/stellarsplit- Restart PostgreSQL container:
docker-compose restart postgresIf Redis connection fails:
- Check Redis container:
docker ps- Check Redis logs:
docker logs redis- Test Redis connection:
docker exec -it redis redis-cli ping
# Should return: PONGIf migrations fail:
- Check migration file syntax
- Ensure database is accessible
- Try reverting and re-running:
npm run migration:revert
npm run migration:runIf TypeORM can't connect:
- Verify DATABASE_URL format:
postgresql://username:password@host:port/database
- Check if database exists:
docker exec -it postgres psql -U postgres -c "\l"- Create database if needed:
docker exec -it postgres psql -U postgres -c "CREATE DATABASE stellarsplit;"Recommended extensions:
- ESLint
- Prettier
- TypeScript
- NestJS Snippets
Create .vscode/settings.json:
{
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"typescript.tsdk": "node_modules/typescript/lib"
}| Command | Description |
|---|---|
npm run start:dev |
Start dev server with hot reload |
npm run dev:watch |
Start with nodemon |
npm run build |
Build for production |
npm run lint |
Check code quality |
npm run test |
Run unit tests |
npm run test:watch |
Run tests in watch mode |
npm run test:coverage |
Generate coverage report |
npm run migration:generate |
Create new migration |
npm run migration:run |
Apply migrations |
npm run migration:revert |
Revert last migration |
After completing setup:
- Read the Developer Guide for coding standards
- Review the Architecture Documentation
- Explore the module structure in
src/ - Check out the API Documentation after starting the server
If you encounter issues:
- Check the Troubleshooting section above
- Review the main README
- Check existing GitHub Issues
- Ask in the project discussions
Happy coding! 🚀