SwiftX LogoSwiftX

Architecture

Understanding the internals of SwiftX.

Architecture

SwiftX is designed to be high-performance and modular. It consists of several key components that work together to handle requests efficiently.

Core Runtime: SwiftXCore

The heart of SwiftX is the SwiftXCore runtime. This is an ultra-lean foundation that provides the essential primitives for non-blocking I/O and task management.

  • Managed Worker Pool: A co-operative tasking system that moves away from traditional thread-per-request models.
  • Custom Scheduler: Optimized for high-throughput and low-latency workloads.

The Routing Engine: RadixRouter

Routing in SwiftX is handled by a high-performance Radix Tree.

  • O(k) Performance: The routing time is proportional only to the length of the path, not the number of routes.
  • Pattern Matching: Supports static paths, path parameters (:id), and wildcards (*).

Plugin System

SwiftX is entirely plugin-driven. Even core functionality like JSON handling or sessions can be implemented as plugins.

  • Modularity: Keep your app lean by only including the plugins you need.
  • Interoperability: Easily share plugins across different SwiftX projects.

Lifecycle of a Request

  1. Connection: A client connects to the server.
  2. Matching: The RadixRouter matches the request path to a handler.
  3. Task Creation: A new TaskContext is created in the Managed Worker Pool.
  4. Execution: The handler is executed asynchronously.
  5. Response: The response is buffered and sent back to the client.

Concurrency and Async

SwiftX is built for Swift Concurrency. Handlers can be async and can safely call other async/await code without blocking the main worker threads.

On this page