Specx component architecture

From maksimzayats/specx · View interactive version

Specx component architecture is an AI agent skill from the GitHub repository maksimzayats/specx. Design or review specx core scope boundaries in Python services. Use when deciding where code belongs across packaged scoped foundation bases, optional local foundation extensions, `core/`, capabilities, delivery, infrastructure, `shared/`, and `ioc`; when adding guardrails or splitting use cases, s

How to use this skill

Skill file

specx Scope Architecture

Use this skill before broad structural changes or when a feature crosses more

than one layer. Read references/boundaries.md for the full rules.

Boundary Model

capabilities/, dtos/, entities, exceptions/, gateways/,

repositories/, services/, and use_cases/.

SQLAlchemy repositories, Redis stores, HTTP clients, file storage, and queues.

Inner core packages must not import it.

specx.core.foundation, specx.delivery.foundation, and

specx.infrastructure.foundation. Every non-foundation source class must

inherit an explicit packaged base directly or through a project-local base;

local bases explicitly inherit the packaged or framework base they extend.

only: real project-local base categories or stateful framework bases that

must not be shared globally, such as a SQLAlchemy declarative base.

dependencies, request parsing, response serialization, HTTP error translation,

app lifecycle managers, and delivery-only services.

factories, logging, telemetry, and external client factories.

once with a BaseConfigurator; do not inject logging.Logger.

Decision Rules

narrower than a service.

BaseEffectService; do not add or use a generic BaseService.

Class names stay prefixed, for example clock.py defines BaseClock.

capabilities such as OpenAI summaries, payments, email, queues, and external

APIs. Gateway ports inherit BaseGateway, declare external effects, and do

not return entities.

core/<scope>/infrastructure/<technology>/.

category exists or a stateful framework base must own project-local state,

such as SQLAlchemy MetaData.

implementations.

probe policy is reusable across delivery layers. Keep a simple

framework-specific liveness probe in delivery, and do not invent core probe

services and use cases solely to satisfy the layer diagram.

in delivery and technical checks behind gateway adapters.

core/<scope>/dtos/.

queries, DTOs, entities, and other core data classes unless the user asks for

another model type. Keep Pydantic at delivery schemas and settings edges.

str or Literal[...].

guidance aligned with these boundaries.

state-changing, queries are read-only, and even empty inputs are explicit.

or BaseQuery, not BaseDTO, and live beside the use case that consumes

them.

open the active UoW inside execute(...). They do not inject repositories,

SQLAlchemy sessions/engines/session factories, or concrete infrastructure

adapters directly.

open UoW scopes or own commit/rollback.

a concrete Example:; the packaged rule checks abstract ports, local bases,

enums, and errors as well as concrete behavior classes.

lifecycle releases app-owned resources and closes the DI container on

shutdown.

__post_init__ using the full module plus class name. Do not add logger

fields to DTOs, entities, commands, queries, or classes with no log records.

secrets, credentials, request bodies, full external URLs, or infrastructure

topology.

omitted. New generated projects use select = ["ALL"], which enables every

rule whose required project surface exists. Projects with a narrower base

selection enable technology families explicitly, for example

extend-select = ["fastapi"]. Do not copy FastAPI paths or guidance into a

project that uses another delivery technology.

Code Style

Use blank lines as logical separators in all code. Keep related statements

together, but separate independent setup, action, assertion, response, branch,

and transformation groups so long blocks stay readable.

References

test targets.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.