Why MVC is wrong for web framework, while Web Straight Line should be the right one?

李白字一日
4 min readMar 16, 2021

MVC is an ancient concept which stands for Model-View-Controller.
Most projects can be trimmed to fit the concept with models, views, controllers.
Hence most web frameworks are designed to be mvc web frameworks.
But when we use those web frameworks, we can find that they are not quite fit to the web development needs.

For example, URL handlers are usually considered controllers, but in effect, they are web handlers. They are not part of your projects, but handlers receiving and sending web data.

If you consider the web handler as the project controller, you may mix web logic with business logic.

And the MVC concept is more of abstraction than realisation.
M,V,C each of them may not be a pure self. Models may have some constrains, views can have events triggers, some data, some actions, controllers are interrelated with each other, receiving data, process data, change states.
You can’t really separate one from another.

If you are designing a User related module.
You may have user store, which can be a user model or something, but still you have a lot operation on that model, should this operation be called controller or models or view?
May be you should be hesitating, because they may be none of them. They are just operations attached to the model by the business logic.

As you can see, the MVC concept makes me very frustrated over and over again when developing projects.

But over time, I learned that MVC may miss some details the real projects need.

So I consider MVC to be recursive and extensive, which means MVC can be M(MVC)V(MVC)C(MVC) and M(constrains, events, actions, data)V(constrains, events, actions, data)C(constrains, events, actions, data).
May be the difference is only different in their proportion.

When working with web frameworks, I constantly encountered controllers. Most Web frameworks consider web handlers to be controllers. But I didn’t connect them at the first day I code web projects till the day I realised that controllers are no good to discribe web handlers.

But which model can best describe web handlers?

After I have tried many frameworks and failed to create an acceptable web framework many times, I started to form the idea, Web Straight Line, as the model for web handlers. And it was firstly documented in chinese here.

I tried this idea in my frist node.js web framework vig. It works, but the code is somewhat ugly and non concret.
you can check it here.
With vig, I somewhat confirmed the idea, Web Straight Line.

VIG is not a very completent framework and lack of documentation.

But it works for me, but the structure is not ease enough and slower than expressjs, because it is based on expressjs.

After vig is almost finalized, I started to try to simplify code construction with vig.

Then it comes out the aex framework. A simple, easy to use, decorated, scoped, object-oriented web server, with async linear middlewares and no more callbacks in middlewares.

I currently very confortable with it. It simplify the way I code with web, very easy to customize, reduce code redudency, efficient, well structured, stacked web processing utilities.
It is a real Web Straight Line framework I really need.

But still it is not very mature to many frameworks. But the idea Web Straight Line seems to be right for me.

And a detailed version of Web Straight Line chart was created after aex is production ready. The following is the newest Web Straight Line Chart:

With Web Straight Line in mind, aex enabled Object Oriented programming with web. Programmers can put anything right into a class, whether it is a model, a view, a controller. The only thing matters is that your are right in your business logic and some effective programming rules are obeyed.

A class is an abstraction of your bussiness logic, you decorate your bussiness with web logic. In aex, it is the decorators.

for example, You can put model, view, controller into one class User. But in backend, we don't treat any thing as view, they are only data, regardless of they are html, xml, json, plain text, etc.

So in effect, there are no views in web server. Neither is in aex. But you can have parsers, templates to generate those data types.

Here is the example on how to do object oriented programming with aex.

You don’t need any controller to describe the user logic if you are comfortable with one class.
Because in aex, the web handlers(web logic) are separated to the business logic by decorators. You can put almost all web logics into middlewares than put them into controllers.
It is encouraged to separate web logic from business logic in aex.

The web straight line is a somewhat new idea on web logic, it is to be enriched and corrected over time. Hope you like this idea and give aex a try:)

Originally published at https://dev.to on March 16, 2021.

--

--