python-primitives-architecture

Codify a primitives-first architecture for Python projects with dataclasses and Result-based error handling.

1|2|Updated Dec 4, 2025
One-click install
npx skills add https://github.com/co-labs-co/context-harness --skill python-primitives-architecture
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: python-primitives-architecture
Source: https://github.com/co-labs-co/context-harness/tree/main/.opencode/skill/python-primitives-architecture
Command: npx skills add https://github.com/co-labs-co/context-harness --skill python-primitives-architecture

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

ContextHarness's primitives-first architecture guide helps teams design Python applications with clear separation between domain primitives, services, and interfaces, improving testability, scalability, and maintainability.

Core Features & Use Cases

  • Primitives-first design: Pure dataclasses with immutable primitives and clearly defined entities.
  • Layered architecture guidance: Distinct PRIMITIVES, SERVICES, and INTERFACES with dependency injection via Protocols.
  • Use cases: Ideal when building CLI, SDK, or Web components that require strong type safety and clean boundaries between layers.

Quick Start

Start by creating a Python package following the documented layout, implement a pure primitive, a service that returns a Result, and a thin interface that exposes the service.

Frequently Asked Questions about python-primitives-architecture

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

FAQPage Schema
What is primitives-first architecture in Python and when do I need it?

Primitives-first architecture in Python separates pure domain dataclasses from services and interfaces to maximize testability. You need it when building CLI, SDK, or Web components that require strict layer boundaries and robust type safety.

How do I structure a Python project using layered architecture and dependency injection?

Structure your Python project by dividing it into distinct PRIMITIVES, SERVICES, and INTERFACES layers. Implement dependency injection using Protocols, allowing slim interfaces to call services that operate on pure dataclasses.

How do I handle errors in clean Python architecture without breaking layer separation?

Handle errors in clean Python architecture by using a Result-based pattern within your service layer. Services return Result objects instead of raising exceptions, keeping domain primitives pure and interface boundaries intact.

Does this primitives-first design approach work for both CLI and Web interfaces?

Yes, primitives-first design works for CLI, SDK, and Web interfaces. By enforcing pure dataclasses and protocol-based dependency injection, the underlying services remain decoupled from the delivery mechanism, ensuring high reusability.

How do I start implementing clean domain modeling with dataclasses and Protocols?

Start by creating a Python package with a documented layout, implement an immutable primitive using dataclasses, build a service that returns a Result, and finally expose it through a thin interface using Protocols for dependency injection.

When should I avoid using dataclasses for domain primitives?

You should avoid using pure dataclasses for domain primitives if your application does not require strict separation between domain logic and interface layers, as the overhead of Protocols and Result-based handling may complicate simple scripts.