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.8.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.8-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: architecture_checker-0.2.8.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.8.tar.gz
Algorithm Hash digest
SHA256 4a70d076f659b1f7cb8ccaf75e081a3d7dd19592dd3d78d95688d71eeb929c03
MD5 bab2b1482c3832527ba1bb399b35a3f9
BLAKE2b-256 6fb849066178bb0765882a22fb89a9a9a143fff1c12ea4690616922f66fa72e2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for architecture_checker-0.2.8-py3-none-any.whl
Algorithm Hash digest
SHA256 97d1060cad40a34da21c133a612237412e9fec9797c251ed68c0241a8b05afea
MD5 28bfb605f87b7d93a27618e45bf84dd3
BLAKE2b-256 9fa65ac056ceafd56fead38f3e840e5261d1ccf9d848035a6506feabbfb3075c

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