Skip to content

Commit 41cf8e2

Browse files
committed
docs: apply code review comments
1 parent 26bde66 commit 41cf8e2

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

β€Ži18n/en/docusaurus-plugin-content-docs/current/guides/issues/excessive-entities.mdβ€Ž

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,26 @@ Excessive entities can lead to ambiguity (what code belongs to this layer), coup
66

77
## How to keep `entities` layer clean
88

9-
To keep a maintainable `entities` layer, consider the following principles based on the application's data processing needs. Keep in mind that this classification is not strictly binary, as different parts of the same application may have β€œthin” or β€œthick” parts:
9+
### 0. Consider having no `entities` layer
1010

11-
- Thin Clients: These applications rely on the backend for most data processing. They often do not require an `entities` layer, as client-side business logic is minimal and involves only data retrieval.
12-
- Thick Clients: These handle significant client-side business logic, making them suitable candidates for the `entities` layer.
11+
You might think that your application won't be Feature-Sliced if you don't include this layer, but it is completely fine for the application to have no `entities` layer. It doesn't break FSD in any way, on the contrary, it simplifies the architecture and keeps the `entities` layer available for future scaling. For example, if your application acts as a thin client, most likely it doesn't need `entities` layer.
1312

14-
It is acceptable for an application to lack an `entities` layer if it functions as a thin client. This simplifies the architecture and keeps the `entities` layer available for future scaling if needed.
13+
:::info[What are thick and thin clients?]
1514

16-
### Avoid Unnecessary Entities
15+
_Thick_ vs. _thin client_ distinction refers to how the application processes data:
16+
17+
- _Thin_ clients rely on the backend for most data processing. Client-side business logic is minimal and involves only exchanging data with the backend.
18+
- _Thick_ clients handle significant client-side business logic, making them suitable candidates for the `entities` layer.
19+
20+
Keep in mind that this classification is not strictly binary, and different parts of the same application may act as a "thick" or a "thin" client.
21+
22+
:::
23+
24+
### 1. Avoid preemptive slicing
25+
26+
In contrast to previous versions, FSD 2.1 encourages deferred decomposition of slices instead of preemptive, and this approach also extends to `entities` layer. At first, you can place all your code in the `model` segment of your page (widget, feature), and then consider refactoring it later, when business requirements are stable. Remember: it is much easier and safer to move something into `entities` later, than refactor code inside `entities` that can affect any upper level slice functionality.
27+
28+
### 2. Avoid Unnecessary Entities
1729

1830
Do not create an entity for every piece of business logic. Instead, leverage types from `shared/api` and place logic in the `model` segment of a current slice. For reusable business logic, use the `model` segment within an entity slice while keeping data definitions in `shared/api`:
1931

@@ -30,7 +42,7 @@ Do not create an entity for every piece of business logic. Instead, leverage typ
3042
πŸ“„ order.ts
3143
```
3244

33-
### Exclude CRUD Operations from Entities
45+
### 3. Exclude CRUD Operations from Entities
3446

3547
CRUD operations, while essential, often involve boilerplate code without significant business logic. Including them in the `entities` layer can clutter it and obscure meaningful code. Instead, place CRUD operations in `shared/api`:
3648

@@ -47,9 +59,9 @@ CRUD operations, while essential, often involve boilerplate code without signifi
4759

4860
For complex CRUD operations (e.g., atomic updates, rollbacks, or transactions), evaluate whether the `entities` layer is appropriate, but use it with caution.
4961

50-
### Store Authentication Data in `shared`
62+
### 4. Store Authentication Data in `shared`
5163

52-
Avoid creating a `user` entity for authentication data, such as tokens or user DTOs returned from the backend. These are context-specific and unlikely to be reused outside authentication:
64+
Prefer `shared` layer to creating a `user` entity for authentication data, such as tokens or user DTOs returned from the backend. These are context-specific and unlikely to be reused outside authentication scope:
5365

5466
- Authentication responses (e.g., tokens or DTOs) often lack fields needed for broader reuse or vary by context (e.g., private vs. public user profiles).
5567
- Using entities for auth data can lead to cross-layer imports (e.g., `entities` into `shared`) or usage of `@x` notation, complicating the architecture.
@@ -59,7 +71,7 @@ Instead, store authentication-related data in `shared/auth` or `shared/api`:
5971
```plaintext
6072
πŸ“‚ shared
6173
πŸ“‚ auth
62-
πŸ“„ use-auth.ts // Hook returning authenticated user info or token
74+
πŸ“„ use-auth.ts // authenticated user info or token
6375
πŸ“„ index.ts
6476
πŸ“‚ api
6577
πŸ“„ client.ts
@@ -68,7 +80,7 @@ Instead, store authentication-related data in `shared/auth` or `shared/api`:
6880
πŸ“„ order.ts
6981
```
7082

71-
### Minimize Cross-Imports
83+
### 5. Minimize Cross-Imports
7284

7385
FSD permits cross-imports via `@x` notation, but they can introduce technical issues like circular dependencies. To avoid this, design entities within isolated business contexts to eliminate the need for cross-imports:
7486

0 commit comments

Comments
Β (0)