An AI agent will put code wherever it finds room unless you tell it where things go. Give it a clear architecture and it will keep a growing app tidy. Leave it vague and you get business logic in widgets and SDK calls in screens. This page explains Flutter’s own recommended structure, a feature-first way to lay it out on disk and the rules that keep an agent inside it. The principles are from Flutter’s architecture guide, read on the day this post was written. The folder layout is the one MobileKit’s pack uses, and it is a choice, not a requirement.
Flutter’s principles
Flutter’s guide says architecture is about “how to structure, organize, and design your Flutter app in order to scale as your project requirements and team grow”, and lists the benefits as maintainability, scalability, testability, lower cognitive load and a better user experience.
Its core ideas:
- Separation of concerns. Split an app into distinct parts with distinct jobs, including inside the UI layer.
- Layers. “Flutter applications should be written in layers”, usually two or three:
- the UI layer, which “displays data to the user that is exposed by the business logic layer, and handles user interaction”;
- the logic layer, which implements core business logic and is optional, “commonly known as the domain layer”;
- the data layer, which “manages interactions with data sources, such as databases or platform plugins.”
- Layers communicate only with the layers directly above or below them. “The UI layer shouldn’t know that the data layer exists, and vice versa.”
- A single source of truth for each data type, held in a repository in the data layer.
The guide also covers MVVM and state management, and dependency injection. It was written, it says, “for teams that have multiple developers contributing to the same code base, who’re building a feature-rich application.” A solo app can use the same shape with less ceremony.
Feature-first on disk
Layers describe responsibilities. They do not say where files go. Two common ways to arrange them:
- Layer-first: all screens in one folder, all repositories in another. Easy at first, but a single feature is spread over the whole tree.
- Feature-first: one folder per feature, with the layers inside it. Everything about “entries” lives together.
MobileKit uses feature-first:
lib/
app/ app widget, router, theme
core/ shared services: analytics, crash reporting, purchases, localisation
shared/ design-system components
features/<feature>/
data/ repositories and data objects
application/ state and use cases
presentation/ screens and widgets
The feature’s data folder is the data layer, application is the logic and state layer, and presentation is the UI layer. That maps Flutter’s layers onto each feature.
Rules that keep it clean
Write these in your CLAUDE.md. They are MobileKit’s, and they are easy for an agent to follow and for you to check:
- Features never import another feature’s
datafolder. Shared logic goes incore. - Repositories wrap SDKs such as Firebase or a purchases SDK, and return your own data types. Widgets never call an SDK directly.
- State lives in the
applicationlayer. One notifier per screen concern. - No business logic in
buildmethods. Event handlers call methods on the state object. - Screens compose small widgets.
- Each data type has one repository. Nothing else caches its own copy.
Those rules make the code testable, because you can replace a repository with a fake. See how to test a Flutter app with Claude Code, and Riverpod with Claude Code for the state layer.
Using it with Claude Code
Architecture only works if it is applied the same way every time. Three habits help:
- Put the layout and the rules in CLAUDE.md, in about twenty lines. See CLAUDE.md for Flutter.
- Ask for a plan before a feature: “List the files you will create, in which folders, and what each one does. Do not write code yet.” Check that each file is in the right layer.
- Review the imports. A widget importing a Firebase package is the quickest tell that a layer has leaked.
You can also enforce parts of it automatically. A lint or a script can fail the build when a feature imports another feature’s data folder, and a hook can run it after every edit. See Claude Code hooks for Flutter.
Common mistakes
- Putting everything in
coreuntil it is a second app. Shared code should be genuinely shared. - A logic layer with nothing in it. Flutter calls it optional, so skip it until real business logic appears.
- Two sources of truth, such as a screen that keeps its own copy of a list the repository also holds.
- Over-engineering a prototype. Start with the folders and rules. Add layers as the app earns them.
Where MobileKit fits
The pack’s Flutter standards carry this layout and its rules, the scaffold stage creates the folders in the first phase, and the build stage checks each phase against them. For the first steps, see Flutter project setup with Claude Code, and for the whole route, Build a Flutter app with Claude Code.
Sources read on the day this post was written: Flutter: architecting Flutter apps and Flutter: architectural concepts.