Behind the Tech: Engineering the Core Infrastructure for AI Crypto Investo

Behind the Tech: Engineering the Core Infrastructure for AI Crypto Investo

Published on May 17, 2026

At Qudex, we don't just build web applications; we engineer highly secure, transactional ecosystems capable of handling complex financial logic at scale. For our flagship project, AI Crypto Investo, the engineering mandate was clear yet ambitious: deliver a high-yield investment platform offering a 7.5% daily return (up to a 2x hard cap) paired with an automated, 5-level deep referral matrix.

When you combine high-frequency yield calculations with a multi-level referral network, standard database queries and basic API routes quickly fall apart under the weight of recursive overhead.

This post takes you behind the scenes of how we architected AI Crypto Investo using a single-app full-stack model, decoupled offline workers, and atomic database state management.




The Architectural Blueprint

The platform is split into three distinct service pillars, each optimized for its specific operational role:


Uploaded image



1. User Dashboard (The Core Application)

Built as a unified, full-stack application using Next.js 15.5.9 (App Router) and React 19.1.0. It handles identity management, multi-investment tracking, crypto payment uploads (including manual screenshot verification staging), and account nesting.

2. Admin Dashboard

An isolated management layer using the same core stack that gives system administrators real-time oversight of user states, investment tiers, payment asset verifications, and withdrawal pipelines.

3. CronJobs Service

A headless, standalone Node.js + TypeScript worker. It runs entirely outside the HTTP request/response path, strictly handling the daily midnight calculations for ROI accruals and multi-level referral commissions.




Architectural Breakthroughs: Solving the "Aha!" Challenges

Building high-yield financial tech means preparing for worst-case scenarios: race conditions, double-spending, and database locking from deep network lookups. Here is how we solved the biggest structural bottlenecks.


Breakthrough #1: Eliminating Recursive Tree Overhead via Staged Referrals

In a standard referral system, calculating commissions requires recursively walking up a database tree (User A <- User B <- User C). If thousands of investments happen simultaneously, these recursive lookups will choke your database.

Our solution? Deferred Referral Commitment.

When a user signs up, their referral structure is placed into a temporary staging table (UnverifiedReferral). The referral network is only materialized after they successfully verify their email. Our verification system enforces a strict 10-minute secure token expiry window to protect against fraud.

Once verified, the system constructs a bounded 5-level chain and materializes it into a denormalized ReferralNetwork table.


// Bounded chain discovery & denormalized network insertion
const referralChain: string[] = [];
let currentId = getReferral.parentId;

while (currentId && referralChain.length < 5) {
referralChain.push(currentId);
const parentUser = await db.user.findUnique({
where: { id: currentId },
select: { referredBy: true }
});
if (!parentUser?.referredBy) break;
currentId = parentUser.referredBy;
}


By pre-calculating the exact level and commission rate for up to 5 levels deep, we turned an expensive recursive traversal problem into a series of blistering-fast, deterministic reads. Unique constraints on the schema level (@@unique([ownerId, level, position])) structurally enforce a maximum cap of 5 children per level node.


Breakthrough #2: Bulletproof Balance Integrity via Atomic Multi-Writes

When a user reinvests their daily ROI or tops up a child account, multiple records must change simultaneously: one wallet balance decrements, another increments, and a new investment record is initialized. If the server drops its connection halfway through, the database enters a corrupted state.

To prevent partial updates, the AI Crypto Investo backend wraps all financial state alterations inside an atomic Prisma transaction (db.$transaction).


await db.$transaction(async (tx) => {
    // 1. Safely decrement source wallet balance
    await tx.user.update({
        where: { id: existingUser.id },
        data: { walletBalance: { decrement: amount } }
    });


    // 2. Safely increment target balance and attach an active investment
    await tx.user.update({
        where: { id: topUpAccount.id },
        data: {
            walletBalance: { increment: amount },
            totalInvested: { increment: amount },
            investments: {
                create: {
                    amount: amount,
                    status: "ACTIVE",
                    targetAmount: amount * 2, // 2x Cap enforcement
                    startDate: new Date(),
                }
            }
        }
    });
});


If any single step fails, the entire operation rolls back completely. No ghost balances, no lost currency.




The Financial Distribution Engine (Cron Service)

The heartbeat of AI Crypto Investo is its background engine. Running every night at midnight (configured to Europe/Moscow time via node-cron), this service updates user balances using an auditable, ledger-like architectural pattern.


1. Hard-Capped Investment Accruals
The system loops over active investments and applies the daily return. To prevent over-allocations, the engine checks if the new return meets or exceeds the 2x target amount. If it does, the payout is capped precisely to the remaining target balance, and the investment status transitions to COMPLETED.


2. Multi-Level Commission Gating
When a child node generates an ROI return, the commission cascades up to 5 levels of root accounts. However, users can't just sit back and collect passive income without participating. The engine enforces Direct Referral Threshold Rules at the database layer:


Matrix Level

Commission on Child's ROI

Minimum Direct Referrals Required to Qualify

Level 1

10%

5 Direct Referrals

Level 2

7.5%

5 Direct Referrals


If a root account has only 3 direct referrals, the engine automatically skips them when calculating Level 4 and Level 5 commissions. This maintains the economic sustainability of the ecosystem.




The Core Modern Tech Stack

To provide context on our infrastructure choices, here is a quick look at the core dependencies powering this setup:

  • Framework Architecture: Next.js 15.5.9 (App Router) combined with React 19.1.0 for seamless Server Components alongside client side interactions.
  • Database Management: Prisma 6.16.2 targeting MongoDB, utilizing strict time-series indexing on DailyReturn and explicit unique compound indexes on membership edges.
  • Security & Comms: NextAuth v5 (Beta) using a secure JWT session strategy with an integrated Prisma adapter; transactional emails are offloaded to Resend.
  • Design Language: Tailwind CSS v4 paired with shadcn/ui (Radix primitives) to implement a unified, dark-mode, responsive dashboard environment utilizing native CSS variables.




Moving Forward with Qudex

By shifting performance-heavy matrix evaluation to email verification time, sealing financial pathways inside database transactions, and separating calculation pipelines into background cron workers, AI Crypto Investo stands as a robust blueprint for modern web applications.

We look forward to sharing more insights from the production trenches as Qudex continues to deploy highly polished, enterprise-ready software.


Ready to scale?

Set up a discovery call with our experts to discuss how Qudex can elevate your digital infrastructure. No strings attached.