Introduction

This document outlines the general architecture that powers the FOAM API.

Overview

The FOAM architecture consists of three major parts:

  1. The FOAM smart contracts, written in Solidity
  2. The FOAM REST API, written in Haskell
  3. The SpatialIndex. written in Purescript

The guiding principles are

  1. DRY (“don’t repeat yourself”)
  2. Strongest possible type-safety
  3. Don’t re-invent the wheel

We leverage Haskell and Purescript to deliver on these principles. Haskell’s and Purescript’s strong type-system enables us to describe the functionality once and derive all interacting components from it - at compile time.

Because of Haskell’s mature set of libraries and integrations (and increasingly this applies to Purescript as well), we do not have to re-invent anything when it comes to utilizing mature products such as Postgres and Redis. What’s perhaps harder for someone not entrenched in these two programming languages to appreciate, is the powerful set of abstractions that are available to us through using these languages. They manifest in both how we write code and how we can combine libraries.

Examples

  1. purescript-web3-generator generates all our code from the ABI that interacts with the blockchain.
  2. hs-web3 and TemplateHaskell derives all our database schemas from the same ABI.
  3. servant generates our swagger documentation in addition to our javascript clients. Moreover, our mocked data is generated by the same API definition.

The diagram below outlines the different parts, and also the direction in which parts communicate with eachother. Communication here really means everything from API calls and websockets to compile-time information flow.