A complete MERN stack application featuring secure user authentication, an automated daily ROI distribution engine, a live profit history tracker, and a dynamic multi-level referral network system.
This project is built using a clean, modern architecture separating the backend API service from a highly responsive React client dashboard.
- Runtime & Language: Node.js with TypeScript, running dynamically in development via
tsxand compiled usingtsc. - Framework & Database: Express.js paired with MongoDB using Mongoose schemas, custom data models, and database indexing.
- Automation: Automated backend scripts run automatically at scheduled intervals using
node-cron. - Validation & Security: Strict data validation via Zod, secure password hashing using
bcrypt, and stateless user sessions secured by double-token JWT authentication(jsonwebtoken). - API Documentation: Interactive API exploration docs built directly with Swagger UI (
swagger-ui-express).
- Core Framework: React 19 with TypeScript, bundled and served instantly using Vite with basic SSL support.
- State & Data Synchronization: Server data synchronization, state tracking, and background caching are handled by TanStack Query alongside Axios. Local UI states are managed via Zustand.
- Data Grid Tables: Advanced history logs are structured with TanStack Table v8, powering instant text searches, status tab filtering, and smooth frontend pagination.
- UI Styling & Charts: Styled with Tailwind CSS v4 and Lucide React icons, featuring responsive performance charts powered by Recharts
Set up your project environment keys by creating a .env file in both the server and client folders.
Create a .env file inside the server root based on the provided configuration samples:
PORT=8000
MONGODB_URI=mongodb+srv://username:password@clusterN.abcdefg.mongodb.net/nexachain
CORS_ORIGIN=http://127.0.0.1:5173
ACCESS_TOKEN_SECRET=your_access_token_secret_string
ACCESS_TOKEN_EXPIRY=15m
REFRESH_TOKEN_SECRET=your_refresh_token_secret_string
REFRESH_TOKEN_EXPIRY=7dCreate a .env file inside the client root:
VITE_SERVER_URL=http://127.0.0.1:8000/api/v1Clone the repository: https://github.com/pr4x9s/yieldnexus.git
cd server
pnpm i
pnpm run devThe server will start up and listen securely on the configured port (e.g., port 8000).
cd client
bun i
bun run devOpen your browser to the designated network IP provided by Vite to review the dashboard application flow.
-
pnpm run dev: Launches the server in development mode usingtsx --watchto reload automatically when code changes. -
pnpm run start: Runs the pre-compiled production build of the server. -
pnpm run build: Compiles the TypeScript backend files into clean JavaScript code. -
pnpm run type-check: Runs the TypeScript compiler in watch mode to highlight layout or type errors immediately without outputting code.
-
bun run dev: Boots the Vite engine running exposed host variables. -
bun run build: Compiles production modules checking script paths and compressing static bundle outputs. -
bun run preview: Stages production-ready code locally inside standard deployment tracking layouts.
The backend uses a recursive loop lookup algorithm to handle downline rewards. When a new user signs up or performs an activity, the backend automatically traverses up the account hierarchy tree, calculating and distributing accurate network level bonuses to eligible parent accounts across multiple tiers.
The automated yield scheduler runs on a daily cron loop configured via node-cron, executing automatically at 12:00 AM every night. To protect data integrity and prevent errors, the script has a strict idempotency check:
- Before any wallet balance is incremented, the server checks the history database for an existing ROI log matching the active investment ID and the current date.
- If the cron job triggers multiple times on the same calendar day by mistake, the script catches it immediately, skips duplicate calculations, and terminates safelyβguaranteeing users are never credited twice.
To keep network payloads small and avoid putting unnecessary heavy filtering loads on the database, the history endpoints stream simple data arrays directly to the client side. The user dashboard filters rows by status tabs, searches by matching text string targets, and paginates records locally using TanStack Table's internal engines. This delivers zero-latency updates for the user without making repeated API network requests.
Private endpoints require a valid authorization bearer token passed in the request header (Authorization: Bearer <token>).
Also available as Swagger OpenAPI Docs at /docs and Postman Collection.
| Method | Endpoint Route | Security | Description |
|---|---|---|---|
| POST | /users/register |
Public | Registers a new user account and links them to their referrer. |
| POST | /users/login |
Public | Verifies credentials, manages session tracking, and returns tokens. |
| POST | /users/logout |
Protected | Clears secure cookies and destroys the active token session. |
| POST | /users/refresh-token |
Public | Evaluates refresh tokens to issue new short-lived access tokens. |
| POST | /investments/create-investment |
Protected | Creates a new investment contract plan using available wallet balance. |
| GET | /investments/get-my-investments |
Protected | Fetches all active, completed, or cancelled investment contracts for the user. |
| GET | /investments/get-roi-history |
Protected | Fetches the historical log of all daily ROI payouts received by the user. |
| GET | /dashboard/stats |
Protected | Returns core KPIs including wallet balance, total investments, and earnings totals. |
| GET | /referrals/direct-refs |
Protected | Fetches the first-line direct user referrals list with engagement stats. |
| GET | /referrals/comp-ref-tree |
Protected | Calculates and returns a structured object mapping the multi-level downline tree. |
| GET | /referrals/get-referral-income-history |
Protected | Audits chronological log of commissions earned from downline registrations. |
| POST | /admin/payout/trigger |
Protected (Admin) | Testing Utility Only: Manually triggers the automated daily cron distribution cycle. |
Sample Request and Response Data Here
- Fixed Daily Yields: Investment contract yields are assigned standard baseline rates when a plan is opened, rather than evaluating live variable index updates.
- Client-Side History Operations: For early scalability, list history data is streamed fully to the client, allowing TanStack Table to handle sorting, status tabs, and row pagination locally in memory for maximum rendering performance.
- Standalone Data Layer: The database architecture relies on core MongoDB transaction patterns and model indexes without requiring separate caching systems to simplify local setup and code evaluation.
.
βββ client
βΒ Β βββ bun.lock
βΒ Β βββ eslint.config.js
βΒ Β βββ index.html
βΒ Β βββ package.json
βΒ Β βββ public
βΒ Β βΒ Β βββ favicon.svg
βΒ Β βΒ Β βββ icons.svg
βΒ Β βββ README.md
βΒ Β βββ src
βΒ Β βΒ Β βββ api
βΒ Β βΒ Β βΒ Β βββ api.ts
βΒ Β βΒ Β βΒ Β βββ auth.service.ts
βΒ Β βΒ Β βΒ Β βββ dashboard.service.ts
βΒ Β βΒ Β βΒ Β βββ investment.service.ts
βΒ Β βΒ Β βββ App.tsx
βΒ Β βΒ Β βββ assets
βΒ Β βΒ Β βΒ Β βββ hero.png
βΒ Β βΒ Β βΒ Β βββ react.svg
βΒ Β βΒ Β βΒ Β βββ vite.svg
βΒ Β βΒ Β βββ components
βΒ Β βΒ Β βΒ Β βββ common
βΒ Β βΒ Β βΒ Β βΒ Β βββ ConfirmationModal.tsx
βΒ Β βΒ Β βΒ Β βββ dashboard
βΒ Β βΒ Β βΒ Β βΒ Β βββ AnalyticsChart.tsx
βΒ Β βΒ Β βΒ Β βΒ Β βββ ReferralTable.tsx
βΒ Β βΒ Β βΒ Β βΒ Β βββ ReferralTree.tsx
βΒ Β βΒ Β βΒ Β βΒ Β βββ StatCards.tsx
βΒ Β βΒ Β βΒ Β βββ investments
βΒ Β βΒ Β βΒ Β βΒ Β βββ CreateInvestment.tsx
βΒ Β βΒ Β βΒ Β βΒ Β βββ InvestmentList.tsx
βΒ Β βΒ Β βΒ Β βββ layout
βΒ Β βΒ Β βΒ Β βΒ Β βββ Navbar.tsx
βΒ Β βΒ Β βΒ Β βΒ Β βββ Sidebar.tsx
βΒ Β βΒ Β βΒ Β βββ layouts
βΒ Β βΒ Β βΒ Β βΒ Β βββ AuthLayout.tsx
βΒ Β βΒ Β βΒ Β βΒ Β βββ DashboardLayout.tsx
βΒ Β βΒ Β βΒ Β βββ profitHistory
βΒ Β βΒ Β βΒ Β βββ ReferralIncomeList.tsx
βΒ Β βΒ Β βΒ Β βββ RoiHistoryList.tsx
βΒ Β βΒ Β βββ conf
βΒ Β βΒ Β βΒ Β βββ conf.ts
βΒ Β βΒ Β βββ hooks
βΒ Β βΒ Β βΒ Β βββ useDashboardData.ts
βΒ Β βΒ Β βΒ Β βββ useInvestments.ts
βΒ Β βΒ Β βΒ Β βββ useLogin.ts
βΒ Β βΒ Β βΒ Β βββ useLogout.ts
βΒ Β βΒ Β βΒ Β βββ useRegister.ts
βΒ Β βΒ Β βββ index.css
βΒ Β βΒ Β βββ main.tsx
βΒ Β βΒ Β βββ pages
βΒ Β βΒ Β βΒ Β βββ index.ts
βΒ Β βΒ Β βΒ Β βββ Login.tsx
βΒ Β βΒ Β βΒ Β βββ protected
βΒ Β βΒ Β βΒ Β βΒ Β βββ Home.tsx
βΒ Β βΒ Β βΒ Β βΒ Β βββ Investments.tsx
βΒ Β βΒ Β βΒ Β βΒ Β βββ ProfitHistory.tsx
βΒ Β βΒ Β βΒ Β βββ Register.tsx
βΒ Β βΒ Β βββ providers
βΒ Β βΒ Β βΒ Β βββ AuthProvider.tsx
βΒ Β βΒ Β βββ store
βΒ Β βΒ Β βΒ Β βββ authStore.ts
βΒ Β βΒ Β βΒ Β βββ themeStore.ts
βΒ Β βΒ Β βββ types
βΒ Β βΒ Β βΒ Β βββ types.ts
βΒ Β βΒ Β βββ utils
βΒ Β βΒ Β βΒ Β βββ cn.ts
βΒ Β βΒ Β βΒ Β βββ format.ts
βΒ Β βΒ Β βββ validators
βΒ Β βΒ Β βββ auth.validator.ts
βΒ Β βΒ Β βββ investment.validator.ts
βΒ Β βββ tsconfig.app.json
βΒ Β βββ tsconfig.json
βΒ Β βββ tsconfig.node.json
βΒ Β βββ vite.config.ts
βββ README.md
βββ server
βββ nexachain-mern-assessment.postman_collection.json
βββ package.json
βββ pnpm-lock.yaml
βββ pnpm-workspace.yaml
βββ public
βββ README.md
βββ src
βΒ Β βββ app.ts
βΒ Β βββ conf
βΒ Β βΒ Β βββ conf.ts
βΒ Β βββ constants.ts
βΒ Β βββ controllers
βΒ Β βΒ Β βββ admin.controller.ts
βΒ Β βΒ Β βββ dashboard.controller.ts
βΒ Β βΒ Β βββ investment.controller.ts
βΒ Β βΒ Β βββ referral.controller.ts
βΒ Β βΒ Β βββ user.controller.ts
βΒ Β βββ db
βΒ Β βΒ Β βββ index.ts
βΒ Β βββ middlewares
βΒ Β βΒ Β βββ auth.middleware.ts
βΒ Β βΒ Β βββ error.middleware.ts
βΒ Β βΒ Β βββ validate.middleware.ts
βΒ Β βββ models
βΒ Β βΒ Β βββ investment.model.ts
βΒ Β βΒ Β βββ referralIncome.model.ts
βΒ Β βΒ Β βββ roiHistory.model.ts
βΒ Β βΒ Β βββ user.model.ts
βΒ Β βββ routes
βΒ Β βΒ Β βββ admin.route.ts
βΒ Β βΒ Β βββ dashboard.route.ts
βΒ Β βΒ Β βββ index.ts
βΒ Β βΒ Β βββ investment.route.ts
βΒ Β βΒ Β βββ referral.route.ts
βΒ Β βΒ Β βββ user.route.ts
βΒ Β βββ server.ts
βΒ Β βββ services
βΒ Β βΒ Β βββ cron.service.ts
βΒ Β βΒ Β βββ payout.service.ts
βΒ Β βββ types
βΒ Β βΒ Β βββ auth.d.ts
βΒ Β βΒ Β βββ types.ts
βΒ Β βββ utils
βΒ Β βΒ Β βββ ApiError.ts
βΒ Β βΒ Β βββ ApiResponse.ts
βΒ Β βΒ Β βββ asyncHandler.ts
βΒ Β βββ validators
βΒ Β βββ auth.validator.ts
βΒ Β βββ investment.validator.ts
βββ swaggerOpenapiDocs.yaml
βββ tsconfig.json