Monolithic architectures should be designed in a way that allows for them to be effectively broken down into individual services or microservices. Albeit a personal opinion, developers will find it quite easy to shift to microservices if horizontal scaling becomes a necessity in the future. The highly decoupled nature of the architecture discussed in the series allows for both dependency injection and breaking down these individual services to run in their own regulated OS environment.
Within the src/ folder, each application should be developed within its own sub-folder. In the example project I develop the app’s core functionality within src/api. ExpressJS is a library allowing developers to develop architectures according to their own preferences. At the core of the library, is the concept of middleware functions. These functions are like filters that last during the lifecycle of each request and shall be written within their own folders in src/api/middleware. The src/routes folder translates to each route after the app’s general URL prefix.
The routes folder will contain files for each specific route of the app. Each of these will serve as nothing more than a table of contents (a dictionary) for each REST endpoint. For example, the /api/auth/login endpoint invokes ‘Authentication.passportLocal’ and ‘Responses.Auth.Login’ middleware functions. The former validates the user input and checks for credentials whereas the latter then receives the request and responds accordingly.
If you’re going with REST APIs, you’ll always find it quite difficult to change the core business logic whenever the front end requires any changes. Sometimes these changes are related to data that is being fetched and sometimes it’s related to permissions and other preliminary checks. To tackle these issues, I find it best to organize the middleware into different segments where each segment is responsible for one distinct step within the lifecycle.
The authentication middleware should be contained within its own folder. In this case, the src/authentication contains the authWall and the passportLocal files - both of which handle the authorization and the authentication mechanisms for incoming client requests respectively.
The responses folder shall be responsible for the last operation within the request lifecycle. For example, in the API’s /api/auth/login route, the ‘auth’ response shall be responsible for generating a valid JWT for the user, logging the transaction, and returning the client with a 201 success response alongside the newly generated token and accompanying user data.
I also use src/permissions, src/helpers, src/queries, and src/validation to maintain a clean separation of concerns. Permissions return 403s whenever an authenticated user isn’t authorized to perform a certain action. Helpers are used to perform database transactions on which permissions might depend. For example, you may need to fetch data about a user to figure out if they have permission to do so. Similarly, src/validation can be used to write individual validator functions to sanitize and validate user-generated input at the start of the request lifecycle.
Copyright © 2026. Salman Ahmad.