Home

The Hexagon toolkit is meant to provide abstraction from underlying technologies (data storage, HTTP server engines, etc.) to be able to change them with minimum impact.

It is designed to fit in applications that conform to the Hexagonal Architecture (also called Clean Architecture or Ports and Adapters Architecture).

Hello World

Simple Hello World HTTP example.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package com.hexagonkt.starters

import com.hexagonkt.helpers.logger
import com.hexagonkt.http.httpDate
import com.hexagonkt.http.server.Server
import com.hexagonkt.http.server.ServerPort
import com.hexagonkt.http.server.jetty.JettyServletAdapter
import com.hexagonkt.injection.InjectionManager

val injector = InjectionManager.apply {
    bindObject<ServerPort>(JettyServletAdapter()) // Bind Jetty server to HTTP Server Port
}

/**
 * Service server. Adapter is injected.
 */
val server: Server = Server {
    before {
        response.headers["Date"] = httpDate()
    }

    get("/hello/{name}") {
        ok("Hello, ${pathParameters["name"]}!", "text/plain")
    }
}

/**
 * Start the service from the command line.
 */
fun main() {
    logger.info { injector }
    server.start()
}

Features

Hexagon's high-level features.

  • Simple to Use: Hexagon is focused in allowing you to use the features you use the most in your daily coding in the easiest way.

  • Easy to Hack: The libraries are done to be lean and simple so you can tweak it to suit your needs instead relying on third parties.

  • Pluggable Adapters: Adding an adapter is just implementing the port's interface. You can code your own adapters from scratch or tune the existing ones.

  • Kotlin First: The library is coded in Kotlin for coding with Kotlin. No strings attached to Java (as a Language).

  • Properly Tested: Project's coverage is checked in every Pull Request. It is also stress tested at TechEmpower Frameworks Benchmark.

  • Modular: Each feature is isolated in its own module. Use only the modules you need without unneeded dependencies.

Architecture

How Hexagon fits in your architecture in a picture.

Note

Using this toolkit won't make your application compliant with Hexagonal Architecture (by its nature, no tool can do that), you have to provide a layer of abstraction by yourself.

architecture

Ports

Ports with their provided implementations (Adapters).

PORT ADAPTERS
HTTP Server Jetty, Servlet
HTTP Client AHC
Messaging RabbitMQ
Store MongoDB
Templates Pebble, Freemarker
Serialization Formats JSON, YAML
Settings Environment, Files, Resources

Comments