Why MVC is wrong for Web Framework?
Tags: webdev, programming, discuss, architecture
Published: 2022-04-05 14:04:04

We have been poisoned for long by MVC in web development. 

Because MVC was introduced earlier before web frameworks, most web frameworks are using it reckless.

The creators of most web frameworks even don't know the different between web logic and business logic.
Let alone how should the web frameworks should be.

They just need MVC to be there, which may make them somewhat more confident.

But if you ask, why a web framework needs a mvc? No one can explain it logically. Because there is no logic to use mvc inside a web frame work.

When I was using a web framework with MVC, I always confused by the controller.

I don't know if the controller is for web request and business logic.

In fact web frameworks only needs do several things like:

1. handling web requests
2. processing requests
3. return data

There are basic two systems around for a web framework to handle, the web request processing system and user logic processing system.

But most web frameworks mix web request and user logic into one controller.
And mix return data with view in MVC.

For web frameworks, they really don't need to interfere with user logic processing. Those web frameworks are very basic frameworks, like express.js.

So as we now know, one route with one controller is definitely not the right way to be a good web framework. Web requests may share the same processing for different routes.
And may have different processes for different HTTP method with the same route.

For a good web framework, it should handle these two systems properly. And handle these things well:

1. the web request routing and request data purifying
2. the bridge passing the web request data to the user logic/ business logic processing system and take back data to the web response
3. Ease the way use logic/business logic being handled.
4. Add hooks for business logic to controller the web flow.

It in fact has nothing to do with MVC. Those things are all on the web flow which I name it the Web Straight Line. It can be described like this chart:

![the Web Straight Line](https://raw.githubusercontent.com/calidion/aex/282ed31a68b31d2067f936515c593796f961cbd5/docs/Web_Straight_Line.png)

It details most useful web processes in almost an ordered way.

Which the web straight line, we clearly see what a web framework can be and why MVC is not necessary for a web framework.

And also there is an implementation for the Web Straight Line, it is call [aex](https://github.com/calidion/aex) using node.js and typescript.

With aex, we need no Controller, but handlers inside classes which are used to handle different request and as a bridge to further user logic processing.

Here is a simple example of using aex to process a web request.

```typescript
import { Aex, http } from "@aex/core";

class UserLogic {
  private parameters;
  constructor(parameters) {
    this.parameters = parameters;
  }
  @http("get", "/user/process1")
  public handler() {
    this.userLogicProcess1()
  }
  
  private userLogicProcess1() {
     // ....
  }
}
```
Note:
> This web flow is applicable in most languages.