Micro-frameworks are ideal for building small applications, but are they good for medium or complex applications?
In this article we’ll learn what options Jooby offers to build large scale web applications and keep the source code organized and maintainable.
Initial application development
Let’s say you want to build a HTTP API for users. An initial application might looks like:
Done! Your application is ready. It looks clean and easy to understand. Simplicity is one the Jooby goals.
Large scale application development
Suppose you want to extend your application with:
- A HTTP API for blogs.
- A HTTP API for comments.
- UI for users, blogs and comments.
We can keep what we did before and extend the number of lines in our App.java. It is perfectly fine to do that, after all you own the application 🙂
But what if you want to better organize your source code? How can you? This is missing feature for most micro-frameworks but not in Jooby.
Jooby provides some features and patterns that let you compose and organize your application.
MVC routes (a.k.a. Controller)
This is well-known pattern in Java frameworks were you annotated methods and make them accessible via HTTP:
We can replace the script routes with our new controller so now our application looks like:
You can apply the same pattern for blogs, comments and UI controllers:
This is how you usually split an application into multiple components using controller classes and annotations.
Wouldn’t be nice if we can keep the script routes and keep source code organized?
This pattern let you compose one or more applications into one big application.
It’s perfect if you love script routes and want to keep them organized.
We split our application into 4 components, like we did before with controllers. But this time each component is an application by itself:
Time to embedded it as we as we did in the controller example:
This approach let you build standalone applications that can be easily embedded into a major application.
In this article we illustrated how to build large scale applications with Jooby using MVC or script routes.
Some users prefer MVC routes over script routes, but the truth is that you can use both or mix them together. Jooby just make sure to give you the right tools. Like always, decision is yours.
That’s all for now. Thank you for reading! If you are not yet convinced about Jooby here is nice article on why you should give it a try: