|
Bogdan Timofte
authored
a week ago
|
1
|
# Project Structure and Naming
|
|
|
2
|
|
|
|
3
|
This document defines how we name SwiftUI views and how we place files in the project so the codebase matches the product language and the UI hierarchy.
|
|
|
4
|
|
|
|
5
|
## Core Rules
|
|
|
6
|
|
|
|
7
|
- Name folders after the feature or navigation surface the user sees.
|
|
|
8
|
- Example: the Home tab lives in `Views/Meter/Tabs/Home/`, not in `Connection/`.
|
|
|
9
|
- Name the main view in a folder after the feature it owns.
|
|
|
10
|
- Example: `MeterHomeTabView.swift` is the root view for the meter Home tab.
|
|
|
11
|
- Keep the file name and the Swift type name identical.
|
|
|
12
|
- Example: `MeterOverviewSectionView.swift` contains `MeterOverviewSectionView`.
|
|
|
13
|
- Prefer product language over implementation history.
|
|
|
14
|
- If the app says "Home", use `Home` in code instead of older terms like `Connection`.
|
|
|
15
|
- Use `Components/` only for reusable building blocks.
|
|
|
16
|
- A component is used in multiple views or is clearly meant to be reused.
|
|
|
17
|
- Example: `MeterInfoCardView` and `MeterInfoRowView`.
|
|
|
18
|
- Use `Subviews/` for views that belong to a single parent feature.
|
|
|
19
|
- A subview is used once or is tightly coupled to one screen/tab.
|
|
|
20
|
- Example: `Views/Meter/Tabs/Home/Subviews/MeterOverviewSectionView.swift`.
|
|
|
21
|
- Use `Sheets/` for modal flows presented from another screen.
|
|
|
22
|
- Example: `Views/Meter/Sheets/AppHistory/AppHistorySheetView.swift`.
|
|
|
23
|
- Keep reusable components close to the narrowest shared owner.
|
|
|
24
|
- If a component is reused only inside Meter screens, keep it in `Views/Meter/Components/`.
|
|
|
25
|
- Do not move it to app-wide `Views/Components/` unless it is truly generic.
|
|
|
26
|
- Keep small support types next to their owner.
|
|
|
27
|
- If a helper type exists for one view only, keep it in the same file or the same feature subfolder.
|
|
|
28
|
- Avoid vague verbs or placeholder names.
|
|
|
29
|
- Prefer `MeterNameEditorView` over `EditNameView`.
|
|
|
30
|
- Prefer `MeterConnectionActionView` over `ConnectionPrimaryActionView`.
|
|
|
31
|
- A folder should describe ownership, not implementation detail.
|
|
|
32
|
- `Home/Subviews/` is better than `Connection/Components/` when the views are single-use parts of the Home tab.
|
|
|
33
|
|
|
|
34
|
## Naming Checklist
|
|
|
35
|
|
|
|
36
|
Before adding or renaming a file, check:
|
|
|
37
|
|
|
|
38
|
- Can someone guess the file location from the screen name?
|
|
|
39
|
- Does the type name say what the view renders?
|
|
|
40
|
- Is this reused enough to deserve `Components/`?
|
|
|
41
|
- If it is single-use, does it live under the parent feature's `Subviews/` folder?
|
|
|
42
|
- Does the code use the same words as the UI?
|
|
|
43
|
|
|
|
44
|
## Current Meter Tab Pattern
|
|
|
45
|
|
|
|
46
|
Use this structure for Meter tab work:
|
|
|
47
|
|
|
|
48
|
```text
|
|
|
49
|
Views/Meter/
|
|
|
50
|
Components/
|
|
|
51
|
MeasurementChartView.swift
|
|
|
52
|
MeterInfoCardView.swift
|
|
|
53
|
MeterInfoRowView.swift
|
|
|
54
|
Sheets/
|
|
|
55
|
AppHistory/
|
|
|
56
|
AppHistorySheetView.swift
|
|
|
57
|
Subviews/
|
|
|
58
|
AppHistorySampleView.swift
|
|
|
59
|
ChargeRecord/
|
|
|
60
|
ChargeRecordSheetView.swift
|
|
|
61
|
Subviews/
|
|
|
62
|
ChargeRecordMetricsTableView.swift
|
|
|
63
|
DataGroups/
|
|
|
64
|
DataGroupsSheetView.swift
|
|
|
65
|
Subviews/
|
|
|
66
|
DataGroupRowView.swift
|
|
|
67
|
Tabs/
|
|
|
68
|
Home/
|
|
|
69
|
MeterHomeTabView.swift
|
|
|
70
|
Subviews/
|
|
|
71
|
MeterConnectionActionView.swift
|
|
|
72
|
MeterConnectionStatusBadgeView.swift
|
|
|
73
|
MeterOverviewSectionView.swift
|
|
|
74
|
Live/
|
|
|
75
|
MeterLiveTabView.swift
|
|
|
76
|
Subviews/
|
|
|
77
|
LoadResistanceIconView.swift
|
|
|
78
|
MeterLiveContentView.swift
|
|
|
79
|
MeterLiveMetricRange.swift
|
|
|
80
|
Chart/
|
|
|
81
|
MeterChartTabView.swift
|
|
|
82
|
Settings/
|
|
|
83
|
MeterSettingsTabView.swift
|
|
|
84
|
Subviews/
|
|
|
85
|
MeterCurrentScreenSummaryView.swift
|
|
|
86
|
MeterNameEditorView.swift
|
|
|
87
|
MeterScreenControlButtonView.swift
|
|
|
88
|
MeterScreenControlsView.swift
|
|
|
89
|
ScreenBrightnessEditorView.swift
|
|
|
90
|
ScreenTimeoutEditorView.swift
|
|
|
91
|
```
|
|
|
92
|
|
|
|
93
|
## Refactor Examples
|
|
|
94
|
|
|
|
95
|
- `Connection/` -> `Home/`
|
|
|
96
|
- `MeterConnectionTabView` -> `MeterHomeTabView`
|
|
|
97
|
- `ConnectionHomeInfoPreviewView` -> `MeterOverviewSectionView`
|
|
|
98
|
- `ConnectionPrimaryActionView` -> `MeterConnectionActionView`
|
|
|
99
|
- `EditNameView` -> `MeterNameEditorView`
|
|
|
100
|
- `MeasurementsView` -> `AppHistorySheetView`
|
|
|
101
|
- `RecordingView` -> `ChargeRecordSheetView`
|
|
|
102
|
- `ControlView` -> `MeterScreenControlsView`
|
|
|
103
|
|
|
|
104
|
## Decision Rule
|
|
|
105
|
|
|
|
106
|
If a new name makes a teammate look in the right folder on the first try, it is probably a good name.
|