Skip to content

Cubex Backend Overview

Introduction

This backend system powers a financial platform that allows users to manage their funds, perform cryptocurrency transactions, and interact with various banking services. The backend is responsible for handling all user interactions securely and efficiently, ensuring smooth and reliable operations across different modules.

System Design Goals

The system is designed to:

  • Securely manage user data and transactions by using authentication methods and ensuring privacy
  • Enable cryptocurrency operations, including creating wallets, managing balances, and converting crypto to Naira
  • Facilitate seamless transfers, whether within the platform or to external Nigerian bank accounts
  • Handle errors and notifications via logging mechanisms and webhook processing, keeping users and administrators informed about transaction statuses

By modularizing these functions, the platform ensures that each aspect works independently but contributes to the overall experience, creating a scalable and user-friendly system.

Technologies Used

  • GitHub Actions
    This tool automates workflows for continuous integration (CI) and continuous deployment (CD). It ensures that code is automatically tested and deployed as soon as changes are made.

  • Husky
    Husky helps maintain code quality by running automated tests whenever code is committed or pushed to GitHub.

  • Cloudflare D1 Database
    This is the platform's main database, where all data is stored and managed.

  • Cloudflare Workers
    Cloudflare Workers provide a serverless environment for running code without managing servers. It allows you to build or enhance applications without worrying about infrastructure.

  • Node.js
    Node.js is a runtime environment that allows developers to run JavaScript on the server side. It works across different operating systems like Windows, Linux, and macOS, and is used to build scalable and efficient web applications.

  • TypeScript
    TypeScript is a free programming language created by Microsoft. It builds on JavaScript by adding a feature called static typing, which helps developers catch errors early by checking the types of variables. This makes it easier to manage large applications. TypeScript code is then converted back into regular JavaScript, allowing it to run in any web browser or environment that supports JavaScript.

Feature Configs

Feature Configs are configuration settings used to control specific features in the mobile app. They include:

  • cubex-version: Holds the latest version of the mobile app, used to inform users when they need to update from a previous version

  • cryptowarnings: Provides warnings to users about certain cryptocurrencies, such as minimum deposit limits for BTC

  • settings: Contains contact information, including email, phone number, links to the chat page, terms and conditions page, banner messages, and the Cubex logo

  • max_naira_withdrawal: Specifies the maximum amount of Naira a user can transfer based on their user level (e.g., Level 1 or Level 2), including transfer limits and daily limits

  • cronjob: Defines tasks to be executed at certain intervals, such as sending notifications about liquidation amounts

  • can_sell_crypto: A feature flag that restricts all users from selling cryptocurrency for Naira; if disabled, users will be unable to sell crypto

  • can_transfer: A feature flag that restricts all users from making any transfers; if disabled, users will be unable to execute transfers

  • banned_list: Contains emails of users who have been blacklisted

  • splash_screen: Includes the splash screen text and links to splash screen images

  • utilities: Lists utilities and their providers, such as MTN and Airtel

Project Structure

/project-root
├── /src         # Source files for the application
│   ├── _lib     # Custom libraries and functions
│   ├── admin    # Allows administrators to manage the platform
│   ├── auth     # Handles user authentication
│   ├── cryptos  # Manages cryptocurrency operations
│   ├── durableObjects    # Ensures single instance for each user request
│   └── featureflags     # Controls feature settings
│   └── middlewares     # Checks user authentication
│   ├── payment  # Handles payments and transfers
│   ├── transferAccounts  # Manages user transfer accounts
│   ├── user     # Manages user profiles and details
│   ├── wallet   # Tracks rewards and wallet transactions
│   ├── webhooks # Manages notifications from external systems
├── /routes.ts   # Endpoints are defined here
├── /worker.ts   # Entrypoint