
Throughout this week, we've published a series of articles contributed by some well-known people within the F# community focused on web and cloud programming. Today, we're announcing the launch of the SAFE stack initiative, which brings all of the elements together as a cohesive story:
In collaboration with our partners, we've today launched the SAFE website, which we are hoping becomes the go-to place for people developing functional-first, cloud-ready web applications.
It's important to understand that SAFE in itself is not a stack that forces you down the route of using the specific technologies named above. Instead, think of them as a starting place to refer to when you're considering an end-to-end solution in F#; we suggest that the key behaviours in SAFE web technologies should include:
Here's a little more detail on this philosophy for each component in the stack.
It's key to understand that whilst we are fans of Suave, we believe that there's also room here for other F#-friendly web programming models. As mentioned in the web programming article of this series, this also includes Giraffe (which closely mirrors the Suave model), Freya and WebSharper.
Whilst we at Compositional IT are big fans of Azure and recommend it as our default cloud provider for customer solutions that require scalable, flexible and easy-to-use services, we know that not everyone feels this way. As such, there's no reason with the SAFE stack can't work equally well on Amazon Web Services (AWS) or Google Cloud Platform (GCP).
Fable provides a superb experience for F#-to-Javascript transpilation in a flexible manner, as well as an experience that "plays nicely" with both the .NET and Javascript ecosystems. However, there are other solutions out there, such as WebSharper, which offers an all-in-one F# solution for F# web applications, and you should certainly investigate such options. Nonetheless, Fable remains our default recommendation for F#-and-Javascript-ecosystem integration.
Elmish provides an excellent option for a UI model that supports some of the core principles of functional programming, such as immutability and expression-based programming, whilst taking full advantage of many of F#'s language features such as discriminated unions and pattern matching. There are other UI models available such as (again) WebSharper's Piglets and Formlets models etc., that you
SAFE isn't a prescriptive solution that forces you to go "all in" either. Here are some alternative application architectures that utilise a variety of elements of the SAFE stack in different ways.
Here's a typical SAFE stack using all the "default" technology set.

An example of this is available on the SAFE github repository with the SAFE Bookstore app.
Here's an alternative version of the SAFE stack that uses some other technologies for the same purposes as the original stack, such as AWS for hosting, and Giraffe for the server-side web stack - this is also totally cool.

Here's a partial implementation of the SAFE stack, which uses F# for the server side, but uses conventional a Typescript + AngularJS combination for the client side.

This is another partial implementation of the SAFE stack, this time using an on-premise installation of the stack, possibly using IIS for hosting the web application, whilst using on-premise database and messaging systems.

Finally, let's look at how we can use the SAFE stack for a cut-down stack - this time just an HTTP-enabled API running Suave, which returns data sourced from Document DB (perhaps along with data retrieved from other sources, for example via a type provider). We're using Fable here to create F# stored procedures in Cosmos DB, which are normally written in Javascript.

By adding React Native into the mix, there's nothing to stop you creating mobile applications using the SAFE stack. There's an example of this with the SAFE Nightwatch sample, too!
It's early days for SAFE, but we feel that this is a particuarly sweet spot within the F# world. We're hopeful that the F# community will come together to collaborate and make the SAFE site the go-to place for someone looking to get up and running with these sorts of applications.
Please do bookmark the official website - we'll be making lots of updates to it in the coming weeks, including adding more documentation and reference applications using alternative stacks. We're also considering doing the following:
Please, also follow the official safe_stack Twitter account as well for the latest news over the coming weeks. We'd love to hear your feedback - please reach out to us.