A Pylint plugin for enforcing Clean Architecture principles and Design Patterns.
Project description
pylint-clean-architecture
A powerful, highly-opinionated Pylint plugin for enforcing Clean Architecture (The Onion Architecture) principles in Python projects.
This linter acts as a "GPS" for your codebase, preventing technical debt by strictly enforcing architectural boundaries, dependency rules, and design patterns.
Features
- Layer Boundary Enforcement: Prevents inner layers (Domain, UseCase) from importing outer layers (Infrastructure, Interface).
- Dependency Injection Checks: Forbids direct instantiation of infrastructure classes in UseCases.
- Design Pattern Enforcement: Detects "naked returns" from repositories, delegation anti-patterns, and more.
- Law of Demeter: Enforces loose coupling by flagging deep method chains.
- Contract Integrity: Ensures Infrastructure classes correctly implement Domain Protocols.
- Anti-Bypass Guard: Prevents "lazy" disabling of linter rules without justification.
Installation
pip install pylint-clean-architecture
Usage
Add the plugin to your pyproject.toml or Pylint configuration:
[tool.pylint.main]
load-plugins = ["clean_architecture_linter"]
Run Pylint as usual:
pylint src/
AI Coding Assistant Support
The clean-arch-init command generates architectural instructions for AI agents (like Cursor or GitHub Copilot) to prevent "Split Brain" issues by teaching the AI your project's rules before it writes code.
Usage:
clean-arch-init
Outcome: This creates a customized .agent/instructions.md file based on the layer names defined in the project's pyproject.toml.
Configuration
The linter is configured via [tool.clean-arch] in pyproject.toml.
[tool.clean-arch]
# 1. Project Type Presets (generic, cli_app, fastapi_sqlalchemy)
project_type = "generic"
# 2. Strict Visibility Enforcement
visibility_enforcement = true
# 3. Custom Layer Mapping (Map directory regex patterns to layers)
[tool.clean-arch.layer_map]
"services" = "UseCase"
"infrastructure/clients" = "Infrastructure"
"domain/models" = "Domain"
Rules
See RULES.md for a complete catalog of enforced rules and "Clean Fix" examples.
Contributing
- Fork the repo.
- Install dependencies:
make install. - Run tests:
make test. - Submit a PR.
Project details
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 clean_architecture_linter_plugin-1.1.2.tar.gz.
File metadata
- Download URL: clean_architecture_linter_plugin-1.1.2.tar.gz
- Upload date:
- Size: 24.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a9321816048e46ead54707732c4b95f73f532ff7c706f9c3bcdfeb8aebd18ee5
|
|
| MD5 |
0956d0eda89a0a60eae08149ab81616c
|
|
| BLAKE2b-256 |
1f61878f459ba90f99b73b4d7454aca706990c350b578941ff9d2872caae1e72
|
Provenance
The following attestation bundles were made for clean_architecture_linter_plugin-1.1.2.tar.gz:
Publisher:
publish.yml on noah-goodrich/pylint-clean-architecture
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
clean_architecture_linter_plugin-1.1.2.tar.gz -
Subject digest:
a9321816048e46ead54707732c4b95f73f532ff7c706f9c3bcdfeb8aebd18ee5 - Sigstore transparency entry: 813329995
- Sigstore integration time:
-
Permalink:
noah-goodrich/pylint-clean-architecture@ddf0f17b26f1b9f55268a10f4eef1da05b32b73d -
Branch / Tag:
refs/heads/main - Owner: https://github.com/noah-goodrich
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ddf0f17b26f1b9f55268a10f4eef1da05b32b73d -
Trigger Event:
push
-
Statement type:
File details
Details for the file clean_architecture_linter_plugin-1.1.2-py3-none-any.whl.
File metadata
- Download URL: clean_architecture_linter_plugin-1.1.2-py3-none-any.whl
- Upload date:
- Size: 27.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
164502590baf280d1cd1721f480b3d7b6ac78b12cb0f587af2a2a16c7d22f537
|
|
| MD5 |
3ccb1328887b4558398215b5aa14ba35
|
|
| BLAKE2b-256 |
b6b8593e98d4406bcdc5c4a94c13e4e8503da1dc2cee3070055d2b09961d2337
|
Provenance
The following attestation bundles were made for clean_architecture_linter_plugin-1.1.2-py3-none-any.whl:
Publisher:
publish.yml on noah-goodrich/pylint-clean-architecture
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
clean_architecture_linter_plugin-1.1.2-py3-none-any.whl -
Subject digest:
164502590baf280d1cd1721f480b3d7b6ac78b12cb0f587af2a2a16c7d22f537 - Sigstore transparency entry: 813329997
- Sigstore integration time:
-
Permalink:
noah-goodrich/pylint-clean-architecture@ddf0f17b26f1b9f55268a10f4eef1da05b32b73d -
Branch / Tag:
refs/heads/main - Owner: https://github.com/noah-goodrich
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ddf0f17b26f1b9f55268a10f4eef1da05b32b73d -
Trigger Event:
push
-
Statement type: