All Projects → qossmic → Deptrac

qossmic / Deptrac

Licence: mit
Keep your architecture clean.

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to Deptrac

Go Cleanarch
Clean architecture validator for go, like a The Dependency Rule and interaction between packages in your Go projects.
Stars: ✭ 434 (-75.67%)
Mutual labels:  architecture, clean-architecture
Ios Clean Architecture Mvvm
Template iOS app using Clean Architecture and MVVM. Includes DIContainer, FlowCoordinator, DTO, Response Caching and one of the views in SwiftUI
Stars: ✭ 753 (-57.79%)
Mutual labels:  architecture, clean-architecture
Viabus Architecture
让 Android 开发可以像流水线一样高效的,职责分离架构 ⚡ 不同于 MVP 的配置解耦,也不能和 似是而非 的 MVVM - Clean 同日而语。VIABUS 是世界范围内首个明确提出,通过职责分离,来真正实现 UI 和 业务并行开发的 Android 项目级开发架构和设计模式理念。
Stars: ✭ 485 (-72.81%)
Mutual labels:  architecture, clean-architecture
Cleanarchitecturerxswift
Example of Clean Architecture of iOS app using RxSwift
Stars: ✭ 3,256 (+82.51%)
Mutual labels:  architecture, clean-architecture
Android Kotlin Clean Architecture
Android Sample Clean Architecture App written in Kotlin
Stars: ✭ 1,562 (-12.44%)
Mutual labels:  architecture, clean-architecture
Clean Architecture Zh
《架构整洁之道》中文翻译
Stars: ✭ 299 (-83.24%)
Mutual labels:  architecture, clean-architecture
Modular Monolith With Ddd
Full Modular Monolith application with Domain-Driven Design approach.
Stars: ✭ 6,210 (+248.09%)
Mutual labels:  architecture, clean-architecture
archunit-junit5-kotlin
Generic Architecture Tests written in Kotlin using ArchUnit and Junit5
Stars: ✭ 22 (-98.77%)
Mutual labels:  architecture, clean-architecture
Swift Design Patterns
🚀 The ultimate collection of various Software Design Patterns implemented in Swift [Swift 5.0, 28 Patterns].
Stars: ✭ 85 (-95.24%)
Mutual labels:  architecture, clean-architecture
Cleanarchitecturetemplate
A template for a dotnet core api / mvc "clean architecture" project.
Stars: ✭ 50 (-97.2%)
Mutual labels:  architecture, clean-architecture
Cleanaspnetcorewebapi
Starter project for creating APIs built on ASP.NET Core using clean architecture.
Stars: ✭ 279 (-84.36%)
Mutual labels:  architecture, clean-architecture
Polysemycleanarchitecture
Showcasing how the Polysemy library can be used to implement a REST application conforming to the guidelines of the Clean Architecture model.
Stars: ✭ 106 (-94.06%)
Mutual labels:  architecture, clean-architecture
Kotlin Modular Tdd Coroutines Mvvm
A sample Kotlin app which was built with modular structure, Kotlin DSL, Kotlin Coroutines, TDD and MVVM patterns.
Stars: ✭ 256 (-85.65%)
Mutual labels:  architecture, clean-architecture
Go Clean Arch
Go (Golang) Clean Architecture based on Reading Uncle Bob's Clean Architecture
Stars: ✭ 5,128 (+187.44%)
Mutual labels:  architecture, clean-architecture
golang-starter
Golang code boilerplate inspired by clean architecture
Stars: ✭ 49 (-97.25%)
Mutual labels:  architecture, clean-architecture
Android Showcase
💎 Android application following best practices: Kotlin, Coroutines, JetPack, Clean Architecture, Feature Modules, Tests, MVVM, DI, Static Analysis...
Stars: ✭ 5,214 (+192.26%)
Mutual labels:  architecture, clean-architecture
Python-CleanArchitecture-Example
This project is a sample Python(Flask) web application adapting Clean Architecture.
Stars: ✭ 69 (-96.13%)
Mutual labels:  architecture, clean-architecture
iOS-Clean-Architecture-Example
An iOS app designed using clean architecture and MVVM.
Stars: ✭ 50 (-97.2%)
Mutual labels:  architecture, clean-architecture
Cleanarchitecture
Clean Architecture Solution Template: A starting point for Clean Architecture with ASP.NET Core
Stars: ✭ 8,945 (+401.4%)
Mutual labels:  architecture, clean-architecture
Ios Architectures
Sample app for iOS architectures
Stars: ✭ 90 (-94.96%)
Mutual labels:  architecture, clean-architecture

