alchemy

Elegant, batteries included web framework for Swift.

struct App: Application {
    func setup() {
        self.get {
            "Hello World!"
        }
    }
}

App.launch()

Features

  • Fast, trie based routing.
  • Customizable middleware.
  • First class support for Plot, a typesafe HTML DSL.
  • Expressive ORM and query builder with out of the box support for Postgres and MySQL.
  • Database agnostic schema migrations.
  • Cron-like job scheduling.
  • Powerful dependency injection.
  • Typesafe API definitions, sharable between Swift clients & server.
  • Concise, elegant APIs built with the best parts of Swift.
  • Extensive docs and fully featured quickstart projects.

Installation

Quickstart

The Alchemy CLI can help you get started with one of the Quickstart templates. It is installable with Mint.

mint install alchemy-swift/cli@main
alchemy new MyNewProject

You'll be guided through picking a new project template, either Backend or Fullstack.

Swift Package Manager

Alchemy is also installable through the Swift Package Manager. Until 1.0.0 is released, minor version changes might be breaking, so you may want to use upToNextMinor.

dependencies: [
    .package(url: "https://github.com/alchemy-swift/alchemy", .upToNextMinor(from: "0.1.0"))
    ...
],
targets: [
    .target(name: "MySwiftBackend", dependencies: [
        .product(name: "Alchemy", package: "alchemy"),
    ]),
]

Running It

You can run your server from Xcode or with

swift run

Check out the deployment guide for deploying to Linux or Docker.

Documentation

Docs

The Docs provide a step by step walkthrough of everything Alchemy has to offer. They also touch on essential core backend concepts for developers new to server side development.

Note: If something is confusing or difficult to understand please let us know on Discord!

Quickstarts

If you'd rather just jump into reading some code, the projects in Quickstarts/ are contrived apps for the purpose of showing working, documented examples of everything Alchemy can do. You can clone them with alchemy new or browse through their code on Github.

API Reference

The inline comments are extensive and full of examples. You can check them out in the codebase or on the Github wiki.

Why Alchemy?

Alchemy is designed to make your development experience...

  • Smooth. Elegant syntax, heavy documentation, and extensive guides touching on every feature. Alchemy is designed to help you build backends faster, not get in the way.
  • Simple. Context-switch less by writing full stack Swift. Keep the codebase simple with all your iOS, backend, and shared code in a single Xcode workspace.
  • Rapid. Quickly develop full stack features, end to end. Write less code by using supporting libraries (Papyrus, Fusion) to share code & provide type safety between your backend & Swift clients.
  • Safe. Swift is built for safety. Its typing, optionals, value semantics and error handling are leveraged throughout Alchemy to help protect you against thread safety issues, nil values and unexpected program state.
  • Swifty. Concise, expressive APIs built with the best parts of Swift.

Roadmap

Our top priorities right now are:

  1. Conversion of async APIs from EventLoopFuture to async/await as soon as it's released.
  2. Filling in missing core server pieces. Particularly,
    • HTTP/2 support
    • SSL/TLS support
    • Built in support for multipart/form-data & application/x-www-form-urlencoded
  3. Persistent, queued jobs backed by Redis / Memcached.

GitHub