Node.js Backend Architectures

Exploring popular backend architectures with Node.js & TypeScript.

All of these architectures & patterns focus on same thing. Separation of Concerns, Testability, Maintainability. Following a set of rules from one or more of these architectures can help to create softwares that are easier to evolve and test over time.

All popular architecture have a few things in common. Most have layers like Domain Layer, Application Layer, Infrastructure Layer and Presentation Layer. The Domain Layer is the core of the application, it contains the business logic. The Application Layer contains the usecases, the business rules. The Infrastructure Layer contains the database, the web server, the external services. The Presentation Layer contains the UI, the API, the CLI.

In all architecture, dependencies flow inward, with inner layers having no knowledge of outer layers.

Inversion of Control (Dependency Injection)

When a piece of code A depends on another piece of code B, instead of creating the depependency inside A, we inject (fancy word for pass) B from outside. This way A is not responsible for creating B and can be easily tested with a mock B.

Domain Driven Design

Clean Architecture

clean-architecture

Usecases are also referred as interactors sometimes

Hexagonal Architecture / Ports & Adapters

Onion Architecture

DCI (Data, Context and Interaction)

Vertical Slice Architecture

Separating the application around features or “vertical slices”. A good addition to the Clean Architecture. First just slice the application vertically, then apply the Clean Architecture principles to each slice.

vertical-slice

Screaming Architecture

CQRS (Command Query Responsibility Segregation)

Repository Pattern

Modular Monoliths

Conway's Law

  • Conway's Law
  • Conway's Law - when we build software, we need to know the different groups/teams/roles it serves, and divide the app up into separate parts, similar to how those groups normally communicate in real life

Resources

Articles

YT Channels

Videos