Rule-based architecture guardrails for Specx Python services.
Project description
Specx
Codex skills for building Python services with explicit architectural boundaries.
Specx is a skill catalog for generating and evolving backend services that keep application code readable under agent-driven development. It gives Codex a shared vocabulary for packaged foundation bases, scoped core packages, delivery adapters, unit-of-work lifecycles, dependency injection, migrations, and architecture tests.
Install · Skills · Generated Architecture · Contribute
Key Features
- Skill-based service scaffolding. Specx replaces a one-off code template with composable skills for project structure, foundation usage, tooling, DI, use cases, services, delivery controllers, infrastructure adapters, settings, migrations, and tests.
- Explicit class boundaries. Generated services use class-based use cases,
services, controllers, repositories, gateways, capabilities, DTOs, entities,
units of work, and factories with packaged
specx.foundationbases. - Clear transaction ownership. Use cases open
UnitOfWorkManagerscopes. Read/effect services may use an active UoW passed by the use case, but they do not own transaction lifecycle. - Guardrails for agent work. The
specxPython package ships rule-based architecture tests that reject layer leaks, entity returns from use cases, schema bootstrap calls, bare classes, wrong suffixes, and hidden transaction ownership. - Reusable runtime bases. Generated services import small base classes from
specx.foundationinstead of vendoring a foundation tree. Projects add localfoundation/modules only when a real missing category needs one. - Alembic-first persistence. SQLAlchemy projects use real Alembic
migrations and drift checks instead of
metadata.create_all()bootstraps.
Install
Install every Specx skill for Codex:
npx skills add maksimzayats/specx --skill '*' --agent codex -y
List skills from a local checkout:
npx skills add . --list --full-depth
Validate the catalog:
make check
Use the architecture package from generated projects:
from pathlib import Path
from specx.testing.architecture import SpecxArchitectureConfig, assert_specx_architecture
def test_specx_architecture() -> None:
assert_specx_architecture(
SpecxArchitectureConfig(
project_root=Path(__file__).resolve().parents[3],
package_name="order_service",
)
)
What You Get
- A reusable Codex skill catalog under
skills/. - A typed Python guardrail package under
src/specx/. - A generated reference service under
samples/task-db-service/. - Rule-based architecture guardrails exposed through
specx.testing.architecture. - A compatibility renderer that writes the tiny generated-project pytest wrapper with the correct package name.
- Root
AGENTS.mdguidance for agents working on this catalog. - Generated-project
AGENTS.mdguidance that projects should carry with them.
Skills
specx-project-structurecreates the initialcore,delivery,infrastructure,ioc, optional localfoundation, optionalshared, migrations, tests, and generated-project agent instructions.specx-foundationteaches packaged base usage and project-local extensions for real missing base categories.specx-project-toolingaddsuv, Ruff, mypy, pytest, Makefile targets, and local validation commands.specx-component-architecturedecides where code belongs across scopes, boundaries, capabilities, gateways, DTOs, schemas, adapters, and shared code.specx-diwire-compositionwiresdiwire.Container,Injected[...], private registrations, app factories, and test overrides.specx-add-core-use-caseadds command/query-driven use cases that return DTOs and own UoW scopes when persistence is needed.specx-add-core-serviceadds focused reusable core behavior without hiding transaction lifecycle.specx-add-infrastructure-adapteradds repositories, gateways, UoW implementations, SQLAlchemy, Redis, HTTP, SDK, and other technical adapters.specx-sqlalchemy-migrationsadds async Alembic configuration, revisions, migration commands, and drift tests.specx-add-delivery-controlleradds top-level FastAPI controllers, schemas, route registration, and delivery-only helpers.specx-settingsaddspydantic-settingsconfiguration without direct environment reads in core code.specx-testsadds unit, integration, end-to-end, DI, migration, and architecture tests backed by thespecxpackage.
Generated Architecture
Specx projects import foundation bases from specx.foundation and organize
application code around scoped core packages:
src/<package>/
core/
<scope>/
capabilities/
dtos/
entities/
exceptions/
gateways/
repositories/
services/
use_cases/
infrastructure/
delivery/
fastapi/
__main__.py
factory.py
controllers/
schemas/
services/
infrastructure/
ioc/
shared/
migrations/
core/<scope>/delivery/ is intentionally not part of the structure. Delivery
lives at the top level, while core packages stay framework-free.
Create src/<package>/foundation/ only when a real class category is missing
from specx.foundation. Local foundation module filenames are not
base_-prefixed, but class names stay prefixed, for example clock.py defines
BaseClock.
Core Rules
- Every project class inherits an explicit packaged or project-local foundation base.
- Use cases accept exactly one same-file
CommandorQueryand return DTOs, not entities. - Commands represent state-changing operations. Queries are read-only, even when the input is empty.
- Commands, queries, DTOs, entities, and other core data classes should use
@dataclass(frozen=True, kw_only=True, slots=True)unless the user asks for another model type. Keep Pydantic for delivery schemas and settings. - Core services inherit
BasePureService,BaseReadService, orBaseEffectService; do not add a genericBaseService. - Small injectable collaborators inherit
BaseCapability, live undercore/<scope>/capabilities/, and do not pretend to be services, repositories, gateways, helpers, or managers. - Gateway ports inherit
BaseGateway, live undercore/<scope>/gateways/, declare external effects, use business language, and do not return entities. - Persistence use cases inject a
UnitOfWorkManagerand open an activeUnitOfWorkinsideexecute(...). - Services may receive an active UoW as a method argument, but they do not open UoW scopes, commit, or roll back.
- SQLAlchemy schema is managed by Alembic migrations, not application schema bootstrap calls.
diwire.Containerbelongs inioc, top-level delivery factory/entrypoint code, and tests only.
Reference Service
The sample service under samples/task-db-service/ is a working generated
project used to validate the skills. It includes:
- FastAPI delivery with
task_db_service.delivery.fastapi.__main__:app. - Task use cases with command/query inputs and DTO outputs.
- Split pure/read/effect services.
- SQLAlchemy repositories and UoW manager.
- Alembic migrations and drift checks.
- Architecture tests that call the rule-based
specxguardrail package.
Run it from the sample directory:
cd samples/task-db-service
make check
Contributing
Developer setup, architecture notes, sample regeneration expectations, and validation workflow live in CONTRIBUTING.md.
License
Specx is released under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file specx-0.0.0a1.tar.gz.
File metadata
- Download URL: specx-0.0.0a1.tar.gz
- Upload date:
- Size: 30.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f24b64f1fc4b213f3999d812b245e712abf45bb3050ad46a84d9239931d1681f
|
|
| MD5 |
6ba480165a80278616f3830368869571
|
|
| BLAKE2b-256 |
abd8fa3f405179a01c8cabf5593a6244f65ae99091bf8132222b41db77ab4103
|
File details
Details for the file specx-0.0.0a1-py3-none-any.whl.
File metadata
- Download URL: specx-0.0.0a1-py3-none-any.whl
- Upload date:
- Size: 42.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9512b9cabc0ad81eec1ec8d00f511ad4959dd5a214eb6f9fbab57971579412b3
|
|
| MD5 |
d98f2d552a5da864b91d8500df008bb3
|
|
| BLAKE2b-256 |
286719ce90c9a1d2bae876bc6fc5eb029becedda06bb9b4bedffbef6d080eaa9
|