Deptrac

What is Deptrac?

Deptrac is a static code analysis tool for PHP that helps you communicate, visualize and enforce architectural decisions in your projects. You can freely define your architectural layers over classes and which rules should apply to them.

For example, you can use Deptrac to ensure that bundles/modules/extensions in your project are truly independent of each other to make them easier to reuse.

Deptrac can be used in a CI pipeline to make sure a pull request does not violate any of the architectural rules you defined. With the optional Graphviz formatter you can visualize your layers, rules and violations.

ModelController1

Table of Contents

  1. Requirements
  2. Installation
    1. PHAR
    2. PHIVE
    3. Composer
    4. Optional Dependency: Graphviz
  3. Getting Started
    1. The Depfile
  4. Run Deptrac
  5. Contribute
    1. Code of Conduct
  6. Further Documentation

Requirements

In order to run Deptrac you need at least PHP 7.4. We also support PHP 8.

You can analyse projects that require an older PHP version as long as nikic/php-parser can parse it.

Installation

While you can install Deptrac using composer, we recommend using either the phar installation or PHIVE. This will ensure that Deptrac and its dependencies are bundled together and will not interfere with any of your project's dependencies.

PHAR

Download the latest deptrac.phar.

You can run the phar file using php:

php deptrac.phar analyse

All examples in this documentation, assume you have the deptrac.phar downloaded in your project's root directory as described above.

Feel free to add Deptrac to your PATH (i.e. /usr/local/bin/deptrac) to make it globally available.

curl -LS https://github.com/qossmic/deptrac/releases/download/0.18.0/deptrac.phar -o deptrac.phar

# optional
sudo chmod +x deptrac.phar
sudo mv deptrac.phar /usr/local/bin/deptrac

PHIVE

You can install Deptrac with Phive

phive install -g qossmic/deptrac

and accept the key with fingerprint 41DD E075 4745 9FAE CFA1 7813 B8F6 4013 4AB1 782E.

To upgrade Deptrac use the following command:

phive update -g qossmic/deptrac

Composer

We do not recommend installing this repository via Composer. Instead, please use the dedicated distribution repository https://github.com/qossmic/deptrac-shim.

When you install Deptrac using the qossmic/deptrac-shim package, you will get the benefit of using the phar installation, but you can use it like any other composer dependency, i.e. you run Deptrac like this:

composer require qossmic/deptrac-shim
php vendor/bin/deptrac analyse

Optional Dependency: Graphviz

If you want to create graphical diagrams with your class dependencies, you will also need the dot command provided by Graphviz.

Graphviz can be installed using common package managers:

# for macos + brew
brew install graphviz

# for ubuntu and debian
sudo apt-get install graphviz

Graphviz is also available for Windows. Install the current stable release and append the binary path on the environment variable Path (e.g. C:\Program Files (x86)\Graphviz2.38\bin).

Getting Started

In order to get started with Deptrac you will need a configuration file, called depfile. This configuration file is written in YAML and, by default, is stored with the name depfile.yaml in your project's root directory.

Deptrac can generate a template for you, using the init command.

php deptrac.phar init

The main purpose of this file is:

  1. Define in which directories Deptrac will search for classes and which files to exclude.
  2. Define your architectural layers using so-called collectors.
  3. Define a ruleset describing which layers can communicate with each other.

You can find out more about the Core Concepts in the docs.

The Depfile

Let's have a look at the generated file:

# depfile.yaml
paths:
  - ./src
exclude_files:
  - '#.*test.*#'
