A TypeScript library providing entity interfaces for Pure Architecture domain modeling.
This library provides TypeScript interfaces for building domain entities in Pure Architecture applications. It includes three core entity types that handle common lifecycle patterns:
- ImmutableEntity: Base entities that cannot be modified after creation
- UpdatableEntity: Entities that can be updated after creation
- SoftRemovableEntity: Entities supporting soft deletion
All entities support custom identifier types.
npm install @gilles-coudert/pure-architecture-entitiesimport {
ImmutableEntity,
UpdatableEntity,
SoftRemovableEntity,
} from '@gilles-coudert/pure-architecture-entities';
// Define an immutable entity
interface User extends ImmutableEntity<string> {
email: string;
username: string;
}
// Define an updatable entity
interface Article extends UpdatableEntity<string> {
title: string;
content: string;
}
// Define a soft-removable entity
interface Post extends SoftRemovableEntity<number> {
title: string;
body: string;
}Base interface for entities that cannot be modified after creation.
interface ImmutableEntity<TId = string> {
id: TId;
createdAt: Date;
}Type Parameters:
-
TId: The type of the entity identifier (defaults tostring)
Properties:
-
id: Unique identifier for the entity -
createdAt: Timestamp when the entity was created
Interface for entities that can be updated after creation. Extends ImmutableEntity.
interface UpdatableEntity<TId = string> extends ImmutableEntity<TId> {
updatedAt: Date;
}Additional Properties:
-
updatedAt: Timestamp of the last update to the entity
Interface for entities that support soft deletion. Extends ImmutableEntity.
interface SoftRemovableEntity<TId = string> extends ImmutableEntity<TId> {
removedAt: Date;
}Additional Properties:
-
removedAt: Timestamp when the entity was soft deleted
import { ImmutableEntity } from '@gilles-coudert/pure-architecture-entities';
interface Product extends ImmutableEntity {
name: string;
price: number;
sku: string;
}
const product: Product = {
id: 'prod-123',
createdAt: new Date(),
accessPolicy: undefined,
name: 'Widget',
price: 29.99,
sku: 'WID-001',
}; price: 29.99,
sku: 'WID-001',
};
import { UpdatableEntity } from '@gilles-coudert/pure-architecture-entities';
interface Order extends UpdatableEntity<number> {
customerId: number;
items: OrderItem[];
total: number;
}
const order: Order = {
id: 12345,
createdAt: new Date(),
updatedAt: new Date(),
customerId: 67890,
items: [],
total: 0,
};import { SoftRemovableEntity } from '@gilles-coudert/pure-architecture-entities';
interface Document extends SoftRemovableEntity<string> {
title: string;
content: string;
}
const document: Document = {
id: 'doc-456',
createdAt: new Date(),
removedAt: new Date()
- Node.js 24 or higher
- npm or yarn
### Setup
```bash
# Clone the repository
git clone https://github.com/GillesCoudert/PureArchitecture-Entities.git
cd PureArchitecture-Entities
# Install dependencies
npm install
# Build the project
npm run build-
npm run build- Compile TypeScript to JavaScript -
npm run test- Run tests with Jest -
npm run lint- Lint code with ESLint
This project uses a comprehensive ESLint configuration tailored for Pure Architecture projects:
-
Strict TypeScript: Enforces explicit return types and prevents use of
any - Naming Conventions: Enforces PascalCase for interfaces, types, and classes
- Code Quality: Limits complexity, file size, and function parameters
- Best Practices: Enforces modern JavaScript/TypeScript patterns
Run linting with:
npm run lintContributions are welcome.
Branch prefixes are required and define the semantic impact of the change:
-
upgrade/→ breaking changes (major version) -
us/→ new features (minor version) -
fix/→ bug fixes (patch version)
Versioning information belongs to the branch, not individual commits.
Branches express intent and scope.
Commits should stay frequent, descriptive, and free of artificial prefixes that often degrade into wip: or chore: without semantic value.
This project is licensed under the Mozilla Public License 2.0 - see the LICENSE file for details.
Gilles Coudert
- Email: pure.framework@gmail.com
- GitHub: @GillesCoudert
- @gilles-coudert/pure-architecture - Core Pure Architecture framework
For issues and questions:
- GitHub Issues: PureArchitecture-Entities/issues
- Email: pure.framework@gmail.com