Controller Builder

Construct Python controller classes with dataclass-based dependency injection and factory methods.

1|Updated Jul 10, 2025
One-click install
npx skills add https://github.com/jzallen/fred_simulations --skill controller-builder
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: Controller Builder
Source: https://github.com/jzallen/fred_simulations/tree/main/.claude/skills/controller-builder
Command: npx skills add https://github.com/jzallen/fred_simulations --skill controller-builder

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps you construct controller classes that act as clean public interfaces for your application's use cases, strictly adhering to clean architecture and dependency injection principles. It ensures your API layer is lean, testable, and free of business logic, promoting maintainability and scalability.

Core Features & Use Cases

  • Dependency Injection: Use dataclasses to define and inject use case functions into controllers.
  • Factory Method Pattern: Generate create_default_controller methods for easy instantiation with all required dependencies.
  • Clean Public Interfaces: Expose use cases through clear, business-oriented public methods, abstracting underlying logic.
  • Use Case: Create a Python UserController that exposes methods like register_user and get_user_profile, injecting register_user_use_case and get_user_use_case functions via a UserDependencies dataclass.

Quick Start

Generate a Python OrderController class with a create_default_controller factory method, injecting create_order_use_case and get_order_details_use_case functions.

Frequently Asked Questions about Controller Builder

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I structure Python API controllers with dependency injection?

Dependency injection in controllers uses dataclasses to define and inject use case functions. Define a dependencies dataclass containing your use case functions, pass it to the controller constructor, and expose public methods that delegate to those injected use cases. This keeps business logic separate from your API layer.

What's the best way to organize controllers in clean architecture?

Controllers should act as thin public interfaces that orchestrate use cases without containing business logic. Use a factory method like `create_default_controller` to instantiate controllers with all dependencies pre-configured, keeping your controller responsibilities focused on request routing and response formatting.

How do I implement the factory method pattern for Python controllers?

A `create_default_controller` factory method instantiates your controller with all required dependencies pre-injected. Use functools.partial to curry use case functions into the dependencies dataclass, then pass it to the controller. This pattern centralizes dependency configuration and simplifies testing.

Can I use dataclass-based dependency containers with partial currying in Python?

Yes. Dataclasses define your dependency container with typed fields for each use case. Use functools.partial to pre-configure use case functions with their dependencies, store the partial functions in dataclass fields, and pass the dataclass instance to your controller for clean, type-hinted dependency access.

Why should controllers avoid implementing business logic directly?

Keeping business logic in dedicated use case functions makes controllers testable, reusable across different interfaces, and easier to maintain. Controllers become thin orchestration layers that route requests to use cases and format responses, improving code organization and scalability.

Do I need runtime validation for dependencies in Python controllers?

Yes. Runtime validation ensures all dependencies are initialized before the controller executes, catching configuration errors early. Validate that required use case functions and repositories are present in your dependency container at controller instantiation or first method call.