Service Architecture Plan - May 20, 2025
CORE ARCHITECTURE DESIGN WITH FEATURE-FIRST APPROACH
This document outlines the service-oriented architecture design for Atlas v2, implementing principles from the Clean Break Architecture Manifesto and integrating the NERV (Neural Event-Reactive Virtualization) architecture with Inner Universe persistence. It focuses on architectural clarity, service separation, protocol-first design, and reactive event-driven patterns while prioritizing feature-driven vertical slices.
Current Status (May 20, 2025)
- Current Approach: Vertical feature slices with focused architectural components
- Current Progress: NERV primitives and component patterns established
- Current Focus: Implementing core NERV components for Streaming Chat feature
- Target Completion: Iterative delivery of features with accompanying architecture components
1. Feature-Driven Architecture Overview
1.1 Core Design Principles
The service architecture maintains these core NERV principles while adopting a vertical slice approach:
- Emergence Over Prescription: Architecture emerges from interaction patterns
- Protocol-First Design: All interfaces are defined first as protocols with clear contracts
- Type-Safe Foundations: Strong typing throughout with centralized type variable system
- Reactive Event Mesh: Components communicate through reactive event subscription
- Temporal State Awareness: State history is maintained through versioned containers
- Perspective Shifting: Different views of the same data for different contexts
- Explicit Effect Tracking: Side effects are explicitly captured and managed
- Adaptive Component Composition: Services discover what they need rather than explicit wiring
1.2 Vertical Architecture Slices
Rather than building complete horizontal layers, we will implement vertical slices that deliver complete functional features:
┌─────────────────────────────────────────────────────────────┐
│ Public API Layer │
└───────────────────────────────┬─────────────────────────────┘
│
┌───────────────────────────────▼─────────────────────────────┐
│ Component Layer │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Providers │ │ Agents │ │ Knowledge │ │
│ └────┬────────┘ └────┬────────┘ └────┬────────┘ │
└───────┼─▲───────────────┼─▲───────────────┼─▲───────────────┘
│ │ │ │ │ │
┌───────▼─┴───────────────▼─┴───────────────▼─┴───────────────┐
│ Service Layer │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ State │ │ Command │ │ Event │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Buffer │ │ Resource │ │ Registry │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
└───────────┬─▲───────────────┬─▲───────────────┬─▲───────────┘
│ │ │ │ │ │
┌───────────▼─┴───────────────▼─┴───────────────▼─┴───────────┐
│ NERV Components & Primitives │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ EventBus │ │TemporalStore│ │ EffectMonad │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ StateProj. │ | AspectWeaver│ │ Container │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
└───────────┬─▲───────────────────────────────────────────────┘
│ │
┌───────────▼─┴───────────────────────────────────────────────┐
│ Inner Universe Layer │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Controller │ │ SpacetimeDB │ │ Adapters │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
└─────────────────────────────────────────────────────────────┘
For each feature slice, we will:
- Implement only the necessary components from each layer
- Build complete end-to-end functionality that users can test
- Follow the clean break architecture principles within the feature scope
- Enable incremental adoption and testing of the architecture
1.3 Key Architectural Components
Core NERV Components
- EventBus: Reactive Event Mesh implementation for decoupled communication
- TemporalStore: Historical state tracking with version history
- PerspectiveAware: Context-specific views of data
- StateProjector: Efficient state evolution with immutability
- EffectMonad: Explicit side-effect tracking
- AspectWeaver: Cross-cutting concerns management
- Container: Dependency management system
- QuantumPartitioner: Parallel execution with dependencies
- DiffSynchronizer: Data reconciliation between systems
Inner Universe Integration
- Controller: Central coordination for SpacetimeDB interaction
- Adapters: Connect NERV components to SpacetimeDB
- Type Mapping: Consistent mapping between Python and Rust types
Core Services
- Service Registry: Central registry for service discovery
- Event System: Event subscription and publication
- Buffer System: Thread-safe data flow management
- State Container: Versioned state management
- Command System: Command pattern implementation
- Resource Manager: Resource lifecycle management
2. Feature-Slice Implementation Approach
2.1 Streaming Chat Feature
The Streaming Chat feature slice will implement:
- EventBus Component: For real-time event communication
- Buffer Service: For streaming token management
- State Container: For response tracking
- Provider Services: For LLM integration
This feature demonstrates:
- Event-driven architecture
- Real-time data flow
- Thread safety
- Provider integration
2.2 Agent Delegation Feature
The Agent Delegation feature slice will implement:
- TemporalStore Component: For agent state tracking
- Event System: For agent communication
- Command System: For task execution
- State Management: For task tracking
This feature demonstrates:
- State transition management
- Complex event flows
- Command pattern usage
- Multi-agent coordination
2.3 Knowledge Retrieval Feature
The Knowledge Retrieval feature slice will implement:
- PerspectiveAware Component: For context-specific views
- Inner Universe Integration: For persistence
- Resource Management: For vector stores
- Buffer System: For chunking and embedding
This feature demonstrates:
- Persistence layer integration
- Resource lifecycle management
- Data transformation
- Information retrieval patterns
3. Component Implementation Strategy
3.1 EventBus and Event System
The EventBus serves as the communication backbone across components:
- Implementation Approach: Start with minimal functionality for Streaming Chat
- Key Capabilities: Event subscription, publication, filtering
- Integration Points: Provider streaming, user interface updates
- Extensions: Add middleware, history tracking for later features
3.2 Buffer System
The Buffer System manages streaming data flow:
- Implementation Approach: Implement for token streaming first
- Key Capabilities: Thread-safe operations, flow control
- Integration Points: Provider streaming, user interface
- Extensions: Add batching, priority for later features
3.3 State Container
The State Container provides versioned state management:
- Implementation Approach: Start with simple response tracking
- Key Capabilities: State updates, version tracking
- Integration Points: UI state representation, event triggers
- Extensions: Add full history, branching for later features
3.4 Resource Management
Resource Management handles external dependencies:
- Implementation Approach: Start with provider connections
- Key Capabilities: Lifecycle management, cleanup
- Integration Points: Vector stores, external services
- Extensions: Add monitoring, pooling for later features
4. Implementation Roadmap and Dependencies
4.1 Streaming Chat Dependencies
For the Streaming Chat feature:
NERV Components:
- EventBus - Essential
- Buffer System - Essential
- StateProjector - Essential
- Container - Optional
Service Implementations:
- Event System - Essential
- Buffer Service - Essential
- State Service - Essential
- Provider Service - Essential
4.2 Agent Delegation Dependencies
For the Agent Delegation feature:
NERV Components:
- EventBus - Essential (reuse from Streaming Chat)
- TemporalStore - Essential
- Container - Essential
- EffectMonad - Optional
Service Implementations:
- Event System - Essential (reuse from Streaming Chat)
- Command Service - Essential
- State Service - Essential (extend from Streaming Chat)
- Registry Service - Essential
4.3 Knowledge Retrieval Dependencies
For the Knowledge Retrieval feature:
NERV Components:
- PerspectiveAware - Essential
- DiffSynchronizer - Essential
- Inner Universe Controller - Essential
Service Implementations:
- Resource Service - Essential
- Persistence Service - Essential
- Buffer Service - Essential (reuse from Streaming Chat)
- Registry Service - Essential (reuse from Agent Delegation)
5. Natural Integration Zones
The architecture recognizes natural integration zones where different patterns blend together organically:
5.1 State-Event Continuum
Where state management and event systems naturally blend:
- Events trigger state transitions in TemporalStore
- State transitions publish events through EventBus
- State history aligns with event history
- Versioned state and event sequences provide natural correlation
5.2 Execution-Dependency Fabric
Where command execution and service dependencies naturally interweave:
- Command execution depends on service availability
- Service discovery influences command capabilities
- Effect tracking captures service interactions
- Command lifecycles align with resource lifecycles
5.3 Perspective-Synchronization Mesh
Where data transformation and data synchronization naturally overlap:
- Data projections influence synchronization strategies
- Schema definitions serve validation and mapping purposes
- Context-specific views inform synchronization priorities
- Transformation and reconciliation form natural feedback loops
6. Conclusion
This service architecture approach focuses on delivering vertical feature slices while maintaining the architectural integrity of the NERV system. By implementing only the necessary components for each feature, we can deliver value incrementally while still building toward the complete clean break architecture.
Key advantages of this approach:
- Faster Value Delivery: Complete features delivered earlier
- Lower Implementation Risk: Architecture validated through actual usage
- Better Resource Allocation: Focus on components needed for current features
- Emergent Design: Architecture emerges naturally from interaction patterns
- Adaptive Evolution: Components evolve based on real-world usage
Next Steps
Focus on implementing the core components required for the Streaming Chat feature: EventBus, Buffer Service, and State Container. This will establish the foundation for immediate functional value while validating core architectural patterns.