Formulaic Docs

Formulaic Framework

Formulaic is a collection of Nest modules and React components for building web applications.

Formulaic libraries are built to work independently of one another, yet integrate nicely if you use multiple components together.

Formulaic contains modules and components that Flyyn has built into many Nest and React applications, and have been abstracted into this namespace to be reusable.

Highlights

  • Utilities return strongly-typed, safe, and chainable responses (using FP)

    • An Either-like structure strongly types error cases

    • A Promise-like chaining structure to quickly transform data

    • Returned data can be directly sent to clients (using fp-interceptor)

Formulaic Libraries

Data Types (FP)

Provides a strongly-typed and chainable structure for return values. Used by most Formulaic libraries.

Entity Service

Provides TypeORM based utilities that are useful in most Nest services that interact with a TypeORM Repository.

Hashing Module

Extremely basic wrapper around bcrypt to use as a Nest service.

ID Generator Module

Provides powerful shortcuts to generate random, collision resistent IDs in multiple formats.

FP Interceptor

Intercepts outgoing HTTP responses in Nest, allowing routes to safely return FP formatted objects.

Authorization (ACL) Utilities

Utilities to quickly create authorization schemes using CASL.

Auth Module

Provides both a simple authentication guard that implements the functionality of Nest’s authentication tutorial, as well as hooks for more complex ACL schemes. Works well with the ACL library.

Requires requests to authenticate via JWT, provided as an Authorization header.

Project Setup

We recommend using Formulaic in a Yarn (version 2+, "Berry") monolithic repository, with a standard Nest server and a React application created with Vite.

Example repository initialization
mkdir ~/Documents/my-app/
cd ~/Documents/my-app/

git init --initial-branch=main
yarn init -w -2

cd packages/

# Create a Nest server - this example uses the Nest CLI to initialize
# the package with a basic Nest boilerplate.
npx @nestjs/cli new "my-server"
cd my-server
rm -rf .git
yarn add @nestjs/swagger @nestjs/typeorm typeorm express
yarn add --dev webpack

# Create a React application using Vite
cd ../
yarn create vite --template react-ts my-app

Installation

Formulaic is composed of a number of independent packages, all available on NPM under the @formulaic namespace.

You can install each package individually, or you can install a meta-package that includes all of the Formulaic packages.

Install Server Bundle
cd packages/my-server/
yarn add @formulaic/api
Install React Bundle
cd packages/my-app/
yarn add @formulaic/react