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.
Before setting up NovaRewards, ensure you have the following installed:
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 test
git clone <repository-url>
cd Nova-Rewards/novaRewards
Using npm workspaces (all packages):
npm install
To install for a specific workspace:
npm install -w backend
npm install -w frontend
cp .env.example .env
.env with Your CredentialsOpen .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.org
PostgreSQL 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_rewards
Backend Settings:
PORT=3001
NODE_ENV=development
JWT_SECRET=your-long-random-secret-here # Generate a strong secret
ALLOWED_ORIGIN=http://localhost:3000
Frontend Settings:
NEXT_PUBLIC_API_URL=http://localhost:3001
NEXT_PUBLIC_STELLAR_NETWORK=testnet
NEXT_PUBLIC_HORIZON_URL=https://horizon-testnet.stellar.org
For 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;
\q
Alternatively, if PostgreSQL is running via Docker or has different credentials, adjust DATABASE_URL in .env.
npm run migrate
This will execute all SQL migrations in database/ to set up tables, indexes, and triggers.
To rollback migrations (dev only):
npm run migrate -- --rollback
npm run setup:new
This script will:
.env file manuallyCopy the output and update your .env:
ISSUER_PUBLIC=G...
ISSUER_SECRET=S...
DISTRIBUTION_PUBLIC=G...
DISTRIBUTION_SECRET=S...
.envIf you already have keypairs in .env:
npm run setup
This will:
ISSUER_SECRET and DISTRIBUTION_SECRET from .envNote: Friendbot provides 10,000 XLM to newly created testnet accounts.
Run all services with automatic file watching:
npm run dev:all
Or 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 backend
Runs on: http://localhost:3001
# Development
npm run dev -w frontend
# Production (requires `npm run build` first)
npm run start -w frontend
Runs on: http://localhost:3000
npm test
This runs tests for both backend and frontend with coverage reports.
npm run test:backend
Or:
npm run test -w backend
npm run test:frontend
Or:
npm run test -w frontend
For debugging or when tests have race conditions:
npx jest --runInBand
npm test -- --coverage
npm run test:ci
This 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
/backend)Main Features:
/frontend)Main Features:
Core tables:
users — Customer and merchant accountsmerchants — Business detailscampaigns — Loyalty campaignstransactions — Point earn/redeem eventspoint_transactions — Detailed ledgerredemptions — Reward fulfillmentcontract_events — Blockchain eventswebhooks — Event subscriptionsAll tables include audit columns (created_at, updated_at) and appropriate indexes for query performance.
setup.js and funded via FriendbotError: ECONNREFUSED ... 5432
Solution:
sudo service postgresql statusDATABASE_URL in .env matches your PostgreSQL configdocker-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 install
Error: 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 setup
Error: 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 backend
Error: Error: connect ECONNREFUSED 127.0.0.1:6379
Solution:
REDIS_URL from .envredis-server (or docker-compose up redis)Solution:
npm run migratenpm run test -- --runInBand.env has correct database credentials for test environmentError: Failed to fetch from API
Solution:
npm run dev -w backend (should listen on 3001)NEXT_PUBLIC_API_URL in .env: should be http://localhost:3001ALLOWED_ORIGIN should match frontend URLError: Module not found: '@stellar/freighter-api'
Solution:
npm install --save @stellar/freighter-api
npm run build
For issues, questions, or contributions, please refer to:
CONTRIBUTING.md — Contribution guidelinesTEAM_COMMUNICATION.md — Team structureLast Updated: 2024