Introducing Marten - The pragmatic web framework

Hey everyone! :wave:

I wanted to take a few moments to introduce a shard I’ve been working on for quite some time:

TL;DR

Marten is a Crystal web framework that makes building web applications easy, productive, and fun. You can read more about it in the dedicated documentation.

What is it?

Marten is a Crystal Web framework that enables pragmatic development and rapid prototyping. It provides a consistent and extensible set of tools that developers can leverage to build web applications without reinventing the wheel. As it stands, Marten focuses on the following aspects:

  • Full featured: Marten adheres to the “batteries included” philosopy. Out of the box, it provides the tools and features that are commonly required by web applications: ORM, migrations, translations, templating engine, sessions, etc.
  • Extensible: Marten gives developers the ability to contribute extra functionalities to the framework easily. Things like custom model field implementations, new route parameter types, session stores, etc… can be registered to the framework easily.
  • App-oriented: Marten allows to separate projects into a set of logical “apps”. These apps can also be extracted in order to contribute features and behaviours to other Marten projects. The goal here is to allow the creation of a powerful apps ecosystem over time.

How does it differ from existing frameworks?

My goal here is not to draw a direct comparison with other existing frameworks. I simply want to highlight a few key things that (I believe) Marten is bringing to the table and that differ from what has been encountered in the Crystal world so far:

  • Auto-generated migrations: Marten’s visions when it comes to models is that everything needed to understand a model should be defined within the model itself. In this light Marten’s models drive tables (and not the reverse way around) and migrations are generated automatically from model definitions. Migrations can still be written manually using a convenient DSL if necessary, but the idea is that defining a model and its fields is all that is necessary in order to have a corresponding table taken care of automatically by the framework
  • App ecosystem: Marten provides an “app” mechanism that allows to separate a project into a set of logical and reusable components. Each app can contribute specific abstractions and features to a project (eg. models and migrations, templates, HTTP handlers and routes, etc). Another interesting benefit of apps is that they can be extracted and distributed as external shards: the goal behind that is to encourage the creation of a rich apps ecosystem over time and to allow projects to build features by installing and leveraging existing apps

What’s next?

The framework is certainly not feature complete (nor necessarily stable) but it can already be used for relatively simple web applications. I am looking for feedback from people who would like to play with the framework and / or leverage it in simple projects.

If you find a bug, don’t hesitate to open an issue into the project’s issue tracker on GitHub. Any help will be greatly appreciated! :pray:

Thanks for reading me!

15 Likes

Wow, great work @ellmetha :tada:

I’m getting the following error while installing due to ameba

In src/ameba/rule/style/redundant_begin.cr:126:40

 126 | return unless token.value == Crystal::Keyword::BEGIN
                                    ^----------------------
Error: undefined constant Crystal::Keyword::BEGIN

make: *** [bin/ameba] Error 1
1 Like

Is there something builtin for auth? Looks really great. Seems simple to use. Will try to play around with it in coming days.

Also…should be sent to twitter

1 Like

Holy smokes! This is awesome. After a minor bump on installing from source (I failed to install the shards and include the -o switch for the binary output to the bin directory), I ran the tutorial to the end. Can’t believe how simple this is to use. Definitely going to be exploring. Thanks!

1 Like

There is no built in authentication mechanism presently. This is something that I plan to add in the near future, but I’m not sure (yet) if this will be built in the framework directly or distributed separately in a dedicated app / shard. :blush:

Would be interesting to leverage the type system and multiple dispatch when rendering templates.

For example

def render("path_to_template", role : Admin)
# admin view template
end

def render("path_to_template", role : User)
# user template stuff
end

This way some logic could be kept out of templates along with various conditional code.

Not sure if what I’m trying to say makes sense ?

It makes sense. It is described also here as “method overloads” in Lucky web framework logic:

1 Like

Also have to say…great documentation.

3 Likes

A marten update command would be great to quickly update as new versions are released.

I wish there was a way to not wait for recompilation everytime a change is made. But i dont think there is any other option. Unless the new crystal interpreter could be used during dev and then compile for prod.

2 Likes