Documentation
Types of libs
Documentation on the types of libs in Nitrokit
Workspaces and Encapsulation
Types of Libraries
In this section, we will break down the different types of libraries and how they help in organizing your code. Properly structuring your libraries is key to maintaining scalability and improving workflow efficiency.
Types of Lib Projects
- π feat (lib): Contains feature logic like Smart and UI components.
- πΌοΈ ui (lib): Contains only reusable UI components.
- π state (lib): Manages state machines that can be reused across features.
- π§ util (lib): Houses utilities that are reused across different libs.
- π data-access (lib): Contains logic that connects to APIs or other IO operations.
- π type (lib): Stores reusable types and interfaces.
- π‘ guard (lib): Holds reusable guards for route protection.
- π const (lib): Contains reusable constants.
- πΎ backend (lib): Contains backend stuff.
These library categories are essential to scaling massive workspaces. Their clear purposes enable clean architecture and efficient feature implementation.
Feat Library π
A feat library acts as the presentation layer of a specific feature.
- Contains: UI components, Smart components, interceptors, directives, pipes, types, interfaces, state-machines, utilities, guards, services, constants.
- Lazy-loaded to improve performance.
- Exposes: Only Smart components (if reusable) and route configurations.
- Example:
feat-user-management
Only expose what is necessary to maintain a clean, modular architecture.
UI Library πΌοΈ
A ui library is dedicated to reusable UI components.
- Contains: UI components, directives, pipes, types, interfaces, utilities, services, state-machines, constants.
- Exposes: UI components, directives, pipes, and their types.
- No Smart components allowed.
- Example:
ui-forms
,ui-design-system
Create UI libs only when components need to be reused. Keep it lean by exposing only whatβs required.
State Library π
State libraries manage reusable state machines.
- Contains: State-machines, types, interfaces, utilities, services, constants.
- Exposes: State-machines, types.
- Example:
state-global
,state-chatbox
,state-users
State libraries should be as lightweight as possible, focusing only on what's needed for efficient state management.
Util Library π§
A util library contains utilities and helper functions.
- Contains: Utilities, types, constants, services (but not data-services).
- Exposes: Utilities and services.
- Example: Use for reusable pure functions.
Create util libraries only when utilities need to be reused across different libs.
Data Access Library π
Data-access libraries manage communication with APIs and external data sources.
- Contains: Data-services, types, interfaces, utilities, interceptors, constants.
- Exposes: Data-services, interceptors.
- Example:
data-access-user-service
All data-related operations should be kept here, separate from feature logic.
Type Library π
The type library stores reusable types and interfaces.
- Contains: Types, interfaces.
- Exposes: Types, interfaces.
- Example:
type-user
This library should be used only for types and interfaces, without any logic.
Guard Library π‘
Guard libraries store reusable guards for route protection.
- Contains: Guards, types, interfaces, constants.
- Exposes: Guards.
- Example:
guard-auth
Guards must be able to access the data-access layer for security and routing purposes.
Const Library π
Const libraries contain reusable constants.
- Contains: Constants.
- Exposes: Constants.
This library exists to avoid circular references between constants and types.
Backend Library πΎ
Backend libraries contain reusable constants.
- Contains: backend stuff.
- Exposes: backend stuff.
Library Import Rules
The table below illustrates the allowed dependencies between different library types:
feat | data-access | ui | type | util | state | guard | const | backend | |
---|---|---|---|---|---|---|---|---|---|
feat | β | β | β | β | β | β | β | β | π« |
data-access | π« | β | π« | β | β | π« | π« | β | π« |
ui | π« | π« | β | β | β | π« | π« | β | π« |
type | π« | π« | π« | β | π« | π« | π« | β | π« |
util | π« | π« | π« | β | β | π« | π« | β | π« |
state | π« | β | π« | β | β | β | π« | β | π« |
guard | π« | β | π« | β | β | β | β | β | π« |
const | π« | π« | π« | β | π« | π« | π« | β | π« |
backend | π« | π« | π« | β | β | π« | π« | β | β |
This matrix ensures modularity by defining clear import boundaries between different library types.
This forms the foundation for scalable architecture in Nitrokit.
Have questions?
Still have questions? Talk to support.