| name | V3 Core Implementation |
| description | Core module implementation for claude-flow v3. Implements DDD domains, clean architecture patterns, dependency injection, and modular TypeScript codebase with comprehensive testing. |
V3 Core Implementation
What This Skill Does
Implements the core TypeScript modules for claude-flow v3 following Domain-Driven Design principles, clean architecture patterns, and modern TypeScript best practices with comprehensive test coverage.
Quick Start
Task("Core foundation", "Set up DDD domain structure and base classes", "core-implementer")
Task("Task domain", "Implement task management domain with entities and services", "core-implementer")
Task("Session domain", "Implement session management domain", "core-implementer")
Task("Health domain", "Implement health monitoring domain", "core-implementer")
Core Implementation Architecture
Domain Structure
src/
├── core/
│ ├── kernel/ # Microkernel pattern
│ │ ├── claude-flow-kernel.ts
│ │ ├── domain-registry.ts
│ │ └── plugin-loader.ts
│ │
│ ├── domains/ # DDD Bounded Contexts
│ │ ├── task-management/
│ │ │ ├── entities/
│ │ │ ├── value-objects/
│ │ │ ├── services/
│ │ │ ├── repositories/
│ │ │ └── events/
│ │ │
│ │ ├── session-management/
│ │ ├── health-monitoring/
│ │ ├── lifecycle-management/
│ │ └── event-coordination/
│ │
│ ├── shared/ # Shared kernel
│ │ ├── domain/
│ │ │ ├── entity.ts
│ │ │ ├── value-object.ts
│ │ │ ├── domain-event.ts
│ │ │ └── aggregate-root.ts
│ │ │
│ │ ├── infrastructure/
│ │ │ ├── event-bus.ts
│ │ │ ├── dependency-container.ts
│ │ │ └── logger.ts
│ │ │
│ │ └── types/
│ │ ├── common.ts
│ │ ├── errors.ts
│ │ └── interfaces.ts
│ │
│ └── application/ # Application services
│ ├── use-cases/
│ ├── commands/
│ ├── queries/
│ └── handlers/
Base Domain Classes
Entity Base Class
export abstract class Entity<T> {
protected readonly _id: T;
private _domainEvents: DomainEvent[] = [];
constructor(id: T) {
this._id = id;
}
get id(): T {
return this._id;
}
public equals(object?: Entity<T>): boolean {
if (object == null || object == undefined) {
return false;
}
if (this === object) {
return true;
}
if (!(object instanceof Entity)) {
return false;
}
return this._id === object._id;
}
protected addDomainEvent(domainEvent: DomainEvent): {
..(domainEvent);
}
(): [] {
.;
}
(): {
. = [];
}
}
Value Object Base Class
export abstract class ValueObject<T> {
protected readonly props: T;
constructor(props: T) {
this.props = Object.freeze(props);
}
public equals(object?: ValueObject<T>): boolean {
if (object == null || object == undefined) {
return false;
}
if (this === object) {
return true;
}
return JSON.stringify(this.props) === JSON.stringify(object.props);
}
get value(): T {
return this.props;
}
}
Aggregate Root
export abstract class AggregateRoot<T> extends Entity<T> {
private _version: number = 0;
get version(): number {
return this._version;
}
protected incrementVersion(): void {
this._version++;
}
public applyEvent(event: DomainEvent): void {
this.addDomainEvent(event);
this.incrementVersion();
}
}
Task Management Domain Implementation
Task Entity
import { AggregateRoot } from '../../../shared/domain/aggregate-root';
import { TaskId } from '../value-objects/task-id.vo';
import { TaskStatus } from '../value-objects/task-status.vo';
import { Priority } from '../value-objects/priority.vo';
import { TaskAssignedEvent } from '../events/task-assigned.event';
interface TaskProps {
id: TaskId;
description: string;
priority: Priority;
status: TaskStatus;
assignedAgentId?: string;
createdAt: Date;
updatedAt: Date;
}
export class Task extends AggregateRoot<TaskId> {
private props: TaskProps;
private constructor(props: TaskProps) {
(props.);
. = props;
}
(: , : ): {
task = ({
: .(),
description,
priority,
: .(),
: (),
: ()
});
task;
}
(: ): {
(props);
}
(: ): {
(...(.())) {
();
}
.. = agentId;
.. = .();
.. = ();
.( (
..,
agentId,
..
));
}
(: ): {
(!..) {
();
}
.. = .();
.. = ();
.( (
..,
result,
.()
));
}
(): { ..; }
(): { ..; }
(): { ..; }
(): | { ..; }
(): { ..; }
(): { ..; }
(): {
...() - ...();
}
}
Task Value Objects
export class TaskId extends ValueObject<string> {
private constructor(value: string) {
super({ value });
}
static create(): TaskId {
return new TaskId(crypto.randomUUID());
}
static fromString(id: string): TaskId {
if (!id || id.length === 0) {
throw new Error('TaskId cannot be empty');
}
return new TaskId(id);
}
get value(): string {
return this.props.value;
}
}
type TaskStatusType = 'pending' | 'assigned' | 'in_progress' | 'completed' | 'failed';
export <> {
() {
({ : status });
}
(): { (); }
(): { (); }
(): { (); }
(): { (); }
(): { (); }
(): {
..;
}
(): { . === ; }
(): { . === ; }
(): { . === ; }
(): { . === ; }
(): { . === ; }
}
= | | | ;
<> {
() {
({ : level });
}
(): { (); }
(): { (); }
(): { (); }
(): { (); }
(): {
..;
}
(): {
priorities = { : , : , : , : };
priorities[.];
}
}
Domain Services
Task Scheduling Service
import { Injectable } from '../../../shared/infrastructure/dependency-container';
import { Task } from '../entities/task.entity';
import { Priority } from '../value-objects/priority.vo';
@Injectable()
export class TaskSchedulingService {
public prioritizeTasks(tasks: Task[]): Task[] {
return tasks.sort((a, b) =>
b.priority.getNumericValue() - a.priority.getNumericValue()
);
}
public canSchedule(task: Task, agentCapacity: number): boolean {
if (agentCapacity <= 0) return false;
if (task.priority.equals(Priority.critical())) return true;
;
}
(: ): {
baseTime = ;
priorityMultiplier = {
: ,
: ,
: ,
:
};
baseTime * priorityMultiplier[task..];
}
}
Repository Interfaces & Implementations
Task Repository Interface
export interface ITaskRepository {
save(task: Task): Promise<void>;
findById(id: TaskId): Promise<Task | null>;
findByAgentId(agentId: string): Promise<Task[]>;
findByStatus(status: TaskStatus): Promise<Task[]>;
findPendingTasks(): Promise<Task[]>;
delete(id: TaskId): Promise<void>;
}
SQLite Implementation
@Injectable()
export class SqliteTaskRepository implements ITaskRepository {
constructor(
@Inject('Database') private db: Database,
@Inject('Logger') private logger: ILogger
) {}
async save(task: Task): Promise<void> {
const sql = `
INSERT OR REPLACE INTO tasks (
id, description, priority, status, assigned_agent_id, created_at, updated_at
) VALUES (?, ?, ?, ?, ?, ?, ?)
`;
await this.db.run(sql, [
task.id.value,
task.description,
task.priority.value,
task.status.value,
task.assignedAgentId,
task.createdAt.toISOString(),
task.updatedAt.toISOString()
]);
this.logger.debug(`Task saved: ${task.id.value}`);
}
(: ): < | > {
sql = ;
row = ..(sql, [id.]);
row ? .(row) : ;
}
(): <[]> {
sql = ;
rows = ..(sql, []);
rows.( .(row));
}
(: ): {
.({
: .(row.),
: row.,
: .(row.),
: .(row.),
: row.,
: (row.),
: (row.)
});
}
}
Application Layer
Use Case Implementation
@Injectable()
export class AssignTaskUseCase {
constructor(
@Inject('TaskRepository') private taskRepository: ITaskRepository,
@Inject('AgentRepository') private agentRepository: IAgentRepository,
@Inject('DomainEventBus') private eventBus: DomainEventBus,
@Inject('Logger') private logger: ILogger
) {}
async execute(command: AssignTaskCommand): Promise<AssignTaskResult> {
try {
await this.validateCommand(command);
const task = await this.taskRepository.findById(command.taskId);
if (!task) {
throw new TaskNotFoundError(command.taskId);
}
agent = ..(command.);
(!agent) {
(command.);
}
(!agent.(task)) {
(command., command.);
}
task.(command.);
agent.(task.);
.([
..(task),
..(agent)
]);
events = [
...task.(),
...agent.()
];
( event events) {
..(event);
}
task.();
agent.();
..();
.({
: task.,
: command.,
: ()
});
} (error) {
..(, error);
.(error);
}
}
(: ): <> {
(!command.) {
();
}
(!command.) {
();
}
}
}
Dependency Injection Setup
Container Configuration
import { Container } from 'inversify';
import { TYPES } from './types';
export class DependencyContainer {
private container: Container;
constructor() {
this.container = new Container();
this.setupBindings();
}
private setupBindings(): void {
this.container.bind<ITaskRepository>(TYPES.TaskRepository)
.to(SqliteTaskRepository)
.inSingletonScope();
this.container.bind<IAgentRepository>(TYPES.AgentRepository)
.to(SqliteAgentRepository)
.inSingletonScope();
this.container.bind<>(.)
.()
.();
..<>(.)
.()
.();
..<>(.)
.()
.();
..<>(.)
.()
.();
}
get<T>(: ): T {
..<T>(serviceIdentifier);
}
bind<T>(: ): <T> {
..<T>(serviceIdentifier);
}
}
Modern TypeScript Configuration
Strict TypeScript Setup
{
"compilerOptions": {
"target": "ES2022",
"lib": ["ES2022"],
"module": "NodeNext",
"moduleResolution": "NodeNext",
"declaration": true,
"outDir": "./dist",
"strict": true,
"exactOptionalPropertyTypes": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedIndexedAccess": true,
"noImplicitOverride"
Testing Implementation
Domain Unit Tests
describe('Task Entity', () => {
let task: Task;
beforeEach(() => {
task = Task.create('Test task', Priority.medium());
});
describe('creation', () => {
it('should create task with pending status', () => {
expect(task.status.isPending()).toBe(true);
expect(task.description).toBe('Test task');
expect(task.priority.equals(Priority.medium())).toBe(true);
});
it('should generate unique ID', () => {
const task1 = Task.create('Task 1', Priority.low());
const task2 = Task.create('Task 2', .());
(task1..(task2.)).();
});
});
(, {
(, {
agentId = ;
task.(agentId);
(task.).(agentId);
(task..()).();
});
(, {
agentId = ;
task.(agentId);
events = task.();
(events).();
(events[]).();
});
(, {
task.();
task.(.());
( task.())
.();
});
});
});
Integration Tests
describe('TaskRepository Integration', () => {
let repository: SqliteTaskRepository;
let db: Database;
beforeEach(async () => {
db = new Database(':memory:');
await setupTasksTable(db);
repository = new SqliteTaskRepository(db, new ConsoleLogger());
});
afterEach(async () => {
await db.close();
});
it('should save and retrieve task', async () => {
const task = Task.create('Test task', Priority.high());
await repository.save(task);
const retrieved = await repository.findById(task.id);
expect(retrieved).toBeDefined();
expect(retrieved!.id.equals(task.id)).toBe();
(retrieved!.).();
(retrieved!..(.())).();
});
(, () => {
lowTask = .(, .());
highTask = .(, .());
repository.(lowTask);
repository.(highTask);
pending = repository.();
(pending).();
(pending[]..(highTask.)).();
(pending[]..(lowTask.)).();
});
});
Performance Optimizations
Entity Caching
@Injectable()
export class EntityCache<T extends Entity<any>> {
private cache = new Map<string, { entity: T; timestamp: number }>();
private readonly ttl: number = 300000;
set(id: string, entity: T): void {
this.cache.set(id, { entity, timestamp: Date.now() });
}
get(id: string): T | null {
const cached = this.cache.get(id);
if (!cached) return null;
if (Date.now() - cached.timestamp > this.ttl) {
this.cache.delete(id);
;
}
cached.;
}
(: ): {
..(id);
}
(): {
..();
}
}
Success Metrics
Related V3 Skills
v3-ddd-architecture - DDD architectural design
v3-mcp-optimization - MCP server integration
v3-memory-unification - AgentDB repository integration
v3-swarm-coordination - Swarm domain implementation
Usage Examples
Complete Core Implementation
Task("Core implementation",
"Implement all core domains with DDD patterns and comprehensive testing",
"core-implementer")
Domain-Specific Implementation
Task("Task domain implementation",
"Implement task management domain with entities, services, and repositories",
"core-implementer")