A comprehensive referral and credit program for digital product platforms. Users can register, share unique referral links, earn credits on first-purchase conversions, and track detailed metrics through an intuitive dashboard.
Live Demo : Click Here
Walk Through Video : Click Here
- Secure Authentication – Powered by Clerk for robust user management
- Unique Referral Links – Every user gets a personalized referral code
- Dual Credit Rewards – 2 credits awarded to both referrer and referred user on first purchase
- Purchase Simulation – Test the complete flow with simulated product purchases
- Fraud Prevention – Automatic duplicate crediting protection
- Total referred users count
- Conversion tracking (referred → purchased)
- Lifetime credits earned
- One-click referral link copying
- Real-time statistics
- Clean, modular architecture
- Type-safe development with TypeScript
- Responsive design optimized for all devices
- RESTful API design
- Comprehensive error handling
| Layer | Technology |
|---|---|
| Frontend | Next.js, TypeScript, Tailwind CSS, Zustand, Framer Motion |
| Backend | Node.js, Express, TypeScript |
| Database | MongoDB with Mongoose ODM |
| Authentication | Clerk |
| Deployment | Render (Backend + Static Frontend) |
root/
├── backend/ # Express API server
│ ├── src/
│ │ ├── models/ # Mongoose schemas
│ │ ├── routes/ # API endpoints
│ │ ├── middleware/ # Auth & validation
│ │ └── server.ts # Entry point
│ ├── package.json
│ └── tsconfig.json
│
└── frontend/ # Next.js application
├── src/
│ ├── app/ # App router pages
│ ├── components/ # React components
│ ├── store/ # Zustand state
│ └── lib/ # Utilities
├── package.json
└── next.config.js
flowchart TB
subgraph Client["Frontend: Next.js + Clerk"]
A[Sign Up / Sign In]
B[Dashboard]
A -->|JWT| B
end
subgraph Backend["Backend: Express + Mongoose"]
API[API Router]
Auth[Auth Middleware]
Users[Users Controller]
Referrals[Referrals Controller]
Purchases[Purchases Controller]
API -->|verify Clerk JWT| Auth
Auth --> Users
Auth --> Referrals
Auth --> Purchases
end
subgraph DB["MongoDB Atlas"]
U[(Users Collection)]
R[(Referrals Collection)]
P[(Purchases Collection)]
end
B -->|GET /api/users/me| API
B -->|GET /api/referrals/stats| API
B -->|POST /api/purchases| API
B -->|POST /api/users/init| API
B -->|POST /api/referrals/bind| API
Users -.-> U
Referrals -.-> R
Purchases -.-> P
Purchases -.->|Transaction| Referrals
Users -.->|Transaction| Referrals
Users -.->|Transaction| Purchases
style Client fill:#e1f5ff,stroke:#0288d1,stroke-width:2px
style Backend fill:#fff3e0,stroke:#f57c00,stroke-width:2px
style DB fill:#f3e5f5,stroke:#7b1fa2,stroke-width:2px
PORT=8080
MONGODB_URI=your_mongodb_connection_string
CLERK_SECRET_KEY=your_clerk_secret_key
CLERK_PUBLISHABLE_KEY=your_clerk_publishable_key
CLIENT_ORIGIN=http://localhost:3000NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=your_clerk_publishable_key
NEXT_PUBLIC_API_BASE=http://localhost:8080
NEXT_PUBLIC_APP_BASE=http://localhost:3000Note: Create
.env.examplefiles with placeholder values before committing to version control.
- Node.js 18+ (macOS M1 compatible)
- MongoDB instance (local or Atlas)
- Clerk account with API keys
1. Clone the repository
git clone https://github.com/yourusername/credflow.git
cd credflow2. Backend Setup
cd backend
npm install
npm run build
npm startServer runs on http://localhost:8080
3. Frontend Setup
cd ../frontend
npm install
npm run devApplication runs on http://localhost:3000
4. Verify Installation
- Navigate to
http://localhost:3000 - Sign up with a test account
- Check console for any errors
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
POST |
/api/users/init |
Create or ensure user exists | ✅ |
GET |
/api/users/me |
Retrieve authenticated user info | ✅ |
GET |
/api/referrals/stats |
Get referral statistics | ✅ |
POST |
/api/referrals/bind |
Bind referral code to user | ✅ |
POST |
/api/purchases |
Simulate product purchase | ✅ |
GET |
/api/health |
Health check endpoint | ❌ |
Get User Stats
curl -X GET http://localhost:8080/api/referrals/stats \
-H "Authorization: Bearer YOUR_CLERK_TOKEN"Response
{
"totalReferred": 5,
"convertedUsers": 3,
"totalCredits": 6,
"referralCode": "ABC123XYZ"
}┌─────────────────────────────────────────────────────────────┐
│ CLIENT LAYER │
│ ┌────────────────────────────────────────────────────┐ │
│ │ Next.js Frontend (Port 3000) │ │
│ │ - Authentication UI (Clerk) │ │
│ │ - Dashboard & Metrics │ │
│ │ - Referral Link Management │ │
│ └────────────────────────────────────────────────────┘ │
└──────────────────────────┬──────────────────────────────────┘
│ HTTPS/REST API
▼
┌─────────────────────────────────────────────────────────────┐
│ SERVER LAYER │
│ ┌────────────────────────────────────────────────────┐ │
│ │ Express API (Port 8080) │ │
│ │ ┌──────────────────────────────────────────┐ │ │
│ │ │ Clerk JWT Verification Middleware │ │ │
│ │ └──────────────────────────────────────────┘ │ │
│ │ ┌──────────────────────────────────────────┐ │ │
│ │ │ Route Handlers │ │ │
│ │ │ - Users Controller │ │ │
│ │ │ - Referrals Controller │ │ │
│ │ │ - Purchases Controller │ │ │
│ │ └──────────────────────────────────────────┘ │ │
│ └────────────────────────────────────────────────────┘ │
└──────────────────────────┬──────────────────────────────────┘
│ Mongoose ODM
▼
┌─────────────────────────────────────────────────────────────┐
│ DATABASE LAYER │
│ ┌────────────────────────────────────────────────────┐ │
│ │ MongoDB │ │
│ │ ┌──────────────┐ ┌──────────────┐ ┌─────────┐ │ │
│ │ │ Users │ │ Referrals │ │Purchases│ │ │
│ │ │ Collection │ │ Collection │ │Collection│ │ │
│ │ └──────────────┘ └──────────────┘ └─────────┘ │ │
│ └────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
User Registration & Referral Flow:
1. User Sign Up
│
├─> Clerk Authentication
│
├─> POST /api/users/init
│ └─> Create User Record
│ └─> Generate Unique Referral Code
│
└─> Redirect to Dashboard
2. Referral Binding (Optional)
│
├─> Check URL for Referral Code
│
├─> POST /api/referrals/bind
│ └─> Validate Code
│ └─> Create Referral Relationship
│
└─> Store Referrer-Referee Link
3. First Purchase
│
├─> POST /api/purchases
│ └─> Check if First Purchase
│ ├─> Award 2 Credits to Buyer
│ └─> Award 2 Credits to Referrer (if exists)
│
└─> Update Purchase Records
4. Dashboard View
│
├─> GET /api/users/me
│
├─> GET /api/referrals/stats
│ └─> Calculate Metrics
│ ├─> Total Referred Count
│ ├─> Converted Users Count
│ └─> Total Credits Earned
│
└─> Render Statistics
- Authentication: All API routes protected with Clerk JWT verification
- Input Validation: Server-side validation for all user inputs
- Rate Limiting: Recommended for production (not included in MVP)
- Environment Variables: Sensitive keys stored in environment config
- CORS: Configured to allow only trusted origins
-
User Registration
- Sign up with new account
- Verify user record in database
- Check referral code generation
-
Referral Flow
- Share referral link
- Sign up via referral link
- Verify referral binding
-
Purchase Flow
- Make first purchase
- Verify credit allocation
- Attempt duplicate purchase
- Confirm no duplicate credits
-
Dashboard
- Check metric accuracy
- Test referral link copy
- Verify real-time updates
- Email notifications for referral conversions
- Credit redemption system
- Multi-tier referral rewards
- Analytics dashboard with charts
- Admin panel for monitoring
- Automated testing suite
- Rate limiting middleware
- Webhook integration for real-time events
✓ Complete source code (frontend + backend)
✓ README with comprehensive documentation
✓ .env.example files for both layers
✓ Architecture diagrams (text-based)
✓ API endpoint documentation
✓ Deployment configuration guides
✓ Incremental Git commit history
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
For questions or issues:
- Open an issue on GitHub
- Contact: vendotha@gmail.com
This project is licensed under the MIT License - see the LICENSE file for details.
Current Version: 1.0.0
Status: Production Ready
Last Updated: November 2025
*Built with ❤️ by Vendotha
Demonstrating clean code, scalable architecture, and modern development practices