FinTech
Tetraaaa: Binary MLM Network Platform with Automated Placement, Level Credits & Direct Referral Tiers
Binary MLM network platform — automated tree placement, level-by-level credit distribution on every join, nightly referral bonus tiers with no double-awards, and a Next.js public storefront.
Next.js
Node.js
PostgreSQL
Tailwind CSS
TypeScript
10
Binary Tree Depth Levels — Full Network Scale Supported
100
Credits Distributed Per Upline Level on Every New Member Join
Instant
Automated Credit Distribution Triggered on Every Join Event
The Problem
MLM Platforms Require Complex Automated Logic at Every Join Event — Manual Operations Don't Scale
Network marketing platforms require complex, rules-driven logic at every join event: where in the binary tree does the new member go? Who gets paid, and how much? How is the credit pool tracked to prevent over-distribution? How are direct referral bonus tiers computed without double-awarding across monthly cron cycles?
Building this on a Node.js stack required a custom automated tree placement engine, a sale-pool-based credit sourcing system, an admin fallback for underfunded positions, and a high-water mark bonus system for direct referral package upgrades — all with Sequelize ORM and PostgreSQL.
Our Solution
Automated Tree Placement Engine, Sale-Pool Credit Distribution, and Nightly Package Rewards
We built Tetraaaa with a Node.js + Express backend using Sequelize ORM on PostgreSQL.
The automated placement engine starts from the root of the network tree, scans for the first available position from left to right, skips any positions already at maximum depth, and places the new user instantly — recording their position with a full parent chain and purchase history. Immediately after placement, the upline reward engine walks up the parent chain, calling creditUserOrAdmin at each level: if the target user has a Sale record with (sale_amount - reward_distributed) >= amount, the amount is drawn from that pool; otherwise the admin is charged and an AdminRewardLog entry records the reason (sale_limit_exceeded or no_sale_row).
The directReferralCron uses a mutex flag to prevent overlapping runs, seeds default packages on startup via findOrCreate, then processes all due users: for each, it fetches all direct referrals and their most recent sale amounts via a single DISTINCT ON batch query, evaluates against packages sorted ascending by tier, finds the highest qualifying package, computes the delta against referral_bonus_credits (the high-water mark), and adds only the incremental difference — preventing double-awarding on tier advances.
Withdrawal requests deduct credits immediately at submission; rejection refunds credits back. Admin getDashboardTotals runs four parallel aggregate queries in a single response for the overview cards.
Architecture
Backend: Node.js + Express + Sequelize ORM + PostgreSQL. JWT authentication (bcrypt hashed passwords). node-cron direct referral package job (configurable CRON env). Parallel admin aggregate queries for dashboard overview. DISTINCT ON SQL batch query for referral sale amounts. JSONB product images. ARRAY product IDs. ENUM user roles and withdrawal statuses. Frontend: Next.js 14 App Router + React + Tailwind CSS. Public storefront + admin dashboard + user wallet.
The Result
Fully Automated MLM — Tree Placement, Credits, and Referral Tiers With Zero Manual Input
Tetraaaa automated every manual step of the MLM network operation: new member placement via the automated tree engine found and filled the first vacant position in the binary tree instantly — no admin action required. Level-by-level credit distribution ran immediately at join time, crediting up to 10 upline levels from the new member's position in a single chain walk.
The sale-pool credit sourcing model prevented over-distribution by design — credits are drawn from the target user's undistributed sale balance, with admin fallback and full AdminRewardLog audit entries when the pool was insufficient. The nightly direct referral cron advanced users through bonus package tiers automatically using a high-water mark system — users were never double-awarded as they crossed tier boundaries.
The admin dashboard's tree visualisation let operators drill down through the binary network depth-by-depth. The withdrawal management system with credit deduction on request and automatic credit refund on rejection gave admins complete financial control. The Next.js 14 public storefront gave members a branded product purchase experience tied directly to their network.
Want scalable architecture and measurable results like this?
Book an Architecture Audit
Build Something Like This
// free scoping call · senior engineers · no commitment
Project scope, timelines, and architecture options in one 45-minute session.
More Work