adamflott.com

AMF - Application Making Framework

Description: A Rust library to aid in daemon and application development using types...or What If main() Had Rules?
Authored: 2022-03-26;
Permalink: https://adamflott.com/programming/rust/amf/
tags : framework; rust; unix;
categories : programming;


Table of Contents

Status

Public Draft - R&D phase

About

An R&D open source project to explore writing a framework to aid in developing daemons, applications, and REPL s in the Rust programming language that can run in various execution environments (Linux, Linux-like, Docker, Kubernetes, etc).

Background

Professionally I've written quite a few daemons that run in various forms (web servers, system managing, etc) and often repeat myself.

At the day job, I was often given asks that sound conceptually easy, but are often wrought with edge cases and complexity an architect gets to gloss over (e.g. Unix signal handling). As a result I spend far too much trying to take care of the ask instead of focusing on the primary goal (e.g. write a daemon that manages firewalls).

As a user of a framework, I don't want to sacrifice my desire to bring my own libraries/techniques instead of being forced by the framework (e.g. logging). My current employer has environments that require special handling. Being able to move an daemon from one environment to another with only a re-compilation has a lot of value (e.g. going from your local desktop to running on one of the cloud platforms).

I attempted an implementation in Haskell in December 2020 and have a partial working version on my GitHub. Given my lost bet on Haskell begetting a revolution for how programs are written, I've re-focused on using Rust. As of 2022 I am not able to find a language with a thriving, growing, and nurturing ecosystem that surpasses Rust.

Goal

Design a system that:

  1. supports all the requirements
  2. alleviates the pain of dealing with the mundane (e.g. configuration loading/updating safely)
  3. to let the user focus on writing code

Terminology

TermDefinition
sectioncommand line options, environment variables, configurations, logging, telemetry
controlInteracting with the app via outside controls (either Unix Domain Socket, HTTP, etc)
environmentExecution environment
app typedaemon, app, REPL, script, etc
computationa user runs their app type in an environment
eventa user defined notable thing that happened
metrica piece of data for telemetry
configurationvalues relevant to the domain of your application that can be safely changed at run time without restarting

Requirements

Non-Requirements

Design

An implementer(/user) will:

Events form the spine of the framework. All notable things that happen get serialized into a channel which n readers and only a single writer. If the user chooses logging output, events become the log entries. Events can be low level: UNIX signals, socket operations, etc or high level: new user added, timer expired, remote host reported down, etc. Event handling is asynchronous. The framework augments each event with the who, when, and where. The data portion of the event should contain the what and/or why.

Metrics

Configuration

Control

References