Skip to main content

A tool to enforce architectural patterns in Django projects

Project description

Architecture Checker

Architecture Checker is a standalone Python tool for enforcing architectural patterns and dependencies in large Django 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 Django 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 Django 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.7.tar.gz (9.2 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.7-py3-none-any.whl (15.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: architecture_checker-0.2.7.tar.gz
  • Upload date:
  • Size: 9.2 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.7.tar.gz
Algorithm Hash digest
SHA256 11a04e44ee8f3ff5ebe18df1bbdf59cbf759cb8b81f5f6a6ca6c02e6eeda14c2
MD5 1f4b393913ab5b97d76c528dbe3f4050
BLAKE2b-256 7a19f3a3785e813ea61bf70b9c6c2cca9b7171b734025d6c89a1fccb07cec2bc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for architecture_checker-0.2.7-py3-none-any.whl
Algorithm Hash digest
SHA256 6b85d65672f623c89494ae7dabe802ea320f4c2e9b9ecbb407fdd85a81fa7594
MD5 7cbec5bd0f6b438935d75d707d58fca6
BLAKE2b-256 8b30409f06a117b82b23707e271d0f41a7e867a5931b5959f1a0ab321ef0943f

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