Skip to content

Commit

Permalink
Tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
seanchatmangpt committed Feb 19, 2024
1 parent 0997275 commit d712294
Show file tree
Hide file tree
Showing 137 changed files with 3,947 additions and 3,456 deletions.
86 changes: 80 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,15 @@ class YourActor(Actor):
### Creating Actors in the ActorSystem

```python
from rdddy.actor_system import ActorSystem

actor_system = ActorSystem()
your_actor = await actor_system.actor_of(YourActor)
```

### Sending and Publishing Messages
### Publishing Messages

```python
# Direct message to a specific actor
await actor_system.send(your_actor.actor_id, YourMessageType(...))

# Broadcast message to all actors
await actor_system.publish(YourMessageType(...))
```
Expand All @@ -66,13 +65,88 @@ await actor_system.publish(YourMessageType(...))
The framework supports robust error handling and the maintenance of system invariants. Actors can catch exceptions during message processing and the `ActorSystem` can broadcast error events, ensuring the system remains responsive and resilient:

```python
class FaultyActor(Actor):
async def receive(self, message: Message):
class FaultyActor(AbstractActor):
async def receive(self, your_command: YourCommand):
# Implementation that might raise an exception
```

The `ActorSystem` detects exceptions, broadcasting an `Event` with error details, which can be tested and verified through the framework's testing capabilities.

## Abstract Classes

The Reactive Domain-Driven Design (RDDDY) framework offers a comprehensive suite of abstract classes, each serving as a template to guide the development of reactive, domain-driven systems. These classes lay the groundwork for creating domain-specific entities, value objects, and services that operate within an asynchronous, message-driven architecture. Below, we detail the role and purpose of each abstract class within the framework, elucidating how they contribute to building scalable, maintainable, and business-aligned software solutions.

### AbstractActor

`AbstractActor` is the fundamental building block of the RDDDY framework, representing the core unit of computation. It defines a standard interface for actors, encapsulating state management, message handling, and interaction protocols. Developers extend `AbstractActor` to implement domain-specific logic, leveraging asynchronous message passing to foster loose coupling and enhance system resilience.

### AbstractSaga

`AbstractSaga` encapsulates the logic for managing long-running, complex business transactions that span multiple services or bounded contexts. It provides mechanisms for orchestrating sequences of domain events and commands, ensuring transactional consistency and compensating actions in case of failures. By extending `AbstractSaga`, developers can implement coordinated workflows that are robust and aligned with business processes.

### AbstractView

`AbstractView` serves as the foundation for user interface components in a reactive system. It outlines methods for rendering data to the user and reacting to user inputs, enabling the development of dynamic and responsive user interfaces. Subclasses of `AbstractView` are tailored to specific UI requirements, responding to changes in the application's state with real-time updates.

### DomainException

While not prefixed with "Abstract," `DomainException` acts as a base class for defining domain-specific exceptions. These exceptions are used to signal error conditions in a way that is meaningful within the domain context, providing clear and actionable feedback to the system or the end-user. Custom exceptions derived from `DomainException` enhance error handling by incorporating domain-relevant information and context.

### AbstractValueObject

`AbstractValueObject` provides a template for creating value objects, which are immutable objects defined by their attributes rather than a unique identity. Value objects are crucial in domain-driven design for encapsulating and expressing domain concepts through their attributes. Extensions of `AbstractValueObject` ensure attribute-based equality and immutability, reinforcing domain integrity and consistency.

### AbstractTask

`AbstractTask` outlines the structure for tasks, which are discrete units of logic executed as part of the system's operations. Tasks encapsulate specific behaviors or processes, such as validation, computation, or state transitions, facilitating modularity and reuse. By defining tasks as subclasses of `AbstractTask`, the system can orchestrate complex operations while maintaining clarity and separation of concerns.

## Integration with Design for Lean Six Sigma (DFLSS)

Integrating the RDDDY framework with DFLSS principles underscores a commitment to process optimization, efficiency, and quality. The framework's emphasis on asynchronous communication, domain-driven design, and resilient architecture resonates with DFLSS goals of reducing variability, eliminating waste, and fostering continuous improvement. Through this synergy, developers can craft software systems that are not only technically sound but also streamlined and aligned with business excellence.


## Best Practices

Implementing the Reactive Domain-Driven Design (RDDDY) framework in enterprise environments requires careful consideration to fully leverage its benefits while ensuring scalability, maintainability, and alignment with business objectives. Below are best practices to guide enterprises in adopting the RDDDY framework effectively.

### Embrace Domain-Driven Design

1. **Ubiquitous Language**: Develop a common language based on the domain model that is shared among developers, domain experts, and stakeholders. This facilitates clear communication and ensures that software implementations are closely aligned with business concepts and requirements.
2. **Bounded Contexts**: Clearly define the boundaries of different domain contexts within the enterprise. This helps in isolating domain models and reducing complexity by ensuring that models within a context are internally consistent but decoupled from other contexts.

