Skip to content

Containers (C4 Level 2)

This page describes the second level of the C4 model - the Container diagram. It shows the high-level technical building blocks that make up the Switchain Services system.

Container Architecture

The Switchain Services system consists of the following containers (high-level components):

Frontend Applications

  • Admin Application (Next.js, React): Provides administration interface for managing the platform

API Services

  • Rates API (Bun, Elysia): API for exchange rate calculations

Background Workers

  • Wallets Worker (Bun, BullMQ): Background worker for wallet operations
  • Common Worker (Bun, BullMQ): Background worker for general tasks

Monitoring

  • Bull Board (Bun, Elysia): Dashboard for monitoring background jobs

Data Storage

  • Database (PostgreSQL): Stores user data, transactions, and system configuration
  • Redis: Used for caching and job queues

External Systems

  • Blockchain Networks: Various blockchain networks (Bitcoin, Ethereum, etc.)
  • Exchange Rate APIs: External services providing cryptocurrency exchange rates
  • KYC Provider: External service for identity verification

Key Interactions

  1. User Interactions:

    • Administrators use the Admin Application and Bull Board via HTTPS
  2. Admin Application:

    • Uses Rates API via HTTPS/REST
    • Reads from and writes to the Database via SQL/Prisma
  3. Rates API:

    • Reads from and writes to the Database via SQL/Prisma
    • Gets rates from Exchange Rate APIs via HTTPS/REST
  4. Wallets Worker:

    • Reads from and writes to the Database via SQL/Prisma
    • Consumes jobs from Redis
    • Sends transactions to Blockchain Networks via RPC/API
  5. Common Worker:

    • Reads from and writes to the Database via SQL/Prisma
    • Consumes jobs from Redis
    • Verifies identity using KYC Provider via HTTPS/REST
  6. Bull Board:

    • Reads job status from Redis

Key Containers

Frontend Applications

  • Admin Application: A Next.js web application that provides an administrative interface for managing the platform.

API Services

  • Rates API: Manages exchange rate calculations and provides rate information.

Background Workers

  • Wallets Worker: Processes wallet-related background jobs like transaction monitoring and wallet creation.
  • Common Worker: Handles general background tasks like notifications and data processing.

Monitoring

  • Bull Board: Provides a dashboard for monitoring and managing background jobs.

Data Storage

  • Database: PostgreSQL database that stores user data, transactions, and system configuration.
  • Redis: Used for caching and as a message broker for job queues.

Container Interactions

The containers interact with each other and with external systems in the following ways:

  1. User Interactions:

    • Administrators use both the Admin Application and Bull Board
  2. Internal Communications:

    • APIs read from and write to the Database
    • APIs publish jobs to Redis queues
    • Workers consume jobs from Redis queues
    • Admin Application communicates with APIs
  3. External Communications:

    • Wallets Worker interacts with Blockchain Networks
    • Rates API communicates with Exchange Rate APIs
    • Common Worker interacts with KYC Provider

Technology Choices

  • Frontend: Next.js, React
  • Backend: Bun runtime with Elysia framework
  • Background Processing: BullMQ
  • Data Storage: PostgreSQL, Redis
  • ORM: Prisma

Next Steps

After understanding the containers that make up the system, you can dive deeper into the Component diagram to see the internal components of each container.