Screen Architecture
One command, six files, none of them knowing more than it needs to — plus the two naming rules and the nesting rule an assistant gets wrong by habit.
One command, six files, none of them knowing more than it needs to
/new-feature Films "title:String,year:Int" on the default MVVM setup produces six small files, each with one job: a view that draws the screen and doesn't know where the data came from, a view model that depends on a protocol rather than the real network code, a repository that decides server vs. cache, a service that talks to the server, the shared data types, and a test that runs against a fake repository in milliseconds.
| File | Its job | What it deliberately doesn't know |
|---|---|---|
FilmsView | Draw the screen — loading, error and empty states come ready-made | Where the films came from |
FilmsViewModel | Hold what's on screen, decide what a tap does | Anything about SwiftUI, or which screen shows it |
FilmsRepository | Decide whether to hit the network or use what's already saved | That any screen exists |
FilmsService | Build the network request, parse the response | Why anyone wanted it |
Models/FilmsModels | The shared data types — request, response, the thing itself | Everything else |
FilmsViewModelTests | Test the view model against a fake repository — no network, milliseconds | The server |
Two naming rules worth knowing, because they're the ones an assistant gets wrong by habit. The protocol belongs to the code that uses it, not the code that implements it. And it's named for what it does (FilmsRepository) rather than for the pattern it belongs to (FilmsInteractorProtocol). There's also no extra UseCase layer between the view model and the repository — a file whose only job is to pass one call along is ceremony.
Screens that belong together live inside the parent's folder. A contacts area isn't three more folders at the top level: /new-feature Contacts/AddContact puts that screen at Features/Contacts/AddContact/ and its test in the matching place under the test folder, and the same goes for Contacts/Favorites and Contacts/ContactDetails. A parent keeps its own files while it gains children, so Contacts/ holds ContactsView.swift and the three child folders side by side and nothing already written has to move. The one thing folders don't do is scope names — the generated types, the navigation entry and the data types in Models/ all sit in one flat namespace — so give a child screen a name that's unique across the whole app: ContactDetails, not Details.
Four combinations come from fixed templates: MVVM+SwiftUI, VIP+SwiftUI, VIP+UIKit and MVC+UIKit have every layer file written from a real template — the same output every time, for everyone. Any other combination — MVC+SwiftUI, MV, VIPER, or any pattern paired with navigation other than its default — is assisted instead: you still get the folders, the data types, the wiring, the navigation entry and a test scaffold generated the same way every time, but the contents of the layer files are written by the assistant, guided by the architecture.md your setup produced. Even those four templated combinations are shaped for T1 and T2 — at T3, where files should go is a best guess.
Assisted does not mean automatic. Because the layer bodies depend on the mix of answers you gave — pattern, UI framework, navigation, persistence, DI — there is no single template that could cover them, so the assistant writes them from your written rules. In practice: describe the pattern you want in your own words when you ask for a feature — what each layer is called, which layer may talk to which, where state lives, and what the first feature should look like when it's done. The clearer that description, the closer the result. Then read the generated files before building on them, and once you have one feature you're happy with, say so plainly — "match the structure of the Films feature" — so every later screen has a concrete example to copy rather than a description to interpret. If you'd rather not do any of this, take the recommended defaults; that's exactly what they're for.