Skip to main content

A tool to enforce architectural patterns in python projects

Project description

Architecture Checker

Architecture Checker is a standalone Python tool for enforcing architectural patterns and dependencies in large python projects. By analyzing code structure and dependencies, this tool ensures that architectural rules are followed, promoting cleaner, more maintainable, and modular codebases.

Inspired by https://github.com/qossmic/deptrac

Features

  • Layer-Based Analysis: Define project layers and restrict their dependencies to enforce modularity.
  • Dynamic Layer Configuration: Easily configure collectors for each layer using file patterns and class inheritance.
  • Cross-Layer Dependency Rules (TODO): Specify rules to disallow certain layers from accessing others.
  • Extensible and Configurable: Customize layers and rules for any python project setup.

Installation

To install Architecture Checker, use pip:

pip install architecture_checker

Configuration

Before running the tool, create a configuration file (config.yaml or similar) that specifies the rules and target files to enforce.

Example Configuration (config.example.yaml)

layers:
  - name: models
    collectors:
      - type: class_inherits
        base_class: "django.db.models.Model"

  - name: services
    collectors:
      - type: file_regex
        regex: "^.*/providers.py$"

  - name: views
    collectors:
      - type: file_regex
        regex: ".*/views_api.py"

ruleset:
  views:
    disallow:
      - models  # Disallows direct access to models in views

Usage

Run the tool from the command line by specifying the project root directory and configuration file:

python run_architecture_checker.py --project_root='/path/to/your_project' --config=config.example.yaml

Arguments

  • --project_root: The path to the root of the project where apps are located.
  • --config: Path to the configuration file that defines the rules and target files.

Sample Output

If violations are found, the tool will output a summary of architectural violations grouped by app, along with details of each violation, such as the file, line number, and violation message.

/path/to/your_project/your_project/app1/views_api.py:74 - Layer 'views' is not allowed to depend on layer 'models'

Running Tests

To test the tool, use unittest:

python -m unittest discover tests

License

See the LICENSE file for details.

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

architecture_checker-0.2.9.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

architecture_checker-0.2.9-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file architecture_checker-0.2.9.tar.gz.

File metadata

  • Download URL: architecture_checker-0.2.9.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for architecture_checker-0.2.9.tar.gz
Algorithm Hash digest
SHA256 43ddd120b53609fa501942c7d9a93defa294d18e44a1e26ca51e14aabd4d52a1
MD5 04f135141638352ca1e8cc8ca2c6188f
BLAKE2b-256 927b9eac887381a9ed5fcf23c6def8e8d4da8c7cb03f2876f26a552a956d747b

See more details on using hashes here.

File details

Details for the file architecture_checker-0.2.9-py3-none-any.whl.

File metadata

File hashes

Hashes for architecture_checker-0.2.9-py3-none-any.whl
Algorithm Hash digest
SHA256 4dbaa2e8f93a1dee36109c1acc82957e594425a04427eeb8b9f9e970fa1d818b
MD5 8aa368d3a6360f5b7501a6ba0249b8aa
BLAKE2b-256 4ff46391eb84e5cc152b8515f604fed9443db70912a596b9243dee21509ff069

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page