Repository Builder

Generate Python Protocol repository interfaces with ORM-separated implementations and mapper-driven data transformation.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps developers implement the Repository Pattern, abstracting data access logic from business logic. It ensures a clean separation of concerns, making your application more testable, maintainable, and independent of specific database technologies, ultimately simplifying data persistence.

Core Features & Use Cases

  • Interface-First Design: Define clear data access contracts using Python Protocol interfaces.
  • Business Model Isolation: Ensure repositories work exclusively with business models, preventing database implementation details from leaking.
  • Mapper Integration: Seamlessly convert between business and ORM models using dedicated mappers for data transformation.
  • Use Case: Generate a Python IProductRepository interface and a SQLAlchemyProductRepository implementation, including create, get_by_id, and update methods, ensuring proper use of mappers and type hints.

Quick Start

Create a Python IUserRepository interface and a PostgreSQLUserRepository implementation for a User model, including methods to create and get_by_email, using a UserMapper.

Frequently Asked Questions about Repository Builder

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

FAQPage Schema
How do I separate domain logic from database persistence in Python?

The repository pattern abstracts data access logic from business logic using Protocol interfaces and mapper-driven transformations. Define a repository interface that works exclusively with business models, then implement it with concrete ORM adapters, keeping domain logic independent of persistence details.

What's the best way to implement clean repositories with SQLAlchemy?

Create a Protocol interface defining your data access contract, then build a SQLAlchemy implementation that maps between ORM and business models using dedicated mapper classes. This enforces type safety, testability, and separation of concerns across CRUD, bulk, and query operations.

How do I use mappers to convert between ORM and business models?

Mappers translate ORM entities to business models in repository methods, keeping persistence implementation hidden. Store mappers in a dedicated mappers/ directory and invoke them during create, read, and update operations to maintain clean domain boundaries.

Can I use the repository pattern with dependency injection and testing?

Yes. Protocol-based repository interfaces enable dependency injection and mock implementations for testing. Inject repositories into use cases and controllers, allowing you to swap real repositories with test doubles without coupling to ORM details.

Do repositories handle transactional support and error handling?

Repositories manage transactions and enforce proper error handling with ValueError and NotFoundError exceptions. Implement logging and validation within repository methods to ensure data consistency and provide clear feedback when operations fail.

Why use Protocol interfaces instead of abstract base classes for repositories?

Protocol interfaces enable structural typing without inheritance, allowing flexible implementations and easier testing with mock objects. They define clear contracts for data access without enforcing a specific class hierarchy.