### Leverage Actors Strategically

1. **Actor Granularity**: Carefully consider the granularity of actors. Too fine-grained actors can lead to overhead in message passing, while too coarse-grained actors can decrease system responsiveness. Balance is key, with actors representing logically distinct units of functionality or state.
2. **Asynchronous Communication**: Maximize the use of asynchronous message passing for communication between actors. This enhances system responsiveness and scalability by avoiding blocking operations and enabling concurrent processing.

### Implement Sagas for Business Transactions

1. **Transaction Management**: Use sagas to manage complex, multi-step transactions across bounded contexts or microservices. Design sagas to handle success scenarios and compensate for failures, ensuring consistency and reliability in business operations.
2. **Saga Coordination**: Coordinate saga steps through events and commands, employing asynchronous messaging to orchestrate operations across distributed components without tight coupling.

### Focus on System Resilience

1. **Error Handling**: Implement robust error handling within actors and sagas. Define clear strategies for dealing with exceptions, including logging, compensation actions, and retries, to maintain system stability and integrity.
2. **Supervision Strategies**: Utilize actor supervision strategies to automatically manage actor lifecycle events, including restarts and escalations. This ensures that the system can recover gracefully from failures.

### Optimize for Performance and Scalability

1. **State Management**: Minimize the state held within actors to reduce memory footprint and enhance performance. Consider stateless actors where possible, and employ caching strategies judiciously for frequently accessed data.
2. **Distribute Workloads**: Design the system to distribute workloads evenly across actors and nodes in a cluster. Utilize routers and dispatchers to manage actor deployment and message routing, ensuring balanced utilization of resources.

### Foster Collaboration and Continuous Improvement

1. **Cross-functional Teams**: Encourage close collaboration between development teams, domain experts, and business stakeholders. This cross-functional approach ensures that the software development process is informed by deep domain knowledge and aligned with business goals.
2. **Iterative Development**: Adopt an iterative, incremental development process. Regularly review and refine the domain model, actor implementations, and system architecture to respond to changing requirements and leverage insights gained from ongoing operations.

### Invest in Monitoring and Observability

1. **System Monitoring**: Implement comprehensive monitoring for the actor system, tracking key metrics such as message throughput, processing times, and error rates. This enables proactive management of system performance and health.
2. **Observability**: Enhance system observability by incorporating detailed logging, tracing, and event recording. This aids in debugging, performance tuning, and understanding system behavior under various conditions.

By following these best practices, enterprises can successfully implement the RDDDY framework to build reactive, domain-driven systems that are scalable, resilient, and closely aligned with business needs. This strategic approach facilitates the development of software solutions that deliver tangible business value, fostering agility, efficiency, and competitive advantage.


## Conclusion

The RDDDY framework offers a powerful paradigm for building scalable, resilient, and domain-driven systems in Python. By leveraging the Actor model and embracing asynchronous communication, developers can tackle the complexities of modern software development, ensuring their applications are both robust and closely aligned with business objectives.
Expand Down
42 changes: 42 additions & 0 deletions assertion.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
2024-02-18 15:52:14,533 - dspy.primitives.assertions - ERROR - AssertionError: You need to create a kwargs dict for APIEndpoint

Validation error:
None
2024-02-18 15:52:14,533 - dspy.primitives.assertions - ERROR - AssertionError: You need to create a kwargs dict for APIEndpoint

Validation error:
None
2024-02-18 15:52:14,541 - dspy.primitives.assertions - ERROR - AssertionError: You need to create a valid python list primitive type for
list_str_for_ast_literal_eval
You will be penalized for not returning only a list for list_str_for_ast_literal_eval
2024-02-18 15:52:14,542 - dspy.primitives.assertions - ERROR - AssertionError: You need to create a valid python list primitive type for
list_str_for_ast_literal_eval
You will be penalized for not returning only a list for list_str_for_ast_literal_eval
2024-02-18 16:01:06,450 - dspy.primitives.assertions - ERROR - AssertionError: You need to create a kwargs dict for APIEndpoint

Validation error:
None
2024-02-18 16:01:06,452 - dspy.primitives.assertions - ERROR - AssertionError: You need to create a kwargs dict for APIEndpoint

Validation error:
None
2024-02-18 16:01:06,459 - dspy.primitives.assertions - ERROR - AssertionError: You need to create a valid python list primitive type for
list_str_for_ast_literal_eval
You will be penalized for not returning only a list for list_str_for_ast_literal_eval
2024-02-18 16:01:06,460 - dspy.primitives.assertions - ERROR - AssertionError: You need to create a valid python list primitive type for
list_str_for_ast_literal_eval
You will be penalized for not returning only a list for list_str_for_ast_literal_eval
2024-02-18 16:27:03,069 - dspy.primitives.assertions - ERROR - AssertionError: You need to create a kwargs dict for APIEndpoint

Validation error:
None
2024-02-18 16:27:03,070 - dspy.primitives.assertions - ERROR - AssertionError: You need to create a kwargs dict for APIEndpoint

