Lint your architecture
David Seddon
david@seddonym.me
Blog: http://seddonym.me
Please note: this talk was given for an
earlier version of Layer Linter.
Check the latest docs before attempting to implement.
layer-linter.readthedocs.io
This talk
1. The shape of a code base
2. A tool to stay in shape
How many modules in
your code base?
a. Less than 10
b. 10s
c. 100s
d. 1,000s +
'Accidental complexity'
How much does accidental complexity
affect your productivity?
a. Not at all
b. A little
c. Somewhat
d. A lot
1. The shape of a
code base
Graph
Directed Graph
# pets/dogs.py
from . import cats
Your modules form a Directed Graph
What is your application
shaped like?
"The goal of an architect is to minimize the human resources required to build and maintain the required system.
"What is it that saps this kind of
people-power? Coupling."
'Uncle Bob' Martin, Clean Architecture, 2018 (p. 160)
Using layers to
reduce coupling
Layers
An ordered
list of Python modules.
No layer import from a layer above it.
Layers between components
Layers within components
Layers between and
within components
Do your applications have
designed dependency flows?
If you do, is the design
always adhered to?
2. A tool to stay
in shape
layer-lint pets
layers.yml
Contract
Contract
Text
$ layer-lint pets
============
Layer Linter
============
---------
Contracts
---------
Analyzed 23 files, 44 dependencies.
-----------------------------------
My layer contract KEPT
Contracts: 1 kept, 0 broken.
Text
$ layer-lint pets
============
Layer Linter
============
---------
Contracts
---------
Analyzed 23 files, 44 dependencies.
-----------------------------------
My layer contract BROKEN
Contracts: 0 kept, 1 broken.
----------------
Broken contracts
----------------
My layer contract
-----------------
1. pets.cats.fur imports pets.dogs.walkies:
pets.cats.fur <-
pets.utils <-
pets.dogs.walkies
Top level layers:
packages:
- pets
layers:
- dogs
- cats
- rabbits
layers.yml
Layers within components:
packages:
- pets.dogs
- pets.cats
- pets.rabbits
layers:
- personality
- traits
- physical
Layers within components:
packages:
- pets.dogs
- pets.cats
- pets.rabbits
layers:
- personality
- traits
- physical
Top level layers:
packages:
- pets
layers:
- dogs
- cats
- rabbits
Text
Top level layers:
packages:
- pets
layers:
- dogs
- cats
- rabbits
whitelisted_paths:
- pets.cats.whiskers <- pets.utils
Whitelisted paths
Upcoming features
-
Closed layers
-
Independent layers
Design
Whitelist
Reduce whitelist
How to begin
Feedback wanted!
In summary
- Think of your code base as a
directed graph.
- Be an architect! Reduce coupling by imposing constraints on this graph.
- Layer Linter can help you do this.
Layer Linter
layer-linter.readthedocs.io
This talk's slides:
slides.com/davidseddon/lint-your-architecture
My blog:
seddonym.me
Work at Octopus Energy:
octopus.energy/careers/
David Seddon
david@seddonym.me @seddonym seddonym.me
Graphs of well
known codebases
http://www.grokcode.com/864/snakefooding-python-code-for-complexity-visualization/
Requests
http://www.grokcode.com/864/snakefooding-python-code-for-complexity-visualization/
Flask
http://www.grokcode.com/864/snakefooding-python-code-for-complexity-visualization/
Celery
http://www.grokcode.com/864/snakefooding-python-code-for-complexity-visualization/
Django
Lint your architecture
By David Seddon
Lint your architecture
Code bases have a nasty habit of becoming a complicated web of circular dependencies. To stop this happening, you need constraints on your project's structure. Meet Layer Linter, a tool to control the dependencies between modules in your Python project. https://layer-linter.readthedocs.io/
- 2,147