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
tests/
routes/
src/
routes/
dummy_namespace/
router.ts
dummy_routes.ts
nested_namespace/
router.ts
dummy_routes.ts
controllers/
dummy_controller.ts
database/
models/
dummy_model.ts
interactions/
dummy_interaction.ts
interfaces/
dummy_model_interface.ts
middleware/
dummy_middleware.ts
app.ts
server.ts
.gitignore
README.md
package.json
tsconfig.json
tslint.json
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
atlas generate router new Would create a new file named new.ts and would connect it the the namespace's router (in this case the top level router).
atlas generate router namespace/new Would create a new file named new.ts and would connect it to the namepsace's router.
Routes creation
Allow route creation with a lot of flags.
atlas generate route new/route --verb "get" --errors customError=411[,...] [...] Would create a new route on the the new router. It would also take care of connecting the route to the server (and generate the swagger yaml).
Notes
This need more thought, I just wanted to give you an elevator pitch.
Notes
In a lot of other projects, the controller folder has the role that the routes folder has in an atlas project.
Why move interfaces to database? Interfaces aren't used only within the context of databases e.g. users can get data from different sources and would need to type them through interfaces.
Why are app and server outside of the src directory? src is where all the source code for the project should be.
Why do we want to generate namespaces for routers?
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
atlas generate router new
Would create a new file named new.ts and would connect it the the namespace's router (in this case the top level router).atlas generate router namespace/new
Would create a new file named new.ts and would connect it to the namepsace's router.Routes creation
Allow route creation with a lot of flags.
atlas generate route new/route --verb "get" --errors customError=411[,...] [...]
Would create a new route on the the new router. It would also take care of connecting the route to the server (and generate the swagger yaml).Notes
This need more thought, I just wanted to give you an elevator pitch.
Notes