qossmic / deptrac

Keep your architecture clean.
https://qossmic.github.io/deptrac
MIT License
2.59k stars 136 forks source link

Vendor folder as a layer question #1405

Open MihaiNeagu opened 4 months ago

MihaiNeagu commented 4 months ago

Regarding the treatment of the vendor as a layer, I have the following depfile

parameters:
  ProjectName: MyProject

deptrac:
  paths:
    - ./src/MyProject
    - ./vendor
  exclude_files:
    - '#.*test.*#'
  layers:
    - name: DomainLayer
      collectors:
        - type: classNameRegex
          value: '#^%ProjectName%\\Domain.*#'
    - name: ApplicationLayer
      collectors:
        - type: classNameRegex
          value: '#^%ProjectName%\\Application.*#'
    - name: InfrastructureLayer
      collectors:
        - type: classNameRegex
          value: '#^%ProjectName%\\Infra.*#'

    - name: InternalPackagesLayer
      collectors:
        - type: directory
          value: 'vendor/symfony/*'
        - type: directory
          value: 'vendor/doctrine/*'
        - type: directory
          value: 'vendor/some-package/*'

    - name: ExternalPackagesLayer
      collectors:
        - type: bool
          must:
            - type: directory
              value: 'vendor/*'
          must_not:
            - type: layer
              value: InternalPackagesLayer

  ruleset:
    InternalPackagesLayer:
      - ExternalPackagesLayer
    ExternalPackagesLayer:
      - InternalPackagesLayer
    InfrastructureLayer:
      - DomainLayer
      - ApplicationLayer
      - InternalPackagesLayer
      - ExternalPackagesLayer
    ApplicationLayer:
      - DomainLayer
      - InternalPackagesLayer
    DomainLayer:
      - InternalPackagesLayer

Event though InternalPackagedLayer is set to depend on ExternalPackagesLayer and viceversa, somehow deptrac returns errors for violations of dependencies between these two layers.

Some examples:

Reason      InternalPackagesLayer                                                                                                                                                 
  Violation   Symfony\Bundle\FrameworkBundle\Test\BrowserKitAssertionsTrait must not depend on PHPUnit\Framework\ExpectationFailedException (ExternalPackagesLayer)                 
  Violation   Symfony\Bundle\FrameworkBundle\Test\BrowserKitAssertionsTrait must not depend on PHPUnit\Framework\ExpectationFailedException (ExternalPackagesLayer)                 
  Violation   Symfony\Bundle\FrameworkBundle\Test\KernelTestCase must not depend on PHPUnit\Framework\Reorderable (ExternalPackagesLayer)                                           
  Violation   Symfony\Bundle\FrameworkBundle\Test\KernelTestCase must not depend on PHPUnit\Framework\SelfDescribing (ExternalPackagesLayer)                                        
  Violation   Symfony\Bundle\FrameworkBundle\Test\WebTestCase must not depend on PHPUnit\Framework\Reorderable (ExternalPackagesLayer)                                              
  Violation   Symfony\Bundle\FrameworkBundle\Test\WebTestCase must not depend on PHPUnit\Framework\SelfDescribing (ExternalPackagesLayer)                                           

and

Reason      ExternalPackagesLayer                                                                                                           
  Violation   GuzzleHttp\Utils must not depend on Symfony\Polyfill\Intl\Idn\Idn (InternalPackagesLayer)                                       
  Violation   GuzzleHttp\Utils must not depend on Symfony\Polyfill\Intl\Idn\Idn (InternalPackagesLayer)                                       
  Violation   GuzzleHttp\Utils must not depend on Symfony\Polyfill\Intl\Idn\Idn (InternalPackagesLayer)                                       
  Violation   GuzzleHttp\Utils must not depend on Symfony\Polyfill\Intl\Idn\Idn (InternalPackagesLayer)                                       
  Violation   PHPStan\PharAutoloader must not depend on Symfony\Polyfill\Php80\Php80 (InternalPackagesLayer)                                  
  Violation   PHPStan\PharAutoloader must not depend on Symfony\Polyfill\Mbstring\Mbstring (InternalPackagesLayer)                            
  Violation   PHPStan\PharAutoloader must not depend on Symfony\Polyfill\Intl\Normalizer\Normalizer (InternalPackagesLayer)                   
  Violation   PHPStan\PharAutoloader must not depend on Symfony\Polyfill\Php73\Php73 (InternalPackagesLayer)                                  
  Violation   PHPStan\PharAutoloader must not depend on Symfony\Polyfill\Intl\Grapheme\Grapheme (InternalPackagesLayer)                       
  Violation   PHPStan\PharAutoloader must not depend on Symfony\Polyfill\Php81\Php81 (InternalPackagesLayer)                                  

What am I doing wrong here?

Originally posted by @MihaiNeagu in https://github.com/qossmic/deptrac/issues/506#issuecomment-2018293291

patrickkusebauch commented 4 months ago

Hello, There is nothing wrong that I can see with the config. Can you provide a minimal reproducer in a stand-alone repository that I could debug?

Also, for handling vendor dependencies, I would suggest taking a look at composer collector. It might fit your use case better.