Angular Architecture (NX-Driven)


Preface
I recommend basing the Angular Workspace architecture on libraries to benefit from the NX build system (commands like 'affected').
Library types
I recommend the following types (the types are of course not fixed and new types can be added individually).
Feature (Screen-Components, Container-Components…)
Domain (Services (business-logic), Models…)
Data-Access (Everything related to access data, also stuff like state-management (exp. Ngrx SignalStore)
UI (Dumb Components)
Util (like helper functions (but without business-logic))
Api (to define a clear interface where a feature can talk to another feature or domain to another domain)
Domain Driven Design
Instead of a horizontal approach like the pizza box architecture (layered).
We prefer the vertical approach where we divide the monolith into domains.
Thus, we have created independent, encapsulated domains, where the code from one domain must not know anything about the other domain (except via a defined API library).
Folder structure and naming-convention
The following structure is suitable, for example, for a monorepo with multiple applications. Each application has its own scope through its own folder. The individual domains follow below. Note that there can also be various shared folders, which differ in their scope.
Next steps
Since we have now built our codebase on libraries I recommend to set the module boundaries now.
Check out the nx-documentation therefore:
Subscribe to my newsletter
Read articles from Oliver Waterkamp directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
