This project was created with Better-T-Stack, a modern TypeScript stack that combines React, TanStack Router, Hono, TRPC, and more.
- TypeScript - For type safety and improved developer experience
- TanStack Router - File-based routing with full type safety
- TailwindCSS - Utility-first CSS for rapid UI development
- shadcn/ui - Reusable UI components
- Hono - Lightweight, performant server framework
- tRPC - End-to-end type-safe APIs
- Bun - Used as Runtime, Bundler, Test Runner and File server
- Drizzle - TypeScript-first ORM
- PostgreSQL - Database engine
- Authentication - Better-Auth
- Turborepo - Optimized monorepo build system
- PGLite - In memory postgres instance for easily running integration tests
- Caddy Docker Proxy - Docker based reverse proxying. No Caddy or Nginx files laying around the repo
- Github Actions - For CI/CD, deployments to vps and automatically running tests
- Cloudflare - DNS and Proxying
- NixOS - Hetzner Based Linux NixOS instance for easy server and user init
- Docker - Orchestration of separate services
First, install the dependencies:
bun installThis project uses PostgreSQL with Drizzle ORM.
-
Make sure you have a PostgreSQL database set up.
-
Update your
apps/server/.envfile with your PostgreSQL connection details. -
Apply the schema to your database:
bun db:pushThen, run the development server:
bun devOpen http://localhost:3001 in your browser to see the web application. The API is running at http://localhost:3000.
takehome/
├── apps/
│ ├── web/ # Frontend application (React + TanStack Router)
│ └── server/ # Backend API (Hono, TRPC)
├── packages/
│ ├── api/ # API layer / business logic
│ ├── auth/ # Authentication configuration & logic
│ └── db/ # Database schema & queries
bun dev: Start all applications in development modebun build: Build all applicationsbun dev:web: Start only the web applicationbun dev:server: Start only the serverbun check-types: Check TypeScript types across all appsbun db:push: Push schema changes to databasebun db:studio: Open database studio UIbun test: Run Tests
- GET /api/referral/generate - generates unique code and ensures idempotency
- GET /api/referral/getMyCode - get authenticated user's referral code
- GET /api/referral/validateCode - validates referral code for registration
- POST /api/referral/register - register user with referral code
- GET /api/referral/trades - Get trades with commision breakdown
- GET /api/referral/network - Get user's referral network
- GET /api/referral/getDownlineTree - Get detailed downline tree
- GET /api/referral/earnings - Get earnings summary for authenticated user
- GET /api/referral/earningsHistory - Get earnings history with pagination
- GET /api/referral/getClaimable - get claimable earnings
- POST /api/referral/claimCommissions - claim individual commisions
- POST /api/referral/claimCashback - claims cashback
- POST /api/referral/claim - Claim all unclaimed earnings of a particular token type
- POST /api/webhook/trade - Simulates trading activity and comission distribution
- Sign in, use referral code if avaliable,it is possible to make multiple accounts to test commission feature
- Go to Dashboard or /referral
- From here you can access referral/network, referral/earnings, referral/trades and referral/test frontend routes by clicking tabs on top portion of dashboard
- Select Trade parameters and press Create Trade button to simulate trading with commission fee splits
- Claim earnings/commissions on earnings