This guide will help you set up the PropChain Backend development environment from scratch.
Before you begin, ensure you have the following installed:
- Node.js v18+ (LTS recommended)
- npm or yarn package manager
- PostgreSQL v14+
- Redis v6+
- Git version control
- Docker & Docker Compose (optional, for containerized setup)
git clone https://github.com/MettaChain/PropChain-BackEnd.git
cd PropChain-BackEnd# Using npm
npm install
# Or using yarn
yarn install# Copy the environment template
cp .env.example .env
# Edit the .env file with your configuration
nano .envRequired Environment Variables:
DATABASE_URL- PostgreSQL connection stringJWT_SECRET- Secret for JWT token signingENCRYPTION_KEY- 32-character encryption keyRPC_URL- Blockchain RPC endpoint
# Create database
createdb propchain
# Run database migrations
npm run migrate
# Generate Prisma client
npm run db:generate
# (Optional) Seed with test data
npm run db:seed# Start in development mode with hot reload
npm run start:dev
# Or with debug logging
npm run start:debugThe API will be available at http://localhost:3000 with interactive Swagger docs at http://localhost:3000/api/docs.
# Start all services (database, redis, api)
docker-compose up -d
# View logs
docker-compose logs -f api
# Stop services
docker-compose down# Start only database
docker-compose up -d postgres redis
# Start API with local development
npm run start:dev# Run linting
npm run lint
# Fix linting issues
npm run lint -- --fix
# Format code
npm run format
# Type checking
npm run build# Run all tests
npm test
# Run specific test suites
npm run test:unit
npm run test:integration
npm run test:e2e
# Generate coverage report
npm run test:cov
# Run tests in watch mode
npm run test:watch# Create new migration
npx prisma migrate dev --name migration_name
# Reset database
npm run db:reset
# View database in browser
npm run db:studio
# Generate Prisma client
npm run db:generatesrc/
├── common/ # Shared utilities and middleware
│ ├── filters/ # Exception filters
│ ├── interceptors/ # Response interceptors
│ ├── logger/ # Winston logging
│ └── decorators/ # Custom decorators
├── config/ # Configuration management
├── database/ # Database models and services
├── health/ # Health check endpoints
├── modules/ # Business logic modules
│ ├── auth/ # Authentication
│ ├── users/ # User management
│ ├── properties/ # Property management
│ ├── transactions/ # Transaction handling
│ └── blockchain/ # Blockchain integration
├── app.module.ts # Root module
└── main.ts # Application entry point
NODE_ENV- Environment (development/staging/production)PORT- Server port (default: 3000)API_PREFIX- API route prefix (default: api)CORS_ORIGIN- Allowed CORS origins
DATABASE_URL- PostgreSQL connection string
REDIS_HOST- Redis server hostREDIS_PORT- Redis server portREDIS_PASSWORD- Redis password (if required)
JWT_SECRET- JWT signing secretJWT_EXPIRES_IN- JWT token expirationENCRYPTION_KEY- Data encryption key
BLOCKCHAIN_NETWORK- Blockchain network (sepolia/mainnet)RPC_URL- Blockchain RPC endpointPRIVATE_KEY- Private key for transactions (development only)
Once the server is running, visit:
- Swagger UI:
http://localhost:3000/api/docs - Health Check:
http://localhost:3000/api/health - Configuration:
http://localhost:3000/api/configuration
Database Connection Error
# Check PostgreSQL status
pg_ctl status
# Reset database
npm run db:resetRedis Connection Error
# Check Redis status
redis-cli ping
# Restart Redis
docker-compose restart redisModule Not Found Errors
# Clear node modules and reinstall
rm -rf node_modules package-lock.json
npm installPort Already in Use
# Find process using port 3000
lsof -ti:3000
# Kill process
kill -9 $(lsof -ti:3000)- Check the GitHub Issues
- Review the API Documentation
- Join our Discord Community
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
Please read our Contributing Guide for detailed guidelines.
- Set
NODE_ENV=production - Configure production database and Redis
- Set secure JWT secrets and encryption keys
- Configure proper CORS origins
- Set up SSL certificates
# Build production image
docker build -t propchain-backend .
# Run with production configuration
docker run -d \
--name propchain-api \
-p 3000:3000 \
--env-file .env.production \
propchain-backend# Apply Kubernetes manifests
kubectl apply -f k8s/
# Check deployment status
kubectl get pods -l app=propchain-backend- Never commit
.envfiles or secrets - Use strong, unique JWT secrets
- Enable rate limiting in production
- Use HTTPS in production
- Regularly update dependencies
- Implement proper input validation
- Use environment-specific configurations
- Enable Redis caching for frequently accessed data
- Use database connection pooling
- Implement proper indexing
- Monitor application metrics
- Use CDN for static assets
- Optimize database queries
- Application logs are stored in
logs/directory - Use structured logging for better monitoring
- Set up external monitoring (Prometheus/Grafana)
- Configure error tracking (Sentry)
- Monitor database performance
Happy coding! 🚀
For additional support, reach out to the PropChain team at support@propchain.io