54 lines
1.6 KiB
Markdown
54 lines
1.6 KiB
Markdown
# Entities
|
|
|
|
## Purpose
|
|
|
|
The `entities` layer defines the **core domain models of the application**.
|
|
|
|
Entities represent **business objects** used throughout the system, such as `User`, `Product`, `Project`, or `Message`.
|
|
|
|
This layer contains **pure type definitions** that describe how data is structured inside the application.
|
|
Entities are **stable, reusable models** that can be used across any layer.
|
|
|
|
```plaintext
|
|
entities/
|
|
| --- user.ts # { id: string; name: string; email: string }
|
|
| --- product.ts # { id: string; name: string; price: number }
|
|
| --- message.ts # { id: string; content: string; createdAt: string }
|
|
| --- enums.ts # { UserRole, ProductCategory }
|
|
```
|
|
|
|
or
|
|
|
|
```plaintext
|
|
entities/
|
|
| --- user/
|
|
| | --- interfaces.ts # { id: string; name: string; email: string }
|
|
| | --- types.ts # { id: string; name: string; email: string }
|
|
| | --- enums.ts # { UserRole }
|
|
| | --- rules.ts # MIN_ALLOWED_AGE = 18
|
|
| | --- index.ts # export all entity types
|
|
| --- product.ts # { id: string; name: string; price: number }
|
|
| --- message.ts # { id: string; content: string; createdAt: string }
|
|
```
|
|
|
|
## Responsibilities
|
|
|
|
The entities layer is responsible for:
|
|
|
|
- defining **domain models**
|
|
- defining **entity-related enums or constants**
|
|
- providing **shared types used across the application**
|
|
|
|
```ts
|
|
export type User = {
|
|
id: number;
|
|
name: string;
|
|
email: string;
|
|
};
|
|
|
|
export enum UserRole {
|
|
ADMIN = "admin",
|
|
SIMLPE_JACK = "simple_jack",
|
|
}
|
|
```
|