hexon
v1.0.0
Published
Framework-agnostic DDD-lite core for hexagonal architecture
Maintainers
Readme
✨ Overview
hexon is a lightweight, framework-agnostic toolkit for building applications using Domain-Driven Design (DDD-lite) and Hexagonal / Clean Architecture principles.
It focuses on clear domain boundaries, not frameworks.
🎯 Features
- ✅ Entities & Value Objects
- ✅ Use Cases (Application layer)
- ✅ Typed Dependency Injection
- ✅ Domain-safe error handling
- ✅ Framework-agnostic (Node, Browser, Worker)
- ❌ No React
- ❌ No UI
- ❌ No magic
📦 Installation
npm install hexon
# or
yarn add hexon
# or
pnpm add hexon🚀 Usage Example
1️⃣ Domain Entity
import { Entity, DomainError } from "hexon"
export class UserAccount extends Entity<string> {
constructor(
id: string,
private active: boolean
) {
super(id)
}
activate() {
if (this.active) {
throw new DomainError("Account is already active")
}
this.active = true
}
isActive() {
return this.active
}
}2️⃣ Repository Interface (Domain Port)
export interface UserAccountRepository {
get(id: string): Promise<UserAccount>
save(account: UserAccount): Promise<void>
}3️⃣ Use Case (Application Layer)
import { UseCase, Result, ok } from "hexon"
type Input = { userId: string }
export class ActivateAccount
implements UseCase<Input, UserAccount>
{
constructor(
private readonly repo: UserAccountRepository
) {}
async execute(
input: Input
): Promise<Result<UserAccount>> {
const account = await this.repo.get(input.userId)
account.activate()
await this.repo.save(account)
return ok(account)
}
}4️⃣ Dependency Injection
import { createToken, container } from "hexon"
const USER_ACCOUNT_REPOSITORY =
createToken<UserAccountRepository>(
"UserAccountRepository"
)
container.register(
USER_ACCOUNT_REPOSITORY,
() => new ApiUserAccountRepository()
)5️⃣ Runtime Execution
const repo = container.resolve(USER_ACCOUNT_REPOSITORY)
const useCase = new ActivateAccount(repo)
const result = await useCase.execute({
userId: "user-1"
})
if (result.ok) {
console.log(
"Account active:",
result.data.isActive()
)
}🧠 Architecture Philosophy
Domain
├─ Entities
├─ Value Objects
└─ Business Rules
Application
├─ Use Cases
└─ Ports (Interfaces)
Infrastructure
├─ API / DB / Cache
└─ Adapters (outside hexon)- hexon lives in the center.
- Frameworks stay at the edges.
📄 License
MIT
