import-linter icon indicating copy to clipboard operation
import-linter copied to clipboard

Visualising the layer structure on a CLI command

Open nazliander opened this issue 4 weeks ago β€’ 1 comments

Hi @seddonym πŸ‘‹

We recently started using import-linter in our team - it's awesome and has made our architecture tests much cleaner!

We'd like to visualise our import layers to share with colleagues in a centralised place (e.g. in our CLI tool).

Would it make sense to add this functionality to import-linter directly? I've already prepared a simple CLI command in a fork.

The idea is to provide a command like:

uv run show-import-layers

Which outputs ASCII art of the layer hierarchy (including the awesome logo!):

╔══╗─────────▢╔╗ β•”β•—      ╔╗◀───┐
β•šβ•£β• β•β—€β”€β”€β”€β”€β”€β”  β•”β•β•šβ•—β•‘β•‘β”€β”€β”€β”€β–Άβ•”β•β•šβ•—   β”‚
 β•‘β•‘   ╔══╦══╦╩╗╔╝║║  ╔╦═╩╗╔╝╔═╦══╗
 ║║╔══╣╔╗║╔╗║╔╣║ β•‘β•‘ ╔╬╣╔╗║║ ║│║╔═╝
β•”β•£β• β•£β•‘β•‘β•‘β•šβ•β•‘β•šβ•β•‘β•‘β•‘β•šβ•—β•‘β•šβ•β•β•‘β•‘β•‘β•‘β•‘β•šβ•—β•‘β•β•£β•‘
β•šβ•β•β•©β•©β•©β•£β•”β•β•©β•β•β•©β•β•šβ•β•β•šβ•β•β•β•©β•©β•β•šβ•©β•β•©β•©β•β•©β•
  └──▢║║                    β–² 
      β•šβ•β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜


--------------------
Layered architecture
--------------------

        β–² higher level (can import from layers below)
        β”‚
   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   β”‚            cli             β”‚
   β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
  ↓│            api             β”‚
   β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
  ↓│         contracts          β”‚
   β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
  ↓│       configuration        β”‚
   β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
  ↓│          adapters          β”‚
   β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
  ↓│  application   β•‘   domain  β”‚
   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
        β”‚
        β–Ό lower level (cannot import layers above)

  β”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆ
  Legend:
    β•‘  independent modules (cannot import each other)

Happy to talk about it in a PR if you're interested.

nazliander avatar Dec 12 '25 17:12 nazliander

I love this!

I have actually been thinking about expanding the scope of Import Linter beyond just a linter, for more visualization tooling. In particular I have been wondering if my other library Impulse might work better inside Import Linter.

I think there is some design thought needed to work out how the different tooling would fit together. E.g. maybe Import Linter should provide a series of subcommands il lint, il visualize-contracts, il drawgraph etc. I can see some complexity in implementing this particular visualization of the layers and how that would fit in with other things, but I'm interested to see the code even if it doesn't get implemented in using the API you've suggested here - I'll take a look.

I wonder if each contract type could optionally get a visualization API that it could implement. Then maybe there is a command for visualizing a contract based on the contract id.

Let me think about it a bit.

seddonym avatar Dec 12 '25 17:12 seddonym