Skip to content

Contents

A complete listing of every page in the Protean documentation. Use your browser's search (Ctrl+F / Cmd+F) to find any topic.


Getting Started

  • Installation -- Set up Python and install Protean.
  • Hello, Protean! -- Define, save, and load your first aggregate in under 20 lines.
  • Quickstart -- Build a domain in 5 minutes with in-memory adapters.

Tutorial: Building Bookshelf

A guided, hands-on tutorial building a complete online bookstore.

Part I -- Building the Domain

Part II -- Making It Real

Part III -- Growing the System

Part IV -- Production Operations

Part V -- System Mastery


Guides

Comprehensive reference organized by topic. Each guide goes deep on a specific area.

  • Guide Overview -- How the guides are organized and where to start.
  • How Do I...? -- Task-oriented index: find the right guide by what you're trying to do.

Choose a Path

Set Up the Domain

Define Domain Elements

Fields

  • Fields Overview -- Field types, attributes, options, and functionalities.
  • Defining Fields -- Three styles for declaring fields: annotation, assignment, and raw Pydantic.
  • Simple Fields -- String, Text, Integer, Float, Boolean, and other primitives.
  • Container Fields -- Fields that hold and embed value objects.
  • Association Fields -- HasOne, HasMany, and Reference fields for relationships.
  • Common Arguments -- Shared field arguments like required, default, and description.
  • Identity -- Identity generation strategies, types, and configuration.

Add Rules and Behavior

  • Domain Behavior -- Enforcing business rules through validations, invariants, and methods.
  • Validations -- Field-level validation using types, options, and custom validators.
  • Invariants -- Business rules that must always hold true within an aggregate.
  • Mutating Aggregates -- Modify state through named methods reflecting actions and events.
  • Status Transitions -- Enforce lifecycle state machines with the Status field.
  • Raising Events -- Notify other parts of the system through domain events.
  • Message Tracing -- Track the full causal chain of commands and events with correlation and causation IDs, and traverse causation chains programmatically.
  • Correlation and Causation IDs -- Complete guide to correlation and causation ID propagation across HTTP headers, OTEL spans, Observatory traces, structured logging, and cross-service boundaries.
  • Domain Services -- Complex domain logic that spans multiple aggregates.
  • Error Handling -- Raise, propagate, and handle domain exceptions.

Change State

  • Changing State -- Mechanisms for state changes: services, commands, and handlers.
  • Application Services -- Bridge between the API layer and the domain model.
  • Commands -- Data transfer objects expressing intention to change state.
  • Command Handlers -- Process commands and execute domain logic.
  • Repositories -- Define custom repositories, the DAO layer, and database-specific persistence.
  • Persist Aggregates -- Save aggregates using a repository's add method.
  • Retrieve Aggregates -- QuerySets, filtering, Q objects, bulk operations, and result navigation.
  • Temporal Queries -- Reconstitute event-sourced aggregates at a specific version or point in time.
  • Unit of Work -- Automatic transaction management for aggregate changes.
  • Custom Database Models -- Override auto-generated storage schemas with adapter-specific tuning.
  • Event Store Setup -- Choose, configure, and operate an event store.
  • Snapshots -- Optimize event-sourced aggregate loading with periodic checkpoints.

React to Changes

  • Consuming State Changes -- React to state changes through handlers, projections, and subscribers.
  • Event Handlers -- Consume events to sync state or trigger side effects.
  • Process Managers -- Coordinate multi-step processes across aggregates with stateful, event-sourced coordination.
  • Projections -- Create read-optimized views built from events.
  • Projectors -- Define event handlers that maintain projections.
  • Query Handlers -- Process queries and return results from projections.
  • Subscribers -- Consume messages from external brokers.
  • CloudEvents Interoperability -- Serialize events to CloudEvents v1.0 for external systems, and consume CloudEvents from external sources.
  • Stream Categories -- How messages are organized and routed.
  • Event Upcasting -- Transforming old event schemas to match the current version during replay.

Run in Production

  • Configuration -- Configure Protean through domain.toml and environment variables.
  • FastAPI Integration -- Domain context middleware, exception handlers, and best practices for using Protean with FastAPI.

Server

CLI

  • CLI Overview -- The protean command-line interface for scaffolding and management.
  • Domain Discovery -- Use --domain to load and initialize domains.
  • protean new -- Initialize new projects.
  • protean shell -- Interactive shell with the domain pre-loaded.
  • protean server -- Run the async background message processing server.
  • protean docs -- Live preview server for documentation.
  • protean test -- Run Protean's framework test suite (development only).
  • protean ir show -- Display the domain's IR as JSON or a human-readable summary.
  • protean schema -- Generate and inspect JSON Schema files for data-carrying domain elements.
  • protean snapshot -- Create snapshots for event-sourced aggregates.
  • protean projection -- Rebuild projections by replaying events from the event store.
  • protean events -- Inspect the event store: read streams, view stats, search events, trace aggregate history, and follow causal chains as a tree or flat table.
  • Type Checking -- Static type checking with the Protean mypy plugin.

