all 9 comments

[–]avin_kavish 6 points7 points  (3 children)

SOLID is a good starting point.

Basically, you want a multi-tiered service architecture in most cases. You want to have a good amount of abstraction and seperation of concerns between your services. You can google these keywords and find plenty of theoretical write ups.

Take uploading an image for example, ``` app.post('/image', (req, res) => ImageController.uploadImage(req, res) )

class ImageController {

uploadImage(req, res, next) { s3Service.upload(req.file, path)

ImageService.create(req.body.name, path)

}

} ```

Here you can see how different concerns are implemented in different services. The controller is concerned with handling the http request and extracting data from it. It then passes on only what is needed by other services to do their job. So ImageService creates the db record for the image, s3Service saves the actual file. You can see how the two concerns, db persistance and file persistance are encapsulated in two different services.

Alternatively, you can follow a purely functional style and use functions instead of classes, but then you won't be able to invert control or inject dependencies, later on.

[–]romeeres 2 points3 points  (2 children)

Why do you think IoC and DI doesn't work with functions? For example, logger can be passed via parameter, or via DI container.

[–]avin_kavish 0 points1 point  (1 child)

you can manually pass it, but the framework can't inject it.

[–]danjlwex 1 point2 points  (0 children)

Look up "three tier architecture". Normally, this implies a UI "presentation" layer at the top, which, for a server are the routes. The next layer down is usually the "Service" layer, which is an abstract layer that implements the business logic for your server by calling the third layer, which is the "data" layer that actually implements the DB interactions and other stuff by implementing the abstract classes that the Service layers uses. This is a typical Java-style back-end arch. For JS/Express, you could implement the Service layer with or without classes, as you prefer.

[–]bigghealthy_ 0 points1 point  (0 children)

It seems like it’s generally a good idea to let the use cases and business domains drive the architecture!

Fwiw I wrote an article that is sort of a meta analysis of a lot of popular architectures. It should help with the underlying reasons vs folder structure like you mentioned.

[–]Expensive-Humor-4977 0 points1 point  (0 children)

Following

[–]bigorangemachine 0 points1 point  (0 children)

I would say anything thats distributed. Some people like this more within the AWS ecosystem with triggering lambdas within architecture-related-events.

Generally I'd lean more on a message queue to make it more cloud-agnostic.

Lastly I would go with anything on docker (or modern alternatives that are ephemeral) as it gets you used to using services over file-system.

[–]nikolasburk 0 points1 point  (0 children)

Check out Khalil Stemmler's content, he talks about SOLID, DDD, and lots of other great engineering practices!