Validation error:
None
2024-02-18 16:27:03,077 - dspy.primitives.assertions - ERROR - AssertionError: You need to create a valid python list primitive type for
list_str_for_ast_literal_eval
You will be penalized for not returning only a list for list_str_for_ast_literal_eval
2024-02-18 16:27:03,077 - dspy.primitives.assertions - ERROR - AssertionError: You need to create a valid python list primitive type for
list_str_for_ast_literal_eval
You will be penalized for not returning only a list for list_str_for_ast_literal_eval
148 changes: 148 additions & 0 deletions chain.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
TypedBuildCoreComponentsPrompt:
classes:
- TypedPrompt
- Chat
description: Develop core components of the DSL.
error_handling: Exception Handling
methods:
- execute
- validate
parsers:
- YAML Parser
- JSON Parser
performance_metrics:
- Speed
- Memory
source: Develop parsers {{ parsers }} for the YAML configurations. Implement classes
{{ classes }} and methods {{ methods }} for functionalities. Include {{ error_handling
}} and consider {{ performance_metrics }}.
title: Build Core Components
TypedDeploymentPrompt:
backup_plan: Daily Backups
ci_cd_pipelines:
- Jenkins
- GitLab
deployment_strategy: Blue-Green
description: Deploy the system.
monitoring_tools:
- Prometheus
- Grafana
rollback_procedures:
- Automated
- Manual
source: Choose an appropriate deployment strategy {{ deployment_strategy }}. Implement
CI/CD pipelines {{ ci_cd_pipelines }}, use monitoring tools {{ monitoring_tools
}}, have a backup plan {{ backup_plan }}, and prepare rollback procedures {{ rollback_procedures
}}.
title: Deployment
TypedDesignArchitecturePrompt:
components:
- Parser
- Executor
description: Design the DSL architecture.
interactions:
- Data Flow
- Control Flow
modularity: Modular
scalability: High
source: Plan how the DSL will interact with other system components {{ components
}}. Define the DSL's syntax {{ syntax }}, ensure {{ scalability }} and {{ modularity
}}, and outline component interactions {{ interactions }}.
syntax: YAML-based
title: Design Architecture
TypedDocumentationPrompt:
api_docs:
- Endpoints
- Examples
description: Create detailed documentation.
documentation_types:
- API
- User Guide
faqs:
- General
- Technical
source: Create detailed documentation types {{ documentation_types }} and offer
training sessions or materials to end-users including user guides {{ user_guides
}}, API documentation {{ api_docs }}, tutorials {{ tutorials }}, and FAQs {{ faqs
}}.
title: Documentation
tutorials:
- Video
- Text
user_guides:
- Getting Started
- Advanced
TypedImplementBusinessLogicPrompt:
algorithms:
- NLP
- ML
data_models:
- User
- Environment
description: Implement the business logic.
goal_setting: S.M.A.R.T
optimization_criteria:
- Efficiency
- Accuracy
source: Add logic for team composition {{ team_composition }}, goal setting {{ goal_setting
}}, use data models {{ data_models }}, apply algorithms {{ algorithms }}, and
meet optimization criteria {{ optimization_criteria }}.
team_composition: Cross-functional
title: Implement Business Logic
TypedMaintenancePrompt:
description: Maintain and update the system.
monitoring_metrics:
- CPU Usage
- Error Rate
patching_policy: Security First
source: Monitor system's usage and performance using metrics {{ monitoring_metrics
}}. Apply patches and updates as required following the update schedule {{ update_schedule
}} and patching policy {{ patching_policy }}. Provide support through channels
{{ support_channels }} and collect feedback via {{ user_feedback_mechanisms }}.
support_channels:
- Email
- Chat
title: Maintenance
update_schedule: Monthly
user_feedback_mechanisms:
- Survey
- Reviews
TypedRequirementAnalysisPrompt:
constraints:
- Time
- Budget
core_functionalities:
- Parsing
- Error Handling
description: Gather detailed requirements for the DSL.
source: Gather detailed requirements that the DSL needs to fulfill. Identify core
functionalities, consult with {{ stakeholders }}, consider {{ constraints }},
choose appropriate {{ technologies }}, within the timeframe of {{ timeframe }}.
stakeholders:
- Product Manager
- Dev Team
- QA Team
technologies:
- Python
- YAML
timeframe: Q1
title: Requirement Analysis
TypedTestingPrompt:
description: Conduct thorough testing.
integration_tests:
- test_end_to_end
source: Write unit tests {{ unit_tests }}, validate through integration tests {{
integration_tests }}, perform stress tests {{ stress_tests }}, use test data {{
test_data }} in various test environments {{ test_environments }}.
stress_tests:
- test_load
test_data:
- Sample YAML
- Sample JSON
test_environments:
- Local
- Staging
title: Testing
unit_tests:
- test_parser
- test_executor
File renamed without changes.
Loading

0 comments on commit d712294

Please sign in to comment.