CtrlK
BlogDocsLog inGet started
Tessl Logo

pantheon-ai/software-design-principles

Apply software design principles across architecture and implementation using deterministic decision workflows, SOLID checks, structural patterns, and anti-pattern detection; use when reviewing designs, refactoring modules, or resolving maintainability and coupling risks.

Does it follow best practices?

Evaluation99%

1.01x

Agent success when using this tile

Validation for skill structure

Overview
Skills
Evals
Files

usecase-transaction-boundary.mdreferences/

title:
Use Case Defines the Transaction Boundary
impact:
HIGH
impactDescription:
ensures data consistency, prevents partial updates
tags:
usecase, transactions, consistency, boundaries

Use Case Defines the Transaction Boundary

The use case is the natural transaction boundary. All operations within a use case should succeed or fail atomically. Infrastructure manages the transaction; use case defines the scope.

Incorrect (transaction managed inside repository):

class OrderRepository:
    def save(self, order):
        with self.db.transaction():  # Transaction per operation
            self.db.insert('orders', order)

class InventoryRepository:
    def reserve(self, items):
        with self.db.transaction():  # Separate transaction
            for item in items:
                self.db.update('inventory', item.sku, decrement=item.qty)

class PlaceOrderUseCase:
    def execute(self, command):
        order = Order.create(command.items)
        self.orders.save(order)  # Commits
        self.inventory.reserve(command.items)  # If this fails, order is orphaned!
        self.payments.charge(order.total)  # If this fails, inventory is reserved but unpaid

Correct (use case defines transaction boundary):

# application/ports/UnitOfWork.py
class UnitOfWork(Protocol):
    def begin(self) -> None: ...
    def commit(self) -> None: ...
    def rollback(self) -> None: ...

# application/usecases/PlaceOrderUseCase.py
class PlaceOrderUseCase:
    def __init__(self, uow: UnitOfWork, orders, inventory, payments):
        self.uow = uow
        self.orders = orders
        self.inventory = inventory
        self.payments = payments

    def execute(self, command):
        self.uow.begin()
        try:
            order = Order.create(command.items)

            self.inventory.reserve(command.items)
            self.payments.charge(order.total)
            self.orders.save(order)

            self.uow.commit()  # All or nothing
            return order.id

        except Exception as e:
            self.uow.rollback()  # Clean rollback
            raise

# Alternative using context manager
class PlaceOrderUseCase:
    def execute(self, command):
        with self.uow:  # Transaction spans entire use case
            order = Order.create(command.items)
            self.inventory.reserve(command.items)
            self.payments.charge(order.total)
            self.orders.save(order)
            return order.id

Note: For distributed systems, consider saga patterns or eventual consistency rather than distributed transactions.

Reference: Unit of Work Pattern

Install with Tessl CLI

npx tessl i pantheon-ai/software-design-principles

SKILL-FULL.md

SKILL.md

tile.json