I'm currently on the process of creating a website/webapp.
My application is based on Node JS with the express framework.
My core backend concept consists of
- routers: handle http request. Like
- controllers: business logic behind routers
- model: interface between database and controller
I'm not sure if this follows any best practice patterns as MVC. It started as a very small personal project with business logic in routers. At some point I had to refractor my app (especially considering DRY) so I added controllers.
So let's say one can create an team with his account. The router will validate the request (user is authenticated, has permissions, ...) and forward the task to the controller. The controller will validate the form data, create a new database entry and return the new entry. The router will render the template and respond the request.
I think so far everything should be pretty straight forward.
Now the team is created and the user can invite other users to his team. Pretty much the same procedure as before.
Now we come to my actual question.
The invited user gets an notification. Currently I create notifications at the same place as I call the model to create a new entry for the invite.
I don't like that notifications after at the same place. Notifications are a side effect and just decrease readability of the actual task.
So my idea was to use events. The team controller should emit an event when someone got invited.
The event handler will create the actual notification. But in my current concept there is no component which would fit the role of handling the event in my opinion.
The notification controller could listen for events on the team controller. But this could end in ring-dependencies (the current example is not the best example for this situation).
So my question is: WHO should listen for events and complete side tasks?