The monolith’s entry point is src/app.js where the initial loading script is executed. To maintain separation of concerns, I use dependency injection in my backend projects to maintain high decoupling. However, for medium-sized projects like these, the service location pattern can do the trick, even though it’s an anti-pattern. For this purpose, I used typedi - a well-maintained package that allows for both design patterns to be incorporated within the app. Bear in mind that the application’s structure allows for the dependency injection pattern to be used as well.
The src/loaders folder has all the loading scripts for each component of the app which includes the database, the HTTP server, and more. The loading script is loaded within the main app.js file. First, it starts off by connecting to the database, any secondary DBs, and throws exceptions if these connections fail. The loading script then proceeds onto loading the service locator.
The services handle all the CRUD functionality of the application. Each service maps to a single business entity within the application. For example, an authentication service will have CRUD functions along with authentication mechanisms. These service methods can each take in the necessary input data for each CRUD operation. As mentioned before, these service methods can also be modified to implement the dependency injection pattern.
The application’s shutdown script complements the loading script. First, the HTTP traffic is shutdown. Next, the primary and any secondary DB connections are safely closed. This makes sure there’s no incoming user data that needs to be persisted to any of the app’s persistence layers. The application then exists with a zero exit code indicating a successful shutdown.
Copyright © 2026. Salman Ahmad.