Section 6 of 17
Library types
Contents
Each type answers one question. If a file answers two, it is two files.
| Type | Question it answers | Contains | Must not contain |
|---|---|---|---|
feature |
What does this use case do? | Routed pages, smart components, wiring of facade to ui | HTTP calls, reusable visual components |
ui |
How does it look? | Presentational components, pipes, directives | Injected stores, services with state, HTTP |
data-access |
Where does the data come from and how does it change? | Store, effects, API clients, facade, providers | Components |
model |
What are the domain's terms and rules? | Types, enums, pure functions such as isOverdue |
Framework imports of any kind |
util |
Which technical helpers does this need? | Formatting, parsing, small algorithms | Domain terms, framework state |
api |
What may other domains use? | Re-exports of a chosen subset of the domain | Its own logic |
shell |
How is this domain mounted? | Routes, route-level providers, guards | Business logic |
6.1. Who may import whom
| From ↓ may import → | shell | feature | ui | data-access | model | util | api of another domain |
|---|---|---|---|---|---|---|---|
| app | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | – |
| shell | – | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| feature | – | – | ✓ | ✓ | ✓ | ✓ | ✓ |
| api | – | ✓ | ✓ | ✓ | ✓ | ✓ | – |
| ui | – | – | ✓ | – | ✓ | ✓ | – |
| data-access | – | – | – | ✓ | ✓ | ✓ | – |
| model | – | – | – | – | ✓ | ✓ | – |
| util | – | – | – | – | – | ✓ | – |
Three lines in this table carry most of the value:
- feature → feature is forbidden. Two pages that need the same thing share it through
uiordata-access. Pages are composed by the shell or the router, not by importing each other. - ui → data-access is forbidden. A component that injects a store is not presentational. Because of this rule the
WorkOrdertype lives inmodel, not indata-access. - model imports no framework.
modelandutilcompile in Angular, React, Vue and Node alike. In a mixed workspace they are the code you share (section 8.3).
6.2. How big is a library
- feature: one use case, usually one route and its children.
feature-work-orders, notfeature-maintenance. - ui: one cohesive group that changes together.
ui-work-order-cardholds the card, the status chip and the status filter. - data-access: one per domain to start. Split by sub-domain when it holds more than three or four store features or the team splits (
data-access-planning,data-access-work-orders). - model: one per domain. It is small by nature.
- If a library has one file, it is probably too small; if its
index.tsexports more than about thirty symbols, it is probably too big.
6.3. Styles
Styles are subject to the same boundaries as TypeScript, but the boundary rule cannot see them: Nx builds the dependency graph from TypeScript and JavaScript imports and ignores @use in SCSS. That is why styles get four rules of their own:
- A component styles only itself, in a file next to it. A library never defines a global class, so
.cardfrom maintenance and.cardfrom billing cannot collide. - The design system speaks through CSS variables. Tokens (colors, spacing, radii, typography) are custom properties from
shared/ui-design-system. Domain components readvar(--ds-…)and never@useSCSS files from other libraries. - Only the application has global styles: reset, fonts and tokens, in one place.
- Nobody styles the inside of someone else's component. A component that should be customizable exposes an input, a prop or a CSS variable.
| Angular | React / Next.js | Vue / Nuxt | |
|---|---|---|---|
| Component styles | styleUrl with the default emulated encapsulation |
CSS Modules: *.module.scss |
<style scoped lang="scss"> |
| Global styles | apps/<app>/src/styles.scss |
an import in the app's app/layout.tsx |
css in nuxt.config.ts |
| Forbidden in libraries | ::ng-deep, ViewEncapsulation.None |
:global(...), importing plain .css |
:deep(...), <style> without scoped |
libs/shared/ui-design-system/src/styles/tokens.scss
:root {
--ds-surface: #ffffff;
--ds-text: #1b1f24;
--ds-text-muted: #59636e;
--ds-danger: #c62828;
--ds-radius: 8px;
--ds-space-2: 8px;
--ds-space-3: 12px;
}
libs/maintenance/ui-work-order-card/src/lib/work-order-card.component.scss
.card {
display: grid;
gap: var(--ds-space-2);
padding: var(--ds-space-3);
border-radius: var(--ds-radius);
background: var(--ds-surface);
color: var(--ds-text);
}
.card--overdue {
border-left: 4px solid var(--ds-danger);
}
.vehicle,
.due {
color: var(--ds-text-muted);
}
In React the same CSS rules go into work-order-card.module.scss, in Vue into the component's <style scoped> block. Stylelint in CI rejects the selectors from the last row of the table (selector-disallowed-list). Rule 2 is checked by a single grep command in CI: @use in a domain library may point only to files of the same library, never to an @fleetline/ alias.