MohamedBeydoun / atlas

An express-typescript code generator
Apache License 2.0
6 stars 0 forks source link

Controller, Router, Route Architecture change #15

Closed AsFal closed 4 years ago

AsFal commented 4 years ago

Architecture change

This proposal concerns the controller, router resources. I will also be defining two new non existing resources.

Current architecture

The following section describes my understanding of the intended architecture. I will not be using a "I believe" structure when stating observations of the architecture, I will just be using a declerative style.

Atlas is a cli tool that generates a Typescript server that follows a version of the MVC architecture. Atlas encourages a functional programming style.

Model

The model is defined within the database folder. The database folder defines the different components of the model. The models folder defines MongoDb schemas and models that define how documents are stored in the database. Associated interface types are defined in the interfaces folder. The interactions defines modules around the MongoDb models that will used by the controller.

Controller

The controller is defined in the controllers folder. This is where all business logic is located. In similar express applications, this folder could also be called services. This layer is not coupled to a specific database. It has an aggregation association to the interactions package in the model and a dependency to the interfaces defined in the model.

View

The view is defined in the routes folder. It uses functions in the controller to defined and handles errors in a controlled way (i.e. maps them to a certain http code).

Suggestions

New folder structure

Adding interfaces folder to database

The idea here is to completely decouple your databse from your controllers. Instead of your controllers having direct access to the Document type, the user defines types which exposes the attributes that the controller is allowed to use. Given that you generate the boilerplate, adding this type of interface would not come at that big of a time cost to the cli user.

As a result of this, the atlas generate model command would now need to generate the MongoDb model, the associated interactions module and the associated interface.

Modifying the router

... tired of writing at this point, will reformulate later. The basic idea is...

Router creation

Allow the creationg of namespaces in your routes. Examples

Routes creation

Allow route creation with a lot of flags.

Notes

This need more thought, I just wanted to give you an elevator pitch.

Notes

MohamedBeydoun commented 4 years ago

A few concerns: