Skip to content

About

An enterprise-grade, high-performance web dashboard application for automated decentralized yield distribution tracking, active investment auditing, and deep multi-level recursive referral network mapping.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

133 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ YieldNexus - Investment & Referral Dashboard Platform (MERN Stack Developer Assessment)

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.


πŸ› οΈ Architecture & Core Tech Stack

This project is built using a clean, modern architecture separating the backend API service from a highly responsive React client dashboard.

Backend API Architecture (/server)

  • Runtime & Language: Node.js with TypeScript, running dynamically in development via tsx and compiled using tsc.
  • 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).

Client Dashboard Architecture

  • 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

βš™οΈ Environment Configurations

Set up your project environment keys by creating a .env file in both the server and client folders.

πŸ”Œ Backend Environment Configuration (/server/.env)

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=7d

πŸ’» Client Environment Configuration (/client/.env)

Create a .env file inside the client root:

VITE_SERVER_URL=http://127.0.0.1:8000/api/v1

πŸš€ Local Installation & Execution Steps

1. Project Initialization

Clone the repository: https://github.com/pr4x9s/yieldnexus.git

2. Launch the Backend API Instance

cd server
pnpm i
pnpm run dev

The server will start up and listen securely on the configured port (e.g., port 8000).

3. Launch the React UI Framework Workspace in Another Terminal

cd client
bun i
bun run dev

Open your browser to the designated network IP provided by Vite to review the dashboard application flow.


πŸ“¦ Script Manifest

Backend Commands (/server/package.json)

  • pnpm run dev: Launches the server in development mode using tsx --watch to 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.

Client Commands (/client/package.json)

  • 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.


πŸ“ˆ Key Architecture & Design Decisions

πŸ”„ Multi-Level Referral Hierarchy Engine

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.

πŸ›‘οΈ Idempotent Daily ROI Cron Job Scheduler

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.

⚑ Optimized Client Data Tables (TanStack Table)

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.


πŸ“‹ Core API Endpoint Documentation

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

Sample Request and Response Data Here


πŸ’‘ Development Assumptions Made

  1. Fixed Daily Yields: Investment contract yields are assigned standard baseline rates when a plan is opened, rather than evaluating live variable index updates.
  2. 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.
  3. 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.

File/Folder Structure

.
β”œβ”€β”€ 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

About

An enterprise-grade, high-performance web dashboard application for automated decentralized yield distribution tracking, active investment auditing, and deep multi-level recursive referral network mapping.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages