Documentation
Welcome to the Refferq documentation. Refferq is an open-source affiliate marketing platform engineered with Next.js 15, TypeScript, PostgreSQL, and Prisma. This comprehensive guide walks you through installation, configuration, core features, API integration, and deployment.
Quick Start
Get Refferq up and running in under 5 minutes:
# 1. Clone the repository
git clone https://github.com/Refferq/Refferq.git
cd Refferq
# 2. Install dependencies
npm install
# 3. Set up environment variables
cp .env.example .env
# Edit .env with your database URL and secrets
# 4. Set up the database
npm run db:generate
npm run db:push
# 5. Start the dev server
npm run devhttp://localhost:3000Installation
System Requirements
- Node.js 18+ (LTS recommended)
- PostgreSQL 12+
- npm or yarn
Docker PostgreSQL
docker run --name refferq-db \
-e POSTGRES_USER=refferq \
-e POSTGRES_PASSWORD=your_password \
-e POSTGRES_DB=refferq \
-p 5432:5432 -d postgres:15Configuration
Required Environment Variables
DATABASE_URL=postgresql://user:password@localhost:5432/refferq
JWT_SECRET=your-secret-min-32-characters-long
RESEND_API_KEY=re_xxxxxxxxxxxxxxxxxxxx
RESEND_FROM_EMAIL=noreply@yourdomain.com
NEXT_PUBLIC_APP_URL=https://yourdomain.comOptional Variables
ADMIN_EMAILS=admin@yourdomain.com
NODE_ENV=productionAffiliate Management
Affiliates go through a registration flow with OTP verification:
- Affiliate submits registration form
- OTP sent to their email for verification
- Account created with
PENDINGstatus - Admin reviews and approves
- Affiliate receives approval email with referral code
PENDING, ACTIVE, SUSPENDED, REJECTEDTracking Setup
JavaScript Tracker
Add the tracking script to your website:
<!-- Add before closing </body> tag -->
<script src="https://yourdomain.com/scripts/refferq-tracker.js"
data-site="your-site-id">
</script>Server-Side Tracking
// Record a conversion via API
const response = await fetch('/api/track/conversion', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
referralCode: 'JOHN-A1B2',
amountCents: 9900, // $99.00
metadata: { orderId: 'ORD-123' }
})
});Commissions
Commission rates are configured at the partner group level. Each affiliate automatically inherits the commission rate of their assigned group:
// Commission calculation
const rate = affiliate.partnerGroup?.commissionRate || defaultRate;
const commissionCents = Math.round(amountCents * (rate / 100));
// All monetary values stored as cents (integers)
// Display: (amountCents / 100).toFixed(2)Payouts
Manage affiliate payouts through the admin panel:
- Affiliate accrues commission balance from conversions
- Affiliate requests payout (or admin initiates)
- Admin reviews and approves the payout request
- Admin processes payment via preferred method
- Payout marked as completed, balance updated
Authentication
Refferq uses JWT tokens stored in HTTP-only cookies:
# Login
POST /api/auth/login
Content-Type: application/json
{
"email": "admin@example.com",
"password": "your-password"
}
# Response sets auth-token cookie automaticallyAPI Endpoints
Authentication
/api/auth/login/api/auth/register/api/auth/logout/api/auth/meAdmin
/api/admin/affiliates/api/admin/referrals/api/admin/transactions/api/admin/payouts/api/admin/partner-groups/api/admin/settingsAffiliate
/api/affiliate/dashboard/api/affiliate/referrals/api/affiliate/commissions/api/affiliate/payoutTracking
/api/track/click/api/track/conversionWebhooks
New in v1.1.0Refferq supports 12 webhook event types for real-time system integration:
Reports API
New in v1.1.0GET /api/admin/reports/analytics?startDate=2025-01-01&endDate=2025-12-31
# Response
{
"totalClicks": 15420,
"totalConversions": 892,
"conversionRate": 5.78,
"totalRevenueCents": 8920000,
"totalCommissionCents": 892000,
"topAffiliates": [...]
}Deploy to Vercel
- Push your code to GitHub
- Import the repository in Vercel
- Set all environment variables
- Deploy — Vercel handles the rest
Docker Deployment
# docker-compose.yml
version: '3.8'
services:
app:
build: .
ports:
- "3000:3000"
environment:
- DATABASE_URL=postgresql://refferq:password@db:5432/refferq
- JWT_SECRET=your-secret-here
depends_on:
- db
db:
image: postgres:15
environment:
- POSTGRES_USER=refferq
- POSTGRES_PASSWORD=password
- POSTGRES_DB=refferq
volumes:
- pgdata:/var/lib/postgresql/data
volumes:
pgdata:VPS / Cloud Deployment
# Install PM2
npm install -g pm2
# Build the application
npm run build
# Start with PM2
pm2 start npm --name "refferq" -- start
# Enable startup script
pm2 startup
pm2 saveNeed Help?
Our community and documentation are here to support you at every step.