Test Your Application


Python API Reference

Auto-generated documentation from source code docstrings.


Core Concepts

Architectural theory and the building blocks of domain-driven systems.

Foundations

  • Ubiquitous Language -- The shared vocabulary between domain experts and developers.
  • Bounded Contexts -- Boundaries within which a domain model is defined and applicable.
  • Analysis Model -- Bridging the gap between domain understanding and software implementation.
  • Identity -- The property that distinguishes one domain object from all others.
  • Invariants -- Business rules that must always hold true within a domain concept.
  • Changing State -- Principles governing how state transitions occur in DDD.
  • Streams -- The primary unit of organization in evented systems.

Architecture Patterns

Building Blocks

  • Domain Elements Overview -- Tactical patterns organized into four layers.
  • Aggregates -- Clusters of objects treated as a single unit for data changes.
  • Entities -- Mutable objects with distinct identity.
  • Value Objects -- Immutable elements distinguished by properties.
  • Domain Services -- Domain logic that doesn't fit within aggregates.
  • Events -- Immutable facts indicating state changes.
  • Commands -- Intentions to change system state.
  • Command Handlers -- Process commands and execute domain logic.
  • Event Handlers -- React to events with side effects and state synchronization.
  • Application Services -- Coordinate use cases at the boundary between external world and domain.
  • Repositories -- Collection-oriented persistence abstraction for aggregates.
  • Subscribers -- Consume messages from external brokers.
  • Projections -- Read-optimized denormalized views.
  • Projectors -- Specialized event handlers that maintain projections.
  • Query Handlers -- Process queries and return read-side results from projections.
  • Process Managers -- Stateful coordinators for multi-step processes across aggregates.

Adapters

Plug-in infrastructure that keeps your domain code free of technology dependencies.

Database

  • Database Providers -- Overview of supported database adapters, capabilities, and provider registry.
  • Memory -- Default in-memory provider for development and testing.
  • SQLite -- File-based relational provider using SQLAlchemy.
  • PostgreSQL -- SQLAlchemy-based adapter for PostgreSQL.
  • Elasticsearch -- Document store adapter for search and analytics.
  • Custom Database Adapters -- Build your own database adapter with entry-point registration.

Brokers

Caches

  • Cache Overview -- Cache port interface, available providers, and configuration.
  • Redis Cache -- Persistent distributed cache with TTL support.

Event Stores

  • Event Store Overview -- Event store port, core operations, temporal queries, and causation tracing.
  • MessageDB -- MessageDB event store adapter.

Patterns & Recipes

In-depth guides for recurring patterns in domain-driven applications. These span multiple domain elements and represent good practices that Protean supports but does not enforce.

Aggregate Design

Event-Driven Patterns

Architecture & Quality

Identity & Communication

Testing & Infrastructure

Operations


Internals

Design reasoning and internal architecture for contributors and advanced users.

  • Internals Overview -- What this section covers.
  • Field System -- How FieldSpec translates domain vocabulary to Pydantic, and why three definition styles are supported.
  • Shadow Fields -- How ValueObject and Reference fields are flattened into database columns via shadow fields.
  • Query System -- How the Repository → DAO → QuerySet → Provider chain works, Q object expression trees, lookup resolution, and lazy evaluation.
  • Event Sourcing -- How raise_() invokes @apply handlers, aggregate reconstitution, version tracking, causation chain traversal algorithms, and projection rebuilding.
  • Event Upcasting -- How old event payloads are transparently transformed to the current schema during deserialization.
  • IR Specification -- The portable JSON schema capturing domain model topology.

Migration

  • Compatibility Reference -- Breaking change rules, three-tier taxonomy, deprecation lifecycle, and config.toml reference.
  • Migrating to 0.15 -- Upgrade guide for the Pydantic v2 foundation release. Covers breaking changes, field style migration, and new features.

Reference

  • Glossary -- Definitions of key terms.
  • Philosophy & Design Principles -- The convictions that guide Protean's design.
  • The Always-Valid Domain -- How four validation layers guarantee domain objects are never invalid.
  • Why Protean? -- Four capabilities that set Protean apart: domain compiler, always-valid domain, progressive architecture, infrastructure portability.

Testing


Community

  • Community -- Get help and connect with other Protean users.
  • Development Setup -- Set up Protean locally for contributing.
  • Testing Protean -- Test strategy, fixtures, and running the suite.
  • Building Adapters -- Overview of creating custom adapters for databases, brokers, event stores, and caches with links to per-port guides.