DEV Community

Matรบลก Makatura
Matรบลก Makatura

Posted on

[0] Creating a web framework from scratch - the motivation

Hello wanderer! ๐Ÿ‘‹ However you managed to come along this article, please, feel welcomed, and join me on my way to create a brand new Scala web framework from scratch!

Wait, what? Why would you do that? ๐Ÿ˜ฎ

I'm sure you are wondering why would anybody waste time doing that. Not only there are already great, production-ready frameworks available, implementing all the cool features would take tremendous amount of effort and time.

And yes, that's absolutely correct! But let me give you the following points to explain my motivation and hopefully give you different look on the matter.

It's a lot of fun for me ๐Ÿคนโ€โ™‚๏ธ

Let's get this one out of the way - I wouldn't do it if I wasn't enthusiastic about it! Building systems that me or somebody else can then take to create new things was always exciting to me and it gives me the sense of pride and accomplishment... and that's simply nice.

Knowledge and experience ๐Ÿ‘จโ€๐ŸŽ“

It's one thing being able to write applications, but it's a brand new world being able to write underlying framework. This journey will introduce me to a lot of new technologies and concepts I would otherwise not explore and I'm hopeful it will aid me to grow as an engineer/developer.

I miss Laravel's experience ๐Ÿ˜ in JVM world โ˜•

Although my first real programming language was Java, my early days of web development were dedicated to PHP - and almost entirely to Laravel framework. And while it's certainly not perfect, it provides great development experience. I always enjoy building apps with this framework, it feels satisfying and you keep finding out excuses to implement new functionality.

When I switched to building web apps in JVM (Java, Kotlin, Scala), I started working on large enterprise applications. And sure, I think I have great tools for that, I think that my code I deliver is robust and reliable... but I never experienced as much joy as before (and when I remember my efforts in configuring non-trivial things in Spring Boot, it's actually quite the opposite).

So I thought - why not try to create a framework that would prioritize development experience? What will happen - will it feel as good as it did for PHP, or is JVM simply not suited for it? I will certainly find out.

Pure Scala implementation ๐Ÿ‘Œ

Looking back now, one more thing that I believe Laravel does well over JVM frameworks is it's use of PHP everywhere. You don't have annotations, you don't have custom expression languages, you don't have XML files, you don't have custom configuration files - just PHP (and environment variables). The power of fully fledged programming language is always available to you, everywhere in the system.

Why not try something similar in JVM world? This is where I think Scala can shine - it's much more powerful language than Java (and even Kotlin), so if done right, it should be possible to move everything back to the regular language without the need to rely on any sort of code metadata or other languages or markups.

And the more you have in the readable code and less in dark magic in the background, the more comprehensive your framework will become to developers.

Master thesis

In a year and a half from writing this article, I will be graduating from University as a master of computer science. For that of course, I will need to finish my master thesis. So why not kill two birds with one stone and make this web framework topic of my thesis? It also has one added benefit - I will be kinda forced to do it, so it will be harder for me to abandon this project due to lack of time or motivation.

And why blog about it? ๐Ÿค”

Why not? If nothing else, it will be my personal archive of my thoughts and progress that will one day make me smile (or laugh). Maybe it will inspire somebody to create their own framework or library. And there's a slight, but non-zero chance that it will blow up - and in that case, this blog will become a new Bible for hypothetical fans of my work. And if you ask me - that'd be cool (and something to brag about in discussions ๐Ÿ˜„).

So what to expect? ๐Ÿ“ˆ

This first (or zero-th?) entry is a bit longer to give you my background, but I expect subsequent parts to be much shorter. I don't intend to write in-depth dev-blog right now, I'd only like to share interesting findings or progress made on this framework. I believe writing one entry per month is just about right - it won't be boring and I won't burn out.

Top comments (3)

Collapse
 
nickfun profile image
Nick F

Play framework is the best we seem to have in Scala with a focus on developer productivity. It doesn't focus on making database interactions easy and that is a huge hole. Also, Laravel is really nice about having a Auth system built in and I found that a huge boost when I used it for a project, Play is lacking there. I hope your efforts can fill in these gaps in the Scala ecosystem. Good luck and I hope to read your progress here.

Collapse
 
hbgl profile image
hbgl

Sounds interesting. What kind of spin are you going to put on it though? I cannot imagine that a professor will just let you do a rewrite of Laravel in Scala for a master thesis.

Collapse
 
matusmak profile image
Matรบลก Makatura

That's something I wanted to focus on in the next article, but here's few thoughts for now :).

I don't think I want to create rewrite of Laravel, but rather be heavily inspired by it :). What I mean is that I don't want to end up with framework like AdonisJS, which is really more-or-less a JS version of Laravel (no hate though!), but with something like VueJS in relation to Angular 1.

To give you some examples, Laravel uses centralized routing system, I want that too, but I will leverage Scala to create a different DSL. Here's a code that I'm currently playing with:

group prefix "/admin" of List(
  get  path "/debug" name "dishes.admin.debug",
  post path "/edit"  name "dishes.admin.edit",
) controller classOf[AdminController],

crud prefix "/students" controller classOf[TestController],
Enter fullscreen mode Exit fullscreen mode

Laravel has Artisan CLI, I will try to include that too, but with custom implementation. Laravel Eloquent is great ORM, I will for sure create similar query builder.

On the other hand, I will have many differences. My ORM won't be using Active Record pattern. My framework won't be fullstack, it will be just focused on backend API. I will also use reactive architecture, similarly to Spring Webflux. And so on :).

As for the master thesis, a big part will be research and evaluation. I will be analysing 3 frameworks - Laravel, Spring (Boot + Webflux) and Play framework, as well as a lot of smaller things (I have a couple of articles for fast routing). For the evaluation, one part will be comparing my framework to other 3 in terms of numbers, the other part will be testing it among other devs.