Przejdź do treści
Biblioteka skilli
Programowanie · Planowanie

clean-architecture-python

/clean-architecture-python

Pomaga układać usługę w Pythonie z pyproject.toml (FastAPI lub inny framework) i dodawać funkcje, endpointy, przypadki użycia, agregaty i repozytoria: do którego pakietu należy moduł i kto może importować od kogo.

Repozytorium
skraft-plugin ↗
Licencja
GPL-3.0
Ostatnia zmiana repozytorium
11.10.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
1
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
0
Przestarzałość

Brak sygnałów. Repozytorium zmienione 11.10.2026, bez odwołań do wycofanych modeli i API.

Licencja

GPL-3.0, otwarta.

Co robi i kiedy

Pomaga układać usługę w Pythonie z pyproject.toml (FastAPI lub inny framework) i dodawać funkcje, endpointy, przypadki użycia, agregaty i repozytoria: do którego pakietu należy moduł i kto może importować od kogo.

Oryginalny opis (EN)

Use when laying out a Python service packaged with pyproject.toml (FastAPI or another web framework), or adding a feature, endpoint, use case, aggregate or repository to one — which package a module belongs in, which package may import which, and how an endpoint reaches a use case. Not for configuration, dependency or tooling changes.

Jak działa

  1. One package per layer
  2. Use cases
  3. Domain
  4. Guard
Sekcje z nagłówków SKILL.md, w oryginale · 62 linii, 513 słów
Podgląd SKILL.md
---
name: clean-architecture-python
description: Use when laying out a Python service packaged with pyproject.toml (FastAPI or another web framework), or adding a feature, endpoint, use case, aggregate or repository to one — which package a module belongs in, which package may import which, and how an endpoint reaches a use case. Not for configuration, dependency or tooling changes.
---

# Clean Architecture — Python

The layer rules are those of `architecture-patterns`. This skill maps them onto Python packages.

## One package per layer

| Package | Holds | May import |
|---|---|---|
| `<context>.domain` | aggregates, value objects, domain events | the standard library only |
| `<context>.application` | use cases and the `Protocol`s they call | `<context>.domain` |
| `<context>.infrastructure` | implementations of those `Protocol`s (SQLAlchemy, HTTP clients, files) | `<context>.application`, `<context>.domain` |
| `<context>.api` | routes, the app factory, the wiring of every class | all three |

- Lay out `src/<context>/` with one sub-package per layer, in a single `pyproject.toml`. A new feature goes into the existing layer packages, never into a new top-level package.
- FastAPI, Pydantic, SQLAlchemy and HTTP clients are imported only in `infrastructure` and `api`. Domain and application use `dataclasses` and `typing`.
- ORM models and their mapping live in `infrastructure`; never make a domain class an ORM or Pydantic model.
- Tests live in the two test packages `clean-architecture-testing` defines, never inside `src/`.

## Use cases

- A use case is a class named after the action (`BorrowBook`) with one public method. The route calls it directly: no `Protocol` or ABC in front of it, no `*Service` implementation.
- A command method returns `None`; the caller creates the new id and passes it in. A query returns a frozen `*ViewModel` dataclass defined in `application`, never a domain object.
- Application declares a `Protocol` only where it calls out (repository, gateway). A repository `Protocol` sits in `domain` when it persists an aggregate, in `application` otherwise.
- Who may *read* a resource is checked in the use case. Who may *change* it is an aggregate rule: the mutation method takes the caller's id and raises.
- Wire every class by hand in `api` (one composition module); FastAPI `Depends` appears only in `api`. No DI container.
- One transaction per use-case call, opened and committed in `api` around the call.
- Inside each layer, one sub-package per feature (`application/loans/borrow_book.py`, `infrastructure/loans/sql_loan_repository.py`), never a module at the layer root or a technical package (`repositories`, `services`, `models`). A feature imports no other feature; what two features use moves to a `shared` sub-package of that layer.
- No `ports` or `adapters` package, and no "port" in module, class or docstring.

## Domain

- An aggregate is created through a `classmethod` factory; code outside `domain` never calls the class itself. It is identified by a typed id (`OrderId`, a frozen dataclass or `NewType`), never a raw `str`, `int` or `UUID`.

## Guard

Declare the graph in `pyproject.toml` and add `import-linter` to the dev dependencies; the architecture test of `clean-architecture-testing` runs `lint-imports`:

```toml
[tool.importlinter]
root_package = "<context>"
include_external_packages = true

[[tool.importlinter.contracts]]
name = "Layers import inward only"
type = "layers"
layers = ["<context>.api", "<context>.infrastructure", "<context>.application", "<context>.domain"]

[[tool.importlinter.contracts]]
name = "Domain and application import no framework"
type = "forbidden"
source_modules = ["<context>.domain", "<context>.application"]
forbidden_modules = ["fastapi", "starlette", "pydantic", "sqlalchemy", "httpx"]

[[tool.importlinter.contracts]]
name = "Application features never import each other"
type = "independence"
modules = ["<context>.application.*"]
ignore_imports = ["<context>.application.** -> <context>.application.shared.**"]
unmatched_ignore_imports_alerting = "none"
```

Wersje

W bazie nie ma innych skilli o nazwie clean-architecture-python.

Migawka bazy z 13.11.2026 · wersja paczki 8c5c6c63c775 (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 0 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 100clean-architecture-react
    Pomaga układać i rozbudowywać front-end w React i TypeScript: do którego folderu należy ekran, komponent, hook, przypadek użycia lub wywołanie API, kto może importować od kogo i jak komponent dociera do API.
  • 100clean-architecture-java
    Pomaga układać i rozbudowywać usługę Java i Spring Boot z Mavenem: do którego modułu należy klasa, który moduł może zależeć od którego i jak endpoint dociera do przypadku użycia.
  • 100python-packaging
    Tworzy pakiety Python i dystrybuuje je w PyPI przez pyproject.toml i punkty wejścia oraz konfiguruje budowanie.
  • 100pyproject-generator
    Tworzy lub ujednolica plik pyproject.toml dla bibliotek Python, usług, serwerów MCP i backendu Electron.
  • 100flutter-clean-arch
    Pomaga tworzyć i audytować warstwy funkcji lub pakietu Flutter: gdzie należy use case, repozytorium, datasource, encja lub model, czy domena może importować Flutter i czy zależności są odwrócone.
  • 100python-best-practices
    Podaje dobre praktyki przy czytaniu i pisaniu plików Python, w tym pyproject.toml i requirements.txt.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.