The forze core package provides the foundation for building backend services with clean architecture. It contains everything you need to define domain models, declare contracts, compose usecases, and wire dependencies — without depending on any specific database, queue, or web framework.
Package structure
| Layer | Module | What it provides |
|---|---|---|
| Base | forze.base |
Error hierarchy, codecs, primitives (UUID, datetime, types), serialization, file I/O, introspection |
| Domain | forze.domain |
Document, CoreModel, BaseDTO, mixins,update validators, field constants |
| Application | forze.application |
Contracts (ports, specs), execution engine, middlewares, usecase plans, composition, mapping, DTOs |
Dependencies flow inward: Application → Domain → Base. No layer imports from an outer one.
Section guide
Foundations
Start here to understand the building blocks:
- Base Layer — error types, codecs, UUID generation, serialization helpers, and other shared utilities
- Domain Models —
Document, commands, read models, mixins, and update validation
Application machinery
These pages cover the orchestration layer:
- Contracts — protocol ports, specs, and dependency keys for all infrastructure concerns
- Execution —
ExecutionContext, dependency injection, runtime lifecycle - Middleware & Plans — guards, effects, transaction wrapping, usecase plans, and the registry
- Composition & Mapping — facades, providers, DTO mapping pipelines, and paginated responses
Reference
- Query Syntax — filter and sort DSL used across all adapters
Quick example
A minimal aggregate definition using the core package:
from forze.domain.models import (
Document,
CreateDocumentCmd,
ReadDocument,
BaseDTO,
)
from forze.domain.mixins import SoftDeletionMixin
from forze.application.contracts.document import DocumentSpec
# Domain model
class Task(SoftDeletionMixin, Document):
title: str
done: bool = False
# Commands and read model
class CreateTaskCmd(CreateDocumentCmd):
title: str
class UpdateTaskCmd(BaseDTO):
title: str | None = None
done: bool | None = None
class TaskRead(ReadDocument):
title: str
done: bool
is_deleted: bool = False
# Specification
task_spec = DocumentSpec(
namespace="tasks",
read={"source": "public.tasks", "model": TaskRead},
write={
"source": "public.tasks",
"models": {
"domain": Task,
"create_cmd": CreateTaskCmd,
"update_cmd": UpdateTaskCmd,
},
},
cache={"enabled": True},
)
With this in place, adapters (Postgres, Mongo, etc.) know how to store and retrieve tasks, usecases can be composed with middleware, and the entire aggregate is testable without any infrastructure.
Related sections
- Core Concepts — architectural overview, layered architecture, and design rationale
- Getting Started — end-to-end walkthrough of building a service with Forze
- Integrations — adapter packages for Postgres, Redis, S3, MongoDB, and more