NovaRewards is a blockchain-powered loyalty rewards platform built on Stellar. It combines a customer rewards system with blockchain-backed NOVA token issuance, enabling merchants to create and manage loyalty campaigns with real cryptocurrency rewards.
- Prerequisites
- Quick Start
- Setup Instructions
- Running the Application
- Testing
- Project Architecture
- Troubleshooting
Before setting up NovaRewards, ensure you have the following installed:
- Node.js 20+ (download)
- PostgreSQL 12+ (download)
- Redis (optional, for rate limiting and caching) (download)
- Stellar Freighter Wallet (install extension) — required for blockchain transactions on the frontend
npm(bundled with Node.js)git(download)
# 1. Clone the repository
git clone <repository-url>
cd Nova-Rewards/novaRewards
# 2. Install dependencies
npm install
# 3. Copy environment file
cp .env.example .env
# 4. Configure your .env (see Setup Instructions)
# Edit .env with PostgreSQL, Stellar testnet, and other credentials
# 5. Run database migrations
npm run migrate
# 6. Setup Testnet keypairs and issue NOVA asset
npm run setup:new
# 7. Start backend and frontend
npm run dev:all # or run separately in different terminals:
# Terminal 1: npm run dev -w backend
# Terminal 2: npm run dev -w frontend
# 8. Run tests
npm run testgit clone <repository-url>
cd Nova-Rewards/novaRewardsUsing npm workspaces (all packages):
npm installTo install for a specific workspace:
npm install -w backend
npm install -w frontendcp .env.example .envOpen .env in your editor and configure:
Stellar Testnet Accounts:
# Leave these empty initially; setup.js will generate them
ISSUER_PUBLIC=
ISSUER_SECRET=
DISTRIBUTION_PUBLIC=
DISTRIBUTION_SECRET=
STELLAR_NETWORK=testnet
HORIZON_URL=https://horizon-testnet.stellar.orgPostgreSQL Database:
POSTGRES_USER=nova
POSTGRES_PASSWORD=changeme # Change this!
POSTGRES_DB=nova_rewards
DATABASE_URL=postgresql://nova:changeme@localhost:5432/nova_rewards
DATABASE_MIGRATE_URL=postgresql://nova_migrate:changeme@localhost:5432/nova_rewardsBackend Settings:
PORT=3001
NODE_ENV=development
JWT_SECRET=your-long-random-secret-here # Generate a strong secret
ALLOWED_ORIGIN=http://localhost:3000Frontend Settings:
NEXT_PUBLIC_API_URL=http://localhost:3001
NEXT_PUBLIC_STELLAR_NETWORK=testnet
NEXT_PUBLIC_HORIZON_URL=https://horizon-testnet.stellar.orgFor more environment variables, see .env.example comments.
# Connect to PostgreSQL as superuser
sudo -u postgres psql
# Create migration user and database
CREATE USER nova_migrate WITH PASSWORD 'changeme';
CREATE USER nova WITH PASSWORD 'changeme';
CREATE DATABASE nova_rewards OWNER nova;
# Grant permissions
GRANT ALL PRIVILEGES ON DATABASE nova_rewards TO nova;
GRANT ALL PRIVILEGES ON DATABASE nova_rewards TO nova_migrate;
\qAlternatively, if PostgreSQL is running via Docker or has different credentials, adjust DATABASE_URL in .env.
npm run migrateThis will execute all SQL migrations in database/ to set up tables, indexes, and triggers.
To rollback migrations (dev only):
npm run migrate -- --rollbacknpm run setup:newThis script will:
- Generate new Issuer and Distribution keypairs
- Fund them via Stellar Friendbot
- Print keypair details to the console
- You must add these to your
.envfile manually
Copy the output and update your .env:
ISSUER_PUBLIC=G...
ISSUER_SECRET=S...
DISTRIBUTION_PUBLIC=G...
DISTRIBUTION_SECRET=S...If you already have keypairs in .env:
npm run setupThis will:
- Use the existing
ISSUER_SECRETandDISTRIBUTION_SECRETfrom.env - Fund the accounts via Friendbot (if not already funded)
- Issue the NOVA asset to the Issuer account
Note: Friendbot provides 10,000 XLM to newly created testnet accounts.
Run all services with automatic file watching:
npm run dev:allOr run individually in separate terminals:
# Terminal 1: Start backend (port 3001)
npm run dev -w backend
# Terminal 2: Start frontend (port 3000)
npm run dev -w frontend# Build the frontend
npm run build
# Start the backend (must be built first)
npm run start -w backend
# Start the frontend
npm run start -w frontend# Development
npm run dev -w backend
# Production
npm start -w backendRuns on: http://localhost:3001
# Development
npm run dev -w frontend
# Production (requires `npm run build` first)
npm run start -w frontendRuns on: http://localhost:3000
npm testThis runs tests for both backend and frontend with coverage reports.
npm run test:backendOr:
npm run test -w backendnpm run test:frontendOr:
npm run test -w frontendFor debugging or when tests have race conditions:
npx jest --runInBandnpm test -- --coveragenpm run test:ciThis generates JUnit XML reports for CI/CD pipelines.
NovaRewards
├── backend/ # Express.js API server
│ ├── server.js # Main server entry point
│ ├── middleware/ # Auth, rate limiting, CORS
│ ├── routes/ # API endpoints
│ ├── models/ # Database queries (SQL layer)
│ ├── services/ # Business logic
│ ├── stellar/ # Stellar blockchain integration
│ ├── webhooks/ # Event listeners
│ └── tests/ # Jest unit tests
│
├── frontend/ # Next.js React application
│ ├── pages/ # Next.js pages and API routes
│ ├── components/ # React components
│ ├── styles/ # CSS modules and global styles
│ ├── lib/ # Utilities (API calls, Stellar SDK)
│ ├── hooks/ # React hooks
│ ├── context/ # React context (auth, state)
│ ├── public/ # Static assets
│ └── __tests__/ # Jest unit tests
│
├── blockchain/ # Stellar Soroban smart contracts
│ ├── contracts/ # Rust contracts
│ └── test/ # Contract tests
│
├── database/ # PostgreSQL migrations
│ ├── 001_create_merchants.sql
│ ├── 002_create_users.sql
│ ├── ...
│ └── migrate.js # Migration runner
│
├── scripts/ # Utility scripts
│ ├── setup.js # Testnet keypair generation
│ ├── reset-testnet.js # Reset testnet data
│ └── deploy-contracts.sh # Deploy contracts
│
├── emails/ # Email templates
│ └── README.md # Email documentation
│
├── docs/ # Additional documentation
│ ├── api/ # API documentation
│ └── security/ # Security guidelines
│
└── docker-compose.yml # PostgreSQL + Redis setup
- Framework: Express.js
- Database: PostgreSQL with migration system
- Authentication: JWT (JSON Web Tokens)
- Rate Limiting: Express rate-limit with Redis
- Blockchain: Stellar SDK for asset management
- Monitoring: Prometheus metrics, Elasticsearch logging
- Testing: Jest with supertest
Main Features:
- User management and authentication
- Campaign management
- Points/rewards system
- Referral tracking
- Merchant account management
- Webhook listeners for contract events
- Email notifications
- Framework: Next.js 14 with React 18
- Wallet Integration: Stellar Freighter
- State Management: React Context + hooks
- HTTP Client: Axios
- Testing: Jest + React Testing Library
- E2E Testing: Playwright
Main Features:
- User onboarding and authentication
- Campaign discovery and participation
- Rewards dashboard
- Referral program interface
- Merchant admin panel
- Wallet connection and transaction signing
Core tables:
users— Customer and merchant accountsmerchants— Business detailscampaigns— Loyalty campaignstransactions— Point earn/redeem eventspoint_transactions— Detailed ledgerredemptions— Reward fulfillmentcontract_events— Blockchain eventswebhooks— Event subscriptions
All tables include audit columns (created_at, updated_at) and appropriate indexes for query performance.
- NOVA Asset: Custom token issued on Stellar testnet
- Accounts: Issuer (issues NOVA) + Distribution (sends tokens)
- Keypairs: Generated via
setup.jsand funded via Friendbot - Contract Events: Soroban contract webhooks logged for tracking
Error: ECONNREFUSED ... 5432
Solution:
- Ensure PostgreSQL is running:
sudo service postgresql status - Check
DATABASE_URLin.envmatches your PostgreSQL config - If using Docker:
docker-compose up -d(starts PostgreSQL in container)
Error: Cannot find module 'express'
Solution:
# Clear and reinstall dependencies
rm -rf node_modules package-lock.json
npm installError: ERROR: --use-env requires ISSUER_SECRET and DISTRIBUTION_SECRET in .env
Solution:
npm run setup:new
# Copy the printed keypairs into your .env
# Then run: npm run setupError: EADDRINUSE: address already in use :::3001
Solution:
# Find and kill the process using port 3001
lsof -i :3001
kill -9 <PID>
# Or use a different port:
PORT=3002 npm run dev -w backendError: Error: connect ECONNREFUSED 127.0.0.1:6379
Solution:
- Redis is optional. If not needed, remove
REDIS_URLfrom.env - To use Redis:
redis-server(ordocker-compose up redis)
Solution:
- Ensure database migrations are up to date:
npm run migrate - Run tests in band mode:
npm run test -- --runInBand - Check test output for specific error messages
- Verify
.envhas correct database credentials for test environment
Error: Failed to fetch from API
Solution:
- Verify backend is running:
npm run dev -w backend(should listen on 3001) - Check
NEXT_PUBLIC_API_URLin.env: should behttp://localhost:3001 - Check CORS settings in backend:
ALLOWED_ORIGINshould match frontend URL - Check browser console for specific error messages
Error: Module not found: '@stellar/freighter-api'
Solution:
npm install --save @stellar/freighter-api
npm run build- Stellar Documentation: https://developers.stellar.org/
- Freighter Wallet API: https://github.com/stellar/freighter
- Next.js Guide: https://nextjs.org/docs
- PostgreSQL Docs: https://www.postgresql.org/docs/
- Express.js Guide: https://expressjs.com/
For issues, questions, or contributions, please refer to:
CONTRIBUTING.md— Contribution guidelinesTEAM_COMMUNICATION.md— Team structure- Project issues: GitHub Issues
Last Updated: 2024