Skip to main content

Installation

This guide provides comprehensive setup instructions for the Rahat Project Payroll (CVA - Cash Voucher Assistance) system. This is a blockchain-based CVA system built with NestJS, Hardhat, and The Graph that enables secure, transparent, and efficient CVA management with blockchain integration.

Prerequisites​

Before setting up the Rahat Voucher Assistance system, you need to have the rahat-platform running. Please refer to the Rahat Platform Setup Guide for detailed instructions on setting up the core Rahat platform.

Note: This project depends on the rahat-platform being operational. Ensure the platform is running before proceeding with the voucher assistance setup.

Installation & Setup​

1. Clone the Repository​

git clone <repository-url>
cd rahat-project-rp

2. Bootstrap the Project​

The bootstrap command will set up the entire project environment:

pnpm bootstrap

This command performs the following operations:

  • Installs all dependencies across the monorepo
  • Sets up environment variables
  • Generates Prisma client
  • Runs database migrations
  • Seeds initial data
  • Sets up The Graph subgraph

3. Start the Application​

pnpm start

This starts the NestJS API server in development mode.

Project Structure​

This is a monorepo built with Nx containing multiple applications:

Apps​

  • apps/rp - Main NestJS API server
  • apps/contracts - Smart contracts (Hardhat)
  • apps/graph - The Graph subgraph for blockchain indexing
  • apps/rp-e2e - End-to-end tests

Libraries​

  • libs/extensions - Shared utilities and extensions

Architecture Overview​

Backend API (apps/rp)​

The main NestJS application provides REST APIs for:

  • Beneficiary Management - Add, update, and manage beneficiaries
  • Vendor Management - Handle vendor operations and redemptions
  • Disbursement Plans - Create and manage payment plans
  • Blockchain Integration - Process blockchain transactions
  • Communication - Handle notifications and messaging

Smart Contracts (apps/contracts)​

Solidity contracts deployed on blockchain networks:

  • RahatToken - ERC20 token for disbursements
  • RahatPayrollProject - Main CVA project contract
  • RahatClaim - Claim processing contract
  • RahatTreasury - Treasury management
  • RahatAccessManager - Access control
  • Vendor - Vendor management
  • Redemptions - Redemption processing

The Graph Subgraph (apps/graph)​

Indexes blockchain events and provides GraphQL API for:

  • Token transfers and approvals
  • CVA project events
  • Claim processing
  • Beneficiary management
  • Vendor operations

Configuration​

Environment Variables​

Create a .env file in the root directory:

# Database
DATABASE_URL="postgresql://rahat:rahat@localhost:5432/rahat-rp"

# Redis
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=

# Blockchain
PRIVATE_KEY=your_private_key
RPC_URL=your_rpc_url

# The Graph
GRAPH_NODE_URL=http://localhost:8020
IPFS_URL=http://localhost:5001

Database Setup​

The project uses PostgreSQL with Prisma ORM. The bootstrap script will:

  1. Create the database
  2. Run migrations
  3. Seed initial data
  4. Set up The Graph subgraph

Available Scripts​

Development​

# Start development server
pnpm start

# Build the application
pnpm build:rp

# Run tests
pnpm test

# Reset database and reseed
pnpm reset

Database Management​

# Run migrations
pnpm migrate:dev

# Reset database
pnpm migrate:reset

# Open Prisma Studio
pnpm prisma:studio

# Generate Prisma client
pnpm prisma:generate

Smart Contracts​

# Compile contracts
pnpm contracts:compile

# Run contract tests
pnpm contracts:test

# Generate coverage report
pnpm contracts:coverage

# Deploy contracts
pnpm contracts:ignite:rahatToken

The Graph​

# Generate GraphQL types
pnpm graph:codegen

# Build subgraph
pnpm graph:build

# Deploy to hosted service
pnpm graph:deploy

# Local development
pnpm graph:deploy-local

Testing​

# Run all tests
pnpm test

# Run e2e tests
pnpm test:e2e

# Run contract tests
pnpm contracts:test

Monitoring & Debugging​

Prisma Studio​

pnpm prisma:studio

Access the database GUI at http://localhost:5555

The Graph Playground​

pnpm graph:deploy-local

Access the GraphQL playground at the URL provided in the output

Deployment​

Production Build​

pnpm build:all

Docker Deployment​

docker build -f Dockerfile.rp -t rahat-project-payroll .

Troubleshooting​

Common Issues​

  1. Database Connection Issues

    • Ensure PostgreSQL is running
    • Check DATABASE_URL in .env file
    • Verify database exists and is accessible
  2. Contract Compilation Errors

    • Check Node.js version (requires v18+)
    • Ensure all dependencies are installed
    • Verify Hardhat configuration
  3. The Graph Issues

    • Ensure Docker is running
    • Check if ports 8000, 8001, 8002, 8003, 8004, 8005, 8020, 5001 are available
    • Verify subgraph configuration

Reset Everything​

If you encounter issues, you can reset the entire setup:

# Reset database and reseed
pnpm reset

# Clean and reinstall dependencies
rm -rf node_modules
pnpm install
pnpm bootstrap

Next Steps​

After successful setup:

  1. Explore the API - Use the provided API documentation to understand available endpoints
  2. Deploy Contracts - Deploy smart contracts to your target blockchain network
  3. Configure The Graph - Set up indexing for your deployed contracts
  4. Run Tests - Ensure all components are working correctly
  5. Start Development - Begin building your CVA application

For more detailed information, refer to: