📚 Documentation
Welcome to the Refferq documentation! This guide will help you get started with setting up and running your own affiliate platform.
🚀 Quick Start
Get Refferq running locally in 5 minutes:
1. Clone the Repository
git clone https://github.com/Refferq/Refferq.git
cd Refferq
2. Install Dependencies
npm install
# or
yarn install
# or
pnpm install
3. Set Up Environment Variables
Copy the example environment file and configure your settings:
cp .env.example .env
Update .env with your database and email credentials:
# Database
DATABASE_URL="postgresql://user:password@localhost:5432/refferq"
# JWT Secret
JWT_SECRET="your-super-secret-jwt-key-change-this"
# Email (Resend)
RESEND_API_KEY="re_xxxxxxxxxxxxx"
EMAIL_FROM="noreply@yourdomain.com"
# App URL (Production)
NEXT_PUBLIC_APP_URL="https://app.refferq.com"
4. Set Up Database
npx prisma generate
npx prisma migrate dev
npx prisma db seed
5. Run Development Server
npm run dev
💾 Installation
System Requirements
- Node.js 18.x or higher
- PostgreSQL 12.x or higher
- npm, yarn, or pnpm
- Git
Database Setup
Refferq uses PostgreSQL. You can use:
- Local PostgreSQL - Install PostgreSQL on your machine
- Docker - Run PostgreSQL in a container
- Cloud Database - Use Supabase, Railway, or Neon
Using Docker for PostgreSQL:
docker run --name refferq-db \
-e POSTGRES_PASSWORD=mysecretpassword \
-e POSTGRES_DB=refferq \
-p 5432:5432 \
-d postgres:15
⚙️ Configuration
Environment Variables
All configuration is done through environment variables in the .env file:
Required Variables:
DATABASE_URL- PostgreSQL connection stringJWT_SECRET- Secret key for JWT tokens (generate a random 32+ character string)RESEND_API_KEY- API key from Resend.com for sending emailsEMAIL_FROM- Sender email addressNEXT_PUBLIC_APP_URL- Your app's public URL
Optional Variables:
NODE_ENV- Environment (development, production)PORT- Server port (default: 3000)
👥 Affiliate Management
User Registration Flow
Refferq uses a passwordless OTP-based authentication system:
- User enters email and selects role (Admin or Affiliate)
- OTP code is sent to their email
- User enters OTP code to complete registration
- New affiliates start with
PENDINGstatus - Admins must approve affiliates to change status to
ACTIVE
Affiliate Statuses
- PENDING - Newly registered, awaiting admin approval
- ACTIVE - Approved and can generate referrals
- INACTIVE - Temporarily disabled
- SUSPENDED - Blocked from the platform
🎯 Tracking Setup
JavaScript Tracking Script
Refferq includes a lightweight JavaScript tracking library (refferq-tracker.js) that you can add to any website.
Step 1: Generate API Key
In the admin dashboard, go to Settings → Integration and click "Generate API Key". You'll receive:
- Public Key (pk_xxx) - Used in frontend tracking
- Private Key (sk_xxx) - Used for server-side API calls
Step 2: Add Tracking Script
Add this script tag to your website, just before the closing </body> tag:
<script
src="https://app.refferq.com/scripts/refferq-tracker.js"
data-api-url="https://app.refferq.com/api"
data-api-key="pk_your_public_key_here"
></script>
Step 3: Track Conversions
When a sale occurs, call the tracking function:
// Track a conversion
Refferq.trackConversion({
orderId: "order_123",
amount: 99.99,
currency: "USD",
email: "customer@example.com"
});
Server-Side Tracking
For more control, use the API directly:
POST /api/track/conversion
Content-Type: application/json
X-API-Key: sk_your_private_key_here
{
"referralCode": "JOHN123",
"orderId": "order_123",
"amount": 99.99,
"currency": "USD",
"customerEmail": "customer@example.com"
}
💰 Commissions
Commission Types
Refferq supports flexible commission structures:
Percentage-Based
{
"type": "PERCENTAGE",
"rate": 20, // 20% commission
"minPayout": 50.00
}
Fixed Amount
{
"type": "FIXED",
"amount": 10.00, // $10 per sale
"minPayout": 50.00
}
Tiered Commissions
{
"type": "TIERED",
"tiers": [
{ "upTo": 10, "rate": 15 }, // First 10 sales: 15%
{ "upTo": 50, "rate": 20 }, // Next 40 sales: 20%
{ "upTo": null, "rate": 25 } // 50+ sales: 25%
]
}
💸 Payouts
Payout Management
Track and manage affiliate payouts through the admin dashboard:
- View affiliate balances and pending payouts
- Set minimum payout thresholds
- Generate payout reports
- Mark payouts as completed
- Export payout history for accounting
Automated Payouts
Integrate with payment providers (coming soon):
- PayPal Mass Pay
- Stripe Connect
- Wise (TransferWise)
- Bank transfers via Plaid
🔐 Authentication
API Authentication
Refferq uses JWT tokens for authentication. Include the token in your requests:
Authorization: Bearer <your-jwt-token>
Getting a JWT Token
POST /api/auth/login
Content-Type: application/json
{
"email": "admin@example.com",
"otp": "123456"
}
Response:
{
"success": true,
"message": "Login successful",
"user": {
"id": "user_id",
"email": "admin@example.com",
"role": "ADMIN"
}
}
📡 API Endpoints
Authentication Endpoints
POST /api/auth/register- Register new userPOST /api/auth/verify-otp- Verify OTP codePOST /api/auth/login- Login userPOST /api/auth/logout- Logout user
Admin Endpoints
GET /api/admin/affiliates- List all affiliatesPATCH /api/admin/affiliates/:id/status- Update affiliate statusGET /api/admin/dashboard- Get dashboard statisticsGET /api/admin/referrals- List all referralsPOST /api/admin/integration/generate-key- Generate API keysPUT /api/admin/profile- Update admin profile
Affiliate Endpoints
GET /api/affiliate/profile- Get affiliate profile and statsPOST /api/affiliate/generate-code- Generate referral codeGET /api/affiliate/referrals- Get affiliate's referralsGET /api/affiliate/earnings- Get earnings data
Tracking Endpoints
POST /api/track/referral- Track referral clickPOST /api/track/conversion- Track conversion/sale
🔔 Webhooks
Configure webhooks to receive real-time notifications:
Webhook Events
affiliate.created- New affiliate registeredaffiliate.approved- Affiliate status changed to ACTIVEreferral.created- New referral trackedconversion.created- New conversion recordedpayout.completed- Payout marked as completed
Webhook Payload Example
{
"event": "conversion.created",
"timestamp": "2025-10-12T10:30:00Z",
"data": {
"conversionId": "conv_123",
"affiliateId": "aff_456",
"amount": 99.99,
"commission": 19.99,
"orderId": "order_789"
}
}
☁️ Deploy to Vercel
One-Click Deploy
Deploy Refferq to Vercel in seconds:
- Fork the Refferq repository on GitHub
- Connect your Vercel account to GitHub
- Click "New Project" and select the forked repository
- Add your environment variables
- Click "Deploy"
🐳 Docker Deployment
Using Docker Compose
Create a docker-compose.yml file:
version: '3.8'
services:
db:
image: postgres:15
environment:
POSTGRES_DB: refferq
POSTGRES_PASSWORD: yourpassword
volumes:
- postgres_data:/var/lib/postgresql/data
ports:
- "5432:5432"
app:
build: .
ports:
- "3000:3000"
environment:
DATABASE_URL: postgresql://postgres:yourpassword@db:5432/refferq
JWT_SECRET: your-jwt-secret
RESEND_API_KEY: re_xxxxx
depends_on:
- db
volumes:
postgres_data:
Run with:
docker-compose up -d
🖥️ VPS/Cloud Deployment
Deploy to Any VPS
Deploy Refferq to Digital Ocean, Linode, AWS, or any VPS:
- Set up server - Ubuntu 22.04 recommended
- Install Node.js - Use nvm or apt
- Install PostgreSQL
- Clone repository
- Configure environment
- Build application -
npm run build - Set up PM2 - Process manager
- Configure Nginx - Reverse proxy
- Set up SSL - Use Let's Encrypt
Using PM2
# Install PM2
npm install -g pm2
# Start application
pm2 start npm --name "refferq" -- start
# Save PM2 config
pm2 save
pm2 startup
📞 Need Help?
Join our community and get support: