Airframe Documentation

repository·main·Indexed 20 days ago

https://github.com/wvlet/airframe

A collection of essential building blocks for Scala application development. Airframe provides a suite of libraries including a dependency injection (DI) framework, airframe-config for YAML and properties-based configuration, airframe-codec for MessagePack-based serialization, airframe-canvas for managing large off-heap memory regions, and airframe-control for simplifying control flow.

Tokens
73.9K
Snippets
289
Records
338
Agent score
71%

What's inside Airframe

  1. Overview of Airframe capabilities

    main

    Airframe provides essential building blocks for Scala application development. Its core features include:

    • Logging: Standardized logging utilities.
    • Object Serialization: Support for JSON and MessagePack.
    • Dependency Injection (DI): A DI library specifically tailored for Scala.
    • HTTP & RPC: HTTP server and client capabilities with RPC support, enabling Scala to be used for both frontend and backend programming.
    • Functional Testing: Provided via the AirSpec library.
  2. Overview of airframe-codec

    main

    airframe-codec is a MessagePack-based schema-on-read data transcoder designed for Scala and Scala.js. It enables efficient serialization and deserialization of Scala objects and provides flexible data conversion capabilities.

    Key features include:

    • Object Serialization/Deserialization: Encode and decode Scala objects (such as case classes and collections) to and from MessagePack format.
    • JDBC Integration: Convert JDBC result sets into MessagePack.
    • Custom Codecs: Extend functionality by implementing your own pack/unpack logic.
    • Schema-on-Read: Automatically convert data types during decoding if the target schema requires it. For example, string representations of numbers (e.g., "1", "2") can be automatically converted to integers if the target Scala object expects integer values.
  3. Overview of airframe-http

    main

    airframe-http is a library designed for creating HTTP web servers with ease. It provides a low-friction approach to building web services in Scala.

    Key components:

    • airframe-http: The core library for HTTP server creation.
    • airframe-http-finagle: An extension that allows you to use Finagle as the underlying HTTP server backend.
  4. What is airframe-canvas and when to use it

    main

    airframe-canvas is a library designed to manage large off-heap memory regions (called Canvas) that exceed the 2GB ($2^{31}$ bytes) limit of standard JVM byte arrays.

    Key benefits include:

    • Bypassing JVM limits: Allocate memory regions larger than the -Xmx JVM heap setting.
    • Performance: Avoids the CPU cost of zero-filling when initializing arrays.
    • Memory Management: Allows for quick manual release of memory via Canvas.release (or close()), and provides a safety net where memory is released during Garbage Collection (GC) even if not manually released.
  5. Overview of AirSpec

    main

    AirSpec is a functional testing framework designed for Scala and Scala.js. It leverages pure Scala functions for writing test cases, minimizing the learning curve for Scala developers.

    Key features include:

    • Test cases written using pure Scala functions.
    • Optional support for dependency injection in test cases.
    • Optional support for property-based testing.
  6. Overview of Airframe core frameworks

    main

    Airframe provides several core frameworks for building applications across Scala, Scala.js, and Scala Native:

    • Airframe DI: Dependency Injection.
    • Airframe RPC: A framework for using Scala for both Frontend and Backend programming (built on top of airframe-http).
    • Airframe Rx: ReactiveX implementation for Scala.
    • AirSpec: A testing framework.

    Additional utility modules include airframe-codec (MessagePack-based schema-on-read), airframe-config (YAML-based configuration), and many others.

  7. Airframe RPC core features and backends

    main

    Airframe RPC is a framework for building RPC services using Scala as a unified interface. Key features include:

    • Backends: Supports Netty (HTTP/1) for standard web/browser compatibility and gRPC (HTTP/2) for high-performance requirements.
    • Serialization: Automatically handles data encoding into JSON or MessagePack (a compact binary format).
    • Client Generation: Uses the sbt-airframe plugin to generate type-safe HTTP client code from your Scala interfaces, eliminating the need for manual HTTP request construction.
    • Cross-Platform: Supports Scala 2.13, 3.x, and Scala.js, enabling the same interface definitions to be used on both the JVM (server) and in the browser (client).
    • Schema Generation: Supports Open API schema generation.
  8. Key features of Airframe RPC

    main

    Airframe RPC provides several advantages for service communication:

    • Type Safety: The client and server share the exact same interface definition.
    • Multiple Protocols: Supports JSON, MessagePack, and gRPC.
    • Cross-Platform: Compatible with Scala.js for frontend development.
    • Automatic Code Generation: Client code is automatically generated from the @RPC interfaces.
  9. Compare Airframe with other DI frameworks

    main

    Airframe is a run-time dependency injection (DI) framework for Scala. When choosing a DI approach, consider the following trade-offs:

    Run-time DI (e.g., Airframe, Google Guice)

    • Pros: Supports dynamic-type binding (useful for switching implementations based on environment like test vs. production), simpler binding code (only direct dependencies need to be written), and rich life-cycle management.
    • Cons: Missing bindings are discovered at runtime rather than compile time.

    Compile-time DI (e.g., MacWire, Dagger2)

    • Pros: Validates the presence of all dependencies at compile time.
    • Cons: Less flexible (no dynamic binding), requires enumerating all dependencies (including transitive ones) in a single scope, and life-cycle management is often difficult or requires reflection-based interceptors.

    Pure-Scala Approaches (e.g., Cake Pattern, Reader Monad)

    • Pros: No external framework required; missing dependencies are caught at compile time.
    • Cons: Requires manual wiring/overrides and careful management of explicit or implicit parameters.