u/trolleid

I built ArchUnit for Python: enforce architecture rules as unit tests.
▲ 11 r/PythonJobs+4 crossposts

I built ArchUnit for Python: enforce architecture rules as unit tests.

I just shipped ArchUnitPython, a library that lets you enforce architectural rules in Python projects through automated tests.

The problem it solves: as codebases grow, architecture erodes. Someone imports the database layer from the presentation layer, circular dependencies creep in, naming conventions drift. Code review catches some of it, but not all, and definitely not consistently.

This problem has always existed but is more important than ever in Claude Code, Codex times. LLMs break architectural rules all the time.

So I built a library where you define your architecture rules as tests. Two quick examples:

# No circular dependencies in services
rule = project_files("src/").in_folder("**/services/**").should().have_no_cycles()
assert_passes(rule)
# Presentation layer must not depend on database layer
rule = project_files("src/")
          .in_folder("**/presentation/**")
          .should_not()
          .depend_on_files()
          .in_folder("**/database/**")
assert_passes(rule)

This will run in pytest, unittest, or whatever you use, and therefore be automatically in your CI/CD. If a commit violates the architecture rules your team has decided, the CI will fail.

Hint: this is exactly what the famous ArchUnit Java library does, just for Python - I took inspiration for the name is of course.

Let me quickly address why this over linters or generic code analysis?

Linters catch style issues. This catches structural violations — wrong dependency directions, layering breaches, naming convention drift. It's the difference between "this line looks wrong" and "this module shouldn't talk to that module."

Some key features:

  • Dependency direction enforcement & circular dependency detection
  • Naming convention checks (glob + regex)
  • Code metrics: LCOM cohesion, abstractness, instability, distance from main sequence
  • PlantUML diagram validation — ensure code matches your architecture diagrams
  • Custom rules & metrics
  • Zero runtime dependencies, uses only Python's ast module
  • Python 3.10+

Very curious what you think! https://github.com/LukasNiessen/ArchUnitPython

u/trolleid — 7 days ago
▲ 31 r/ChatGPTPro+7 crossposts

Claude Code Skill for Terraform and OpenTofu: testing, modules, CI/CD, very token optimized

I just shipped a Claude Code & Codex skill that aggregates Terraform Best Practices, largely based on official HashiCorp best practices plus a bunch of other trusted sources I have collected over the years.

There's a couple skills out there already, so let me tell you why I created this skill.

Other skills burned through my tokens. So I checked their reference files and they basically just copied a couple best practice collections + terraform docs and pasted it in md files. Claude reads all of it and it's super expensive.

So I created a different approach. The agent diagnoses most likely failure modes (such as blast radius or secret exposure), and reads only targeted reference files. This is far leaner and far more token efficient, and it works IMO equally well or even better.

Similar to other skills it eliminates LLM hallucinations with Terraform. Curious about feedback!

PS: I also have a 5 min YT video where I demo the skill: https://www.youtube.com/watch?v=2N1TuxndgpY

github.com
u/trolleid — 1 day ago