Skip to content

Decentralized Contract Architecture for Action Handlers#262

Open
ruzaqiarkan-eng wants to merge 2 commits into
developfrom
decentralized-contract-architecture-11590012441252482169
Open

Decentralized Contract Architecture for Action Handlers#262
ruzaqiarkan-eng wants to merge 2 commits into
developfrom
decentralized-contract-architecture-11590012441252482169

Conversation

@ruzaqiarkan-eng

Copy link
Copy Markdown
Collaborator

This PR implements a robust, decentralized architecture for the FlexiRule contract system. Previously, all action metadata (CSS, required fields, operation overrides, policies) was managed in a single, monolithic 1440-line contracts.py file. This created a maintenance bottleneck and violated the Single Responsibility Principle.

In the new architecture:

  1. Each Action Handler is the Single Source of Truth: Handlers now define their own metadata via get_action_contract() and get_operation_contracts().
  2. Centralized Aggregation via Registry: The HandlerRegistry collects contracts from all registered handlers, providing a unified API for the engine, validation service, and frontend.
  3. Reusable Presets: Introduced factories in base_contract.py (like aggregate_operation_overrides) that eliminate hundreds of lines of duplicated JSON-like structures.
  4. Backward Compatibility: contracts.py remains as a facade, ensuring existing backend services and third-party handlers continue to work without modification.
  5. Schema Consistency: The contract DTO now ensures a uniform schema across all action types, facilitating easier frontend consumption.

Verified via golden-file comparison of get_contract_dto() output and the full backend test suite.


PR created automatically by Jules for task 11590012441252482169 started by @ruzaqiarkan-eng

Refactored the monolithic 1440-line `contracts.py` into a decentralized system where each `ActionHandler` owns its metadata contract (UI definitions, operations, policies).

Key changes:
- Created `base_contract.py` with `ActionContract` and `OperationContract` data classes and reusable presets.
- Created `contract_utils.py` for shared utility functions and constants.
- Created `contract_dto.py` for standardized frontend API generation.
- Enhanced `ActionHandler` base class with contract protocol methods.
- Enhanced `HandlerRegistry` to aggregate and cache decentralized contracts.
- Migrated all 13 built-in action handlers to implement the contract protocol.
- Transformed `contracts.py` into a thin backward-compatible facade using module-level `__getattr__`.

This improvement co-locates execution logic with metadata, adheres to the Single Responsibility and Open/Closed principles, and eliminates extensive duplication in operation contracts.
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

- Ran `ruff format` on all modified files to fix formatting issues.
- Fixed mypy error in `ActionHandler.get_action_contract` by ensuring `action_type` is a string.
- Cleaned up redundant imports and long lines in handlers for better readability and lint compliance.
Base automatically changed from refactor-contracts to develop July 4, 2026 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

1 participant