Skip to main content

Intro

Domain modeling is a powerful tool for clarifying and refining our understanding of a subject area, and for identifying opportunities for optimization and improvement. By carefully considering the needs of stakeholders and the nature of the domain, it is possible to create effective and useful models that can facilitate communication and drive progress.

Fmodel aims to bring functional, algebraic and reactive domain modeling to TypeScript.

It is inspired by DDD, EventSourcing and Functional programming communities, yet implements these ideas and concepts in idiomatic TypeScript, which in turn makes our code

  • less error-prone,
  • easier to understand,
  • easier to test,
  • type-safe and
  • thread-safe.

FModel promotes clear separation between data and behaviour:

  • Data
    • Command - An intent to change the state of the system
    • Event - The state change itself, a fact. It represents a decision that has already happened.
    • State - The current state of the system. It is evolved out of past events.
  • Behaviour
    • Decide - A pure function that takes command and current state as parameters, and returns the flow of new events.
    • Evolve - A pure function that takes event and current state as parameters, and returns the new state of the system.
    • React - A pure function that takes event as parameter, and returns the flow of commands, deciding what to execute next.

The focus is on implementing robust information systems (back-end):

  • traditional - state-stored systems / storing the new state by overwriting the previous state.
  • event-driven - event-sourced systems / storing the events in immutable storage by only appending.
  • or you can have both flavors within your systems landscape, and easily transit from one to another

What you'll need

Getting Started

Get started by including dependencies.

NPM registry

Fmodel is published in NPM registry, so you need to enable it as a source of dependencies in your build.

Include the dependencies

You're now ready to include Fmodel in your project.

package.json:

"dependencies": {
"@fraktalio/fmodel-ts": "^2.1.1"
}

Create a new application

You have great frameworks at your service to bootstrap development:

info

Fmodel does not require usage of any framework whatsoever. It is completely up to you.