agentleFS
moasqmoasq/ios-dev-agent/.cursor/rules/file-structure.mdc

ios-dev-agent / rules

Cursor rule4 starsChanged 6 months agoMITView on GitHub

iOS development rule

The file

We split this file-structure.mdc into the rules it gives an agent

3 rules. About 0 are common, 1 is distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    When a view grows beyond 150 lines, split into extensions by section:

    line 43
  2. Very specific:

    NEVER use flat Views/, ViewModels/, or Components/ top-level directories

    line 83
  3. Very specific:

    Every View and its ViewModel MUST live under Features/<FeatureName>/

    line 84

≈ “Common” is an estimate: at least 1 in 5 of the 6,668 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
file-structure.mdc
---
description: iOS development rule
globs: "**/*.swift"
alwaysApply: true
---

# File Structure Rules

## Line Limit
- **Target**: 150 lines per file — aim for this
- **Hard limit**: 200 lines — files exceeding 200 lines MUST be split using extensions (`View+Sections.swift`)
- Files between 150-200 lines are acceptable if splitting would hurt readability

## Body as Table of Contents
The `body` property should read like a table of contents — only referencing computed properties, not containing implementation:

```swift
// Good
var body: some View {
    VStack {
        headerSection
        contentSection
        footerSection
    }
}

// Bad — implementation directly in body
var body: some View {
    VStack {
        HStack {
            Image(systemName: "person")
            Text(user.name)
                .font(AppTheme.Fonts.headline)
            Spacer()
            Button("Edit") { showEdit = true }
        }
        // ... 80+ more lines
    }
}
```

## Extension Splitting Pattern
When a view grows beyond 150 lines, split into extensions by section:

```swift
// ProfileView.swift — main file
struct ProfileView: View {
    @State var viewModel: ProfileViewModel

    var body: some View {
        ScrollView {
            headerSection
            statsSection
            settingsSection
        }
    }
}

// ProfileView+Sections.swift — extracted sections
extension ProfileView {
    var headerSection: some View { ... }
    var statsSection: some View { ... }
    var settingsSection: some View { ... }
}
```

## Directory Structure
```
Models/              → Data model structs (with static sampleData)
Shared/              → Shared utility types (e.g. Loadable.swift)
Config/              → App configuration (e.g. AppConfig.swift with API keys, endpoints)
Repositories/<Entity>/ → Repository protocols + concrete implementations, grouped by entity
                       (e.g. Repositories/Users/UserRepository.swift,
                             Repositories/Users/LocalUserRepository.swift)
                       External-service repositories only when that service is explicitly configured
Theme/               → AppTheme.swift only
Services/<Domain>/   → Domain services (Auth, Networking, etc.) — NOT in Features/
Features/<Name>/     → Co-locate View + ViewModel (e.g. Features/TodoList/TodoListView.swift)
Features/Common/     → Shared reusable views used by multiple features
App/                 → @main app entry point only
```

- NEVER use flat `Views/`, `ViewModels/`, or `Components/` top-level directories
- Every View and its ViewModel MUST live under `Features/<FeatureName>/`
- Services handle business logic and external integrations — `Features/` is exclusively for Views + ViewModels
- Shared components go under `Features/Common/`

## One Type Per File
- Each file contains exactly one primary type (struct, class, or enum)
- Extensions of the same type may live in separate files
- File name matches the type name: `ProfileView.swift` for `struct ProfileView`

## Naming Conventions
- Views: `{Feature}View.swift` (e.g., `NotesListView.swift`)
- ViewModels: `{Feature}ViewModel.swift` (e.g., `NotesListViewModel.swift`)
- Models: `{ModelName}.swift` (e.g., `Note.swift`)
- Theme: `AppTheme.swift`
- App entry: `{AppName}App.swift`

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.