Skip to content

armgit / ruflo

Public Imported from GitHub
0

🌊 The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated

4.8 KB
Raw Blame

ADR-002: Implement Domain-Driven Design Structure

Status: Implemented Date: 2026-01-03

Context

Current v2 structure organizes code by technical layer (cli/, core/, mcp/, swarm/), making it difficult to understand complete features and leading to high coupling between layers.

Problems:

  • Feature code scattered across 5+ directories
  • Unclear ownership and boundaries
  • Changes require touching many files
  • Difficult for new contributors to navigate

Example: Agent Management Feature

Current (scattered):
β”œβ”€β”€ cli/commands/agent.ts          # CLI interface
β”œβ”€β”€ core/orchestrator.ts           # Orchestration logic
β”œβ”€β”€ agents/agent-manager.ts        # Management logic
β”œβ”€β”€ mcp/tools.ts                   # MCP tools
└── swarm/coordinator.ts           # Coordination logic

Proposed (cohesive):
└── agent-lifecycle/
    β”œβ”€β”€ api/cli/agent-commands.ts
    β”œβ”€β”€ api/mcp/agent-tools.ts
    β”œβ”€β”€ application/agent-service.ts
    β”œβ”€β”€ domain/agent.ts
    └── infrastructure/agent-repository.ts

Decision

We will restructure v3 using Domain-Driven Design (DDD) principles with clear bounded contexts.

Structure:

src/
β”œβ”€β”€ agent-lifecycle/      # Bounded Context 1
β”‚   β”œβ”€β”€ domain/          # Business logic, entities
β”‚   β”œβ”€β”€ application/     # Use cases, services
β”‚   β”œβ”€β”€ infrastructure/  # Persistence, external systems
β”‚   └── api/            # External interfaces (CLI, MCP)
β”œβ”€β”€ task-execution/      # Bounded Context 2
β”œβ”€β”€ memory-management/   # Bounded Context 3
β”œβ”€β”€ coordination/        # Bounded Context 4
β”œβ”€β”€ shared-kernel/       # Shared types and utilities
└── infrastructure/      # Cross-cutting concerns

Layer Rules:

  1. Domain layer: No external dependencies, pure business logic
  2. Application layer: Orchestrates domain, no infrastructure details
  3. Infrastructure layer: Implements technical concerns
  4. API layer: Thin adapters to external world

Rationale

Benefits:

  • Features colocated, easy to find
  • Clear boundaries reduce coupling
  • Easy to understand and modify
  • Enables team scaling (own a domain)
  • Facilitates testing (mock boundaries)
  • Supports microservices future (extract domains)

Costs:

  • Migration effort from v2 structure
  • Learning curve for DDD concepts
  • More directories to navigate
  • Requires discipline to maintain boundaries

Implementation

Directory Template:

domain-name/
β”œβ”€β”€ domain/
β”‚   β”œβ”€β”€ models/           # Entities, value objects
β”‚   β”œβ”€β”€ interfaces/       # Repository interfaces
β”‚   β”œβ”€β”€ events/          # Domain events
β”‚   └── services/        # Domain services
β”œβ”€β”€ application/
β”‚   β”œβ”€β”€ services/        # Application services
β”‚   β”œβ”€β”€ handlers/        # Event handlers
β”‚   └── queries/         # Query services (CQRS)
β”œβ”€β”€ infrastructure/
β”‚   β”œβ”€β”€ repositories/    # Repository implementations
β”‚   β”œβ”€β”€ adapters/        # External system adapters
β”‚   └── persistence/     # Persistence implementations
└── api/
    β”œβ”€β”€ cli/            # CLI commands
    β”œβ”€β”€ mcp/            # MCP tools
    └── dto/            # Data transfer objects

Example: Task Execution Domain

// domain/models/task.ts
export class Task {
  constructor(
    readonly id: TaskId,
    readonly type: TaskType,
    private status: TaskStatus
  ) {}

  assign(agentId: AgentId): void {
    if (this.status !== TaskStatus.Created) {
      throw new InvalidStateError('Task already assigned');
    }
    this.status = TaskStatus.Assigned;
    this.emit(new TaskAssigned(this.id, agentId));
  }
}

// application/services/task-service.ts
export class TaskExecutionService {
  constructor(
    private taskRepo: ITaskRepository,
    private agentService: AgentLifecycleService,
    private eventBus: IEventBus
  ) {}

  async createTask(spec: TaskSpec): Promise<TaskId> {
    const task = Task.create(spec);
    await this.taskRepo.save(task);
    return task.id;
  }
}

// api/cli/task-commands.ts
export class CreateTaskCommand {
  constructor(private taskService: TaskExecutionService) {}

  async execute(args: CreateTaskArgs): Promise<void> {
    const taskId = await this.taskService.createTask(args);
    console.log(`Task created: ${taskId}`);
  }
}

Success Criteria

  • Clear domain boundaries documented
  • All features contained within single domain
  • No circular dependencies between domains
  • Domain models independent of infrastructure
  • New features can be added in <3 files

References

  • Domain-Driven Design by Eric Evans
  • Implementing Domain-Driven Design by Vaughn Vernon
  • Current architecture assessment: docs/architecture/v3-assessment.md

Implementation Date: 2026-01-04 Status: βœ… Complete