layers:
  -
    name: Controller
    collectors:
      -
        type: className
        regex: .*Controller.*
  -
    name: Repository
    collectors:
      -
        type: className
        regex: .*Repository.*
  -
    name: Service
    collectors:
      -
        type: className
        regex: .*Service.*
ruleset:
  Controller:
    - Service
  Service:
    - Repository
  Repository: ~

By default, Deptrac will search your project's src/ directory for classes and will ignore any files and directory having test in it.

We then define three layers by searching for class names in the files found by Deptrac. Any file containing a class with Controller will be grouped in a layer with the same name. The same happens for classes having Repository and Service in their name. It is important to note that the fully qualified class name is used for grouping classes. That means, the collector will take the full namespace into account.

The default ruleset will then allow classes in the Controller-layer to communicate - i.e. use classes from - the Service layer. Classes grouped in the Service layer may not use classes from the Controller layer, but they can use classes from the Repository layer. Classes inside the Repository layer may not use any classes from the other two layers.

You can learn more about the file in the Depfile reference.

Run Deptrac

Once you have set up the depfile you can run Deptrac to analyse your code and check for violations.

php deptrac.phar

# which is equivalent to
php deptrac.phar analyse depfile.yaml

If you run php deptrac.phar -v you'll get a more verbose output.

The analyse command runs with a caching mechanism for parsed files by default. This can be disabled with the --no-cache option.

The generated output will roughly look like this:

 ----------- --------------------------------------------------------------------------------------------------------------------------------
  Reason      Repository
 ----------- --------------------------------------------------------------------------------------------------------------------------------
  Violation   examples\MyNamespace\Repository\SomeRepository must not depend on examples\MyNamespace\Controllers\SomeController (Controller)
              /Users/dbr/workspace/qossmic/deptrac/examples/ControllerServiceRepository1/SomeRepository.php:5
 ----------- --------------------------------------------------------------------------------------------------------------------------------


 -------------------- -----
  Report
 -------------------- -----
  Violations           1
  Skipped violations   0
  Uncovered            0
  Allowed              4
  Warnings             0
  Errors               0
 -------------------- -----

This is a report generated by Deptrac. At the top you can see a list of violations, if there are any. A violation means, that a layer uses a layer that is prohibited by the configured ruleset. In this case, a class from the Repository layer uses a class from the Controller layer.

The table on the bottom gives you an overview over:

  • how many violations were found.
  • how many violations were skipped, meaning your depfile contains exceptions. which will not cause Deptrac to return with an error status code, e.g. in CI, when these violations are found.
  • how many classes were found in the directories, that were not assigned to a layer.
  • how many usages between layers were found that do not violate the ruleset.
  • how many warnings where encountered, e.g. because a class is grouped in multiple layers.
  • how many errors were encountered, e.g. when you exclude a violation in your depfile but that violation is not encountered.

If the output does not match your expectations please take a look at the debugging commands available in Deptrac.

You can also change the output format itself by using one of the many provided Output Formatters.

Contribute

Deptrac is in active development. We are looking for your suggestions and help to make it better.

Feel free to open an issue if you encounter bugs, have suggestions or would like to add a new feature to Deptrac.

Please feel free to improve this documentation, fix bugs, or work on a suggested feature by making a pull request on GitHub. Don't hesitate to ask for support, if you need help at any point.

The Contribution Guide in the documentation contains some advice for making a pull request with code changes.

Code of Conduct

If you are professional and polite then everything will be alright.

Please don't be inconsiderate or mean, or anything in between.

Further Documentation

You can find additional documentation on the following topics in the docs/ directory:

  • Core Concepts - explains layers, rules and violations in more details.
  • Depfile - reference for all available settings in a depfile
  • Collectors - reference for which collectors are available in Deptrac to define your layers.
  • Formatters - lists the different output formats supported by Deptrac
  • Debugging - overview of the debug commands
  • Contribute - advice for contributing code changes, e.g. how to run tests or how to build a phar file with your changes that you can use to analyse your projects
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].