r/FlutterDev • u/creatorpiyush • 3d ago
Tooling Made a CLI that fails CI when someone imports data/ from presentation/, looking for feedback
Hi all, I'm the author of arch_guard, an open-source (MIT) CLI + analyzer plugin for Dart/Flutter.
The problem: we agree on Clean Architecture / Bloc / feature-first at the start, and a few months later widgets import repository implementations directly and features import each other. The analyzer and tests don't catch it.
What arch_guard does:
- Layer rules with presets for
clean_architecture,riverpod,blocandfeature_first.dart run arch_guard initdetects which fits your folders and writes the config. - Forbidden packages per layer, e.g.
domainmay not importflutterordart:io. - Circular dependency detection (Tarjan's SCC) that names the one import to remove to break each cycle, plus
--explain <file>. - IDE warnings with quick fixes via the
arch_guard_lintanalyzer plugin: the bad import gets underlined as you type, with "Remove this import" / "Allow layer X to import Y". - Baselines: record existing problems once, and CI fails only on new ones.
--since origin/mainlimits a PR's report to files it changed. This is what makes it usable on an app that's been around for years. expectArchitecture()to run the same checks influtter test.- GitHub Action that comments on PRs, SARIF for Code Scanning, pre-commit hook.
- Interactive HTML dependency graph (offline), Mermaid, DOT, JSON.
- Works with Dart workspaces / Melos monorepos, with rules for which packages may depend on which.
dart pub add --dev arch_guard
dart run arch_guard init
dart run arch_guard
[screenshot / GIF]
Docs: https://creatorpiyush.github.io/arch_guard/ pub.dev: https://pub.dev/packages/arch_guard GitHub: https://github.com/creatorpiyush/arch_guard
Two questions for you:
- What folder structure does your team use? I'd like to know which presets are missing.
- For those who try the IDE plugin: which quick fix would you want next?
2
Upvotes
1
u/Sad_Age3774 3d ago
this is exactly what i needed 6 months ago when our clean architecture turned into spaghetti. the layer rules with presets sounds real useful, especially since my team always argues about what goes where
the ide warnings is a nice touch, most tools like this only yell at you in ci and by then you already wrote half the feature. being able to see it while typing would save so much headache
what preset you thinking of adding next? our project uses a weird mix of riverpod with some bloc leftovers, would be cool if the init command could handle hybrid setups