|
| 1 | +# Anytype iOS app |
| 2 | + |
| 3 | +## Overview |
| 4 | +Anytype is a privacy-focused, local-first workspace application for iOS. Built with Swift and SwiftUI, it provides users with a secure environment for creating and organizing their digital content including notes, tasks, and documents. The app uses a custom middleware for data synchronization and storage. |
| 5 | + |
| 6 | +## Development Setup |
| 7 | +- Run `make setup-middle` for initial dependency setup |
| 8 | +- If Dependencies/Middleware/Lib.xcframework is missing binaries, try `make generate-middle` |
| 9 | +- Use Xcode 16.1 or later for development |
| 10 | +- The project uses Swift Package Manager for dependency management |
| 11 | + |
| 12 | +## Building and Testing |
| 13 | +- **For compilation check**: Use "Build for Testing" (`Cmd+Shift+U`) instead of normal build |
| 14 | +- **Normal build**: `xcodebuild -scheme Anytype -configuration Debug -destination 'platform=iOS Simulator,name=iPhone 15' build` |
| 15 | + |
| 16 | +## Important Guidelines |
| 17 | + |
| 18 | +### Generated Files |
| 19 | +- **Never edit files marked with `// Generated using Sourcery/SwiftGen`** |
| 20 | +- These files are automatically generated and will be overwritten |
| 21 | + |
| 22 | +### Localization |
| 23 | +- To change localization constants (e.g., `Loc.constantName` or `Loc.Group.constantName`): |
| 24 | + 1. Edit `Localizable.xcstrings` file |
| 25 | + 2. Run `make generate-middle` to regenerate constants |
| 26 | + 3. The generated Loc constants will be updated automatically |
| 27 | + |
| 28 | +## Code Style Guidelines |
| 29 | + |
| 30 | +### Formatting |
| 31 | +- Use 4 spaces for indentation (no tabs) |
| 32 | +- Opening brackets on same line (K&R style) |
| 33 | +- Keep lines under 120-140 characters |
| 34 | +- One blank line between functions, two between major sections |
| 35 | + |
| 36 | +### Naming Conventions |
| 37 | +- Classes/Structs/Protocols: PascalCase (e.g., `ChatViewModel`, `BlockActionService`) |
| 38 | +- Variables/Functions: camelCase (e.g., `objectDetails`, `updateRows()`) |
| 39 | +- Protocols often suffixed with `Protocol` (e.g., `BlockActionServiceProtocol`) |
| 40 | +- Extensions: `TypeName+Feature.swift` (e.g., `RelationDetails+Extensions.swift`) |
| 41 | + |
| 42 | +### Swift Patterns |
| 43 | +- Prefer `guard` for early returns over nested `if` statements |
| 44 | +- Use `@MainActor` for UI-related classes and methods |
| 45 | +- Place imports at top: system frameworks first, then third-party, then internal modules |
| 46 | + |
| 47 | +### Property Organization |
| 48 | +1. @Published/@Injected properties grouped together |
| 49 | +2. Public properties before private |
| 50 | +3. Constants before variables |
| 51 | +4. Properties before methods |
| 52 | + |
| 53 | +### Modern Swift Features |
| 54 | +- Use async/await for asynchronous code |
| 55 | +- Leverage SwiftUI property wrappers (@State, @StateObject, @Published) |
| 56 | +- Use trailing closures for last closure parameters |
| 57 | +- Type inference where obvious, explicit types for clarity |
| 58 | + |
| 59 | +## Architecture |
| 60 | + |
| 61 | +### Key Technologies |
| 62 | +- **Swift & SwiftUI**: Primary development language and UI framework |
| 63 | +- **Combine**: For reactive programming and data binding |
| 64 | +- **Factory**: Dependency injection framework |
| 65 | +- **Middleware**: Custom binary framework for core functionality |
| 66 | +- **Protobuf**: For communication with the middleware |
| 67 | + |
| 68 | +### Project Structure |
| 69 | +``` |
| 70 | +Anytype/ |
| 71 | +├── Sources/ |
| 72 | +│ ├── ApplicationLayer/ # App lifecycle, coordinators, global state |
| 73 | +│ ├── PresentationLayer/ # UI components, ViewModels, flows |
| 74 | +│ ├── ServiceLayer/ # Business logic, data services |
| 75 | +│ ├── Models/ # Data models, entities |
| 76 | +│ ├── CoreLayer/ # Core utilities, networking |
| 77 | +│ └── Design system/ # Reusable UI components, themes |
| 78 | +├── Modules/ # Swift packages (internal frameworks) |
| 79 | +│ ├── Services/ # Core services package |
| 80 | +│ ├── AnytypeCore/ # Core utilities package |
| 81 | +│ ├── ProtobufMessages/ # Generated protobuf code |
| 82 | +│ └── ... |
| 83 | +├── Dependencies/ |
| 84 | +│ └── Middleware/ # Binary framework for core functionality |
| 85 | +└── AnyTypeTests/ # Unit and integration tests |
| 86 | +``` |
| 87 | + |
| 88 | +### Dependency Injection |
| 89 | +The project uses Factory for dependency injection. Services are registered in: |
| 90 | +- `Anytype/Sources/ServiceLayer/ServicesDI.swift` |
| 91 | +- `Modules/Services/Sources/ServicesDI.swift` |
| 92 | + |
| 93 | +### Key Patterns |
| 94 | +- **MVVM Architecture**: ViewModels handle business logic for SwiftUI views |
| 95 | +- **Coordinator Pattern**: Navigation is handled by coordinator objects |
| 96 | +- **Repository Pattern**: Data access is abstracted through service layers |
| 97 | +- **Protocol-Oriented Programming**: Heavy use of protocols for testability |
| 98 | + |
| 99 | +### Data Flow |
| 100 | +1. **Middleware Layer**: Handles data persistence and synchronization |
| 101 | +2. **Service Layer**: Provides high-level APIs for data operations |
| 102 | +3. **ViewModels**: Transform data for presentation |
| 103 | +4. **Views**: SwiftUI views display the data |
| 104 | + |
| 105 | +## Common Tasks |
| 106 | + |
| 107 | +### Adding a New Feature |
| 108 | +1. Create models in `Models/` if needed |
| 109 | +2. Add service layer logic in `ServiceLayer/` |
| 110 | +3. Create ViewModel in appropriate `PresentationLayer/` subdirectory |
| 111 | +4. Build UI components using SwiftUI |
| 112 | +5. Add tests in `AnyTypeTests/` |
| 113 | + |
| 114 | +### Working with Middleware |
| 115 | +- The middleware is a pre-compiled binary framework |
| 116 | +- Communication happens through Protobuf messages |
| 117 | +- See `Modules/ProtobufMessages/` for message definitions |
| 118 | + |
| 119 | +## Git Workflow |
| 120 | +- Main branch: `develop` |
| 121 | +- Feature branches: `ios-XXXX-description` |
| 122 | +- Always create pull requests for code review |
| 123 | +- Run tests before pushing changes |
| 124 | + |
| 125 | +## Useful Commands |
| 126 | +- `make setup-middle` - Initial setup |
| 127 | +- `make generate-middle` - Regenerate middleware and generated files |
0 commit comments