01Architecture is dependency direction
Folder names matter less than people think. What matters is which code is allowed to import which. When any file can import any other, a change in one feature ripples into five, and nobody can say what's safe to refactor.
The structure I use on enterprise Angular apps has four kinds of code, and dependencies only flow one way: features depend on shared code, never the reverse, and features never depend on each other.
02The four layers
-
01
core/: app-wide, created onceAuth, interceptors, error handling, the app shell, global config. Provided in
app.config.ts. Features use it; it never imports a feature. -
02
shared/ui/: presentational componentsButtons, tables, dialogs, form fields and library wrappers. Inputs in, outputs out, no services, no HTTP. The easiest code in the app to test and reuse.
-
03
shared/data/: APIs and modelsTyped API clients and domain models used by more than one feature. No components, so it can't accidentally pull UI into a service.
-
04
features/*: one folder per product areaClients, billing, documents. Each has a
routes.ts, its own components and stores, and is lazy-loaded. Features never import from each other. -
05
Cross-feature needs go down, not sideways
If billing needs something from clients, that thing moves to
shared/, or the two communicate through the router or a core service. -
06
Lint the rules, don't document them
An import-boundary lint rule fails the build on a forbidden import. A wiki page about architecture gets ignored by the third sprint.
03Smart and presentational, at the feature level
Inside each feature, route components are the "smart" layer: they inject stores, read route params and coordinate. Everything below them is presentational and takes data through inputs. That keeps business logic in a handful of places instead of spread through every child component.
This also makes OnPush the default without extra effort: presentational components only change when their inputs change, which is exactly what OnPush assumes.
04The folder tree and its rules
This is the shape, plus the lint configuration that enforces it. I use eslint-plugin-boundaries here; Nx users get the same with tags and @nx/enforce-module-boundaries.
src/app/
├── core/ # auth, interceptors, shell, error handling
├── shared/
│ ├── ui/ # presentational components + library wrappers
│ └── data/ # API clients, models
└── features/
├── clients/ # routes.ts, pages, components, store
├── billing/
└── documents/
// eslint.config.js (eslint-plugin-boundaries)
'boundaries/element-types': ['error', {
default: 'disallow',
rules: [
{ from: 'feature', allow: ['shared-ui', 'shared-data', 'core'] },
{ from: 'core', allow: ['shared-ui', 'shared-data'] },
{ from: 'shared-ui', allow: ['shared-ui'] },
{ from: 'shared-data', allow: ['shared-data'] },
],
}],
The takeaway
Pick a small number of layers, make dependencies flow in one direction, keep features isolated from each other, and enforce it with lint. The payoff isn't elegance — it's being able to change one feature without fearing the other five.