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.0.tar.gz (9.3 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.0-py3-none-any.whl (18.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for architecture_checker-0.2.0.tar.gz
Algorithm Hash digest
SHA256 0bf800088ff87ef1d7a375156512bb12f66fe11c8a96030c31e27ee00c8aea3f
MD5 81195db99e05504a103843f808d09532
BLAKE2b-256 9f5edae1c61b7e6eae9b58eb6f7e5ff855a4ebede16c1ce90a332e5b25982a46

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for architecture_checker-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 24df85bff700954337810b4e7b27a8ed3176047b5aefbdbc388e7a1452f580e0
MD5 82bcb386f43ce4e00381896ada29bab2
BLAKE2b-256 9e7f27002cdf72ad3a1c67f68ef675bb12976b1682aa2edb9e0a5c2eedaca96c

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