flx: Generate Clean Architecture for Flutter in Seconds
Introduction
As a Flutter developer, you've probably found yourself stuck in a messy codebase at some point — controllers everywhere, logic bleeding into UI, and files dumped in one huge folder. If you've ever said:
"I just want to generate my project structure properly using Clean Architecture..."
Then you're going to love this.
I created flx, a lightweight Flutter CLI tool that automatically generates a modular, clean architecture structure in seconds, with support for GetX and Bloc out of the box.
The Problem
Flutter gives us freedom, but too much freedom can lead to inconsistent folder structures, spaghetti logic, and poor scalability. Especially when you're working in a team, it's hard to maintain:
- Folder organization
- Clean separation of layers
- State management patterns
- Reusability and testability
This is where flx steps in — to standardize the project structure from day one.
What is flx?
flx is a command-line tool built in Dart, designed to help Flutter developers generate feature-based, clean-architecture-friendly folder structures with a single command.
It's heavily inspired by the feature-first modular approach, using Clean Architecture principles.
Key Features
- ⚙️ Clean Architecture structure: presentation, domain, data
- 🧱 Feature-based folders (
lib/features/auth
, etc.) - 🧠 State manager support: GetX and Bloc
- 🔧 Configuration via
.flxrc.json
- ✨ Minimal boilerplate to get started fast
Here's an example of the generated structure for a feature like 'auth':
lib/features/auth/
├── data/
│ ├── datasources/
│ ├── models/
│ └── repositories/
├── domain/
│ ├── entities/
│ ├── usecases/
│ └── repositories/
└── presentation/
├── pages/
├── controllers/ or bloc/
└── bindings/
No more guessing. No more messy folders.
How to Install
dart pub global activate flx
Then run:
flx config --state getx # or bloc
flx gen feature auth
Done. Your feature is ready with clean layers and structure.
Boilerplate Included
Every generated feature comes with:
- Folder structure for data, domain, presentation
- Ready-to-code files (controller, bloc, usecase, etc.)
- Configurable support for custom state managers (more coming)
Why Clean Architecture?
Because separation of concerns matters.
By following Clean Architecture:
- Your code becomes modular
- It's easier to test
- You avoid tight coupling
- You scale like a pro
Docs & Source Code
- 📘 Docs: flx-docs.vercel.app
- 💻 GitHub: github.com/yourusername/flx
- 🌐 pub.dev: pub.dev/packages/flx
Final Thoughts
Flx was born out of my frustration with cluttered projects. If it helps even one other dev build better, faster, and cleaner — it's worth it.
If you're building serious Flutter apps, give flx a try and let me know what you think. Contributions, ideas, and feedback are always welcome!