๐๏ธ Features Pattern
NestFlux follows a consistent feature-based architecture pattern across both client and server applications to promote code organization, maintainability, and scalability.
๐ Folder Structure Overviewโ
src/
โโโ core/ # Core framework functionality (managed by NestFlux)
โโโ common/ # Reusable code across multiple features
โโโ features/ # Application-specific features
๐ Pattern Philosophyโ
โ๏ธ Core Folderโ
- Contains essential framework functionality required to run the application
- Handles core concepts like authentication or API configuration
- Provides the foundational infrastructure that features and common code depend on
- Managed by NestFlux: Updates to NestFlux will primarily affect core folders
๐ Common Folderโ
- Contains reusable code that's shared across multiple features
- Used for project-specific functionality that spans multiple business domains
- Should be generic enough to be used in various contexts within your project
๐ฆ Features Folderโ
- Contains application-specific code that implements business requirements
- Each feature represents a distinct domain or functionality
- Features can be nested with unlimited depth for complex domains
- Should be cohesive and focused on a specific business capability
When updating NestFlux to newer versions, changes will primarily affect the core/
folders. The common/
and features/
folders will rarely be modified, ensuring your custom business logic and project-specific code remains stable across updates.
๐ Documentationโ
Every feature (both in core/
, common/
and features/
) must include a FEATURE.md file that documents its purpose, responsibilities, and usage examples. This ensures consistent documentation across the codebase and helps developers understand each feature's role. See the FEATURE.md template for the complete documentation structure.
The distinction between core/
, features/
and common/
is for code organization only. There are no restrictions on code reuse - features can import from other features, and common code can be used anywhere. The goal is to structure code logically while maintaining full flexibility for code sharing and reusability.
๐๏ธ Feature structuresโ
Each application type (client and server) has its own specific folder structure tailored to its technology stack and architectural patterns:
- Client features are designed around React patterns - components, hooks, and client-side logic
- Server features follow NestJS conventions - controllers, services, modules, and server-side architecture
- Both share common folder types (lib, types, data) for consistency where it makes sense
- This approach ensures each application follows its framework's best practices while maintaining the overall feature pattern consistency
๐๏ธ Feature Grouping Ruleโ
Important: If a feature contains sub-features, it becomes a grouping feature and cannot contain its own feature content (components, hooks, services, etc.). It can only contain:
FEATURE.md
(required documentation)- Sub-feature folders
Example of a grouping feature:
user-management/ # Grouping feature - no feature content allowed
โโโ FEATURE.md # Only documentation allowed
โโโ user-profile/ # Sub-feature with actual implementation
โ โโโ FEATURE.md
โ โโโ components/
โ โ โโโ profile-form.tsx
โ โโโ hooks/
โ โโโ use-profile.ts
โโโ user-settings/ # Another sub-feature
โ โโโ FEATURE.md
โ โโโ components/
โ โ โโโ settings-panel.tsx
โ โโโ lib/
โ โโโ settings-utils.ts
โโโ user-permissions/ # Third sub-feature
โโโ FEATURE.md
โโโ services/
โ โโโ permissions.service.ts
โโโ types/
โโโ permissions.types.ts
This ensures clear separation between organizational structure and implementation details.
๐ป Client Feature Structureโ
Each client feature follows this hierarchy:
feature-name/
โโโ FEATURE.md # Feature documentation
โโโ api/ # API queries and mutations (TanStack Query)
โ โโโ use-sth.query.ts # Data fetching queries
โ โโโ use-sth.mutation.ts # Data modification operations
โโโ components/ # React components specific to this feature
โ โโโ feature-component.tsx
โโโ data/ # Static configuration and constants
โ โโโ feature-config.ts
โโโ hooks/ # Custom React hooks for this feature
โ โโโ use-feature-hook.ts
โโโ lib/ # Business logic and utilities
โ โโโ feature-utils.ts
โโโ types/ # TypeScript types specific to this feature
โโโ feature.types.ts
๐ Server Feature Structureโ
Each server feature follows this hierarchy:
feature-name/
โโโ FEATURE.md # Feature documentation
โโโ feature.controller.ts # NestJS controller (if needed. Can have more than one)
โโโ feature.service.ts # NestJS service (if needed. Can have more than one)
โโโ feature.module.ts # NestJS module (if needed. Usually one per feature)
โโโ data/ # Static configuration and constants
โ โโโ feature-config.ts
โโโ decorators/ # Custom decorators (if needed)
โ โโโ feature.decorator.ts
โโโ guards/ # Custom guards (if needed)
โ โโโ feature.guard.ts
โโโ strategies/ # Authentication strategies (if needed)
โ โโโ feature.strategy.ts
โโโ lib/ # Business logic and utilities
โ โโโ feature-utils.ts
โโโ repositories/ # Database operations
โ โโโ feature.repository.ts
โโโ types/ # TypeScript types specific to this feature
โโโ feature.types.ts
๐ FEATURE.md Templateโ
Each feature must include a FEATURE.md
file following this template:
# Feature Name
## ๐ Overview
Brief description of what this feature does and its purpose.
## ๐ฏ Responsibilities
- List the main responsibilities of this feature
- What business logic it handles
- What problems it solves
## ๐ง Known Limitations (optional)
- Current limitations or technical debt
- Future improvements planned
## ๐ Related Documentation (optional)
- Links to relevant docs
- API specifications
- Design documents