|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Commands |
| 6 | + |
| 7 | +**Build:** |
| 8 | +```bash |
| 9 | +swift build |
| 10 | +``` |
| 11 | + |
| 12 | +**Run tests:** |
| 13 | +```bash |
| 14 | +swift test |
| 15 | +``` |
| 16 | + |
| 17 | +**Run specific test:** |
| 18 | +```bash |
| 19 | +swift test --filter "testName" |
| 20 | +``` |
| 21 | + |
| 22 | +**Run tests with code coverage:** |
| 23 | +```bash |
| 24 | +swift test --enable-code-coverage |
| 25 | +``` |
| 26 | + |
| 27 | +**Build in verbose mode:** |
| 28 | +```bash |
| 29 | +swift build -v |
| 30 | +``` |
| 31 | + |
| 32 | +## Architecture |
| 33 | + |
| 34 | +MattermostKit is a Swift 6 package for sending messages to Mattermost via Incoming Webhooks. The architecture follows a protocol-based design for testability and uses Swift 6 strict concurrency throughout. |
| 35 | + |
| 36 | +### Core Design |
| 37 | + |
| 38 | +- **Actor-based client**: `MattermostWebhookClient` is an `actor` for thread-safe async operations |
| 39 | +- **Protocol abstraction**: `NetworkClient` protocol enables dependency injection for testing |
| 40 | +- **Slack-compatible**: Uses the same attachment schema as Slack for compatibility |
| 41 | +- **Mattermost-specific**: Supports `Props.card` (sidebar content) and `Priority` (urgent/important) |
| 42 | + |
| 43 | +### Key Differences from Slack |
| 44 | + |
| 45 | +Mattermost webhooks **do not support** Slack's Block Kit. Only use: |
| 46 | +- Markdown text in the `text` field |
| 47 | +- Slack-compatible `attachments` array |
| 48 | +- Mattermost-specific `props.card` and `priority` |
| 49 | + |
| 50 | +### Module Structure |
| 51 | + |
| 52 | +**Client Layer** (`Sources/MattermostKit/Client/`): |
| 53 | +- `MattermostWebhookClient` - Main actor that encodes and sends messages |
| 54 | +- `NetworkClient` protocol - Abstraction for HTTP POST operations |
| 55 | +- `URLSessionNetworkClient` - Default URLSession-based implementation |
| 56 | + |
| 57 | +**Models** (`Sources/MattermostKit/Models/`): |
| 58 | +- `Message` - Core message with `text`, `username`, `iconEmoji`, `attachments`, `props`, `priority` |
| 59 | +- `Attachment` - Slack-compatible attachments with fields, colors, actions |
| 60 | +- `Props` - Mattermost metadata (primarily `card` for RHS sidebar) |
| 61 | +- `Priority` - Message priority levels (`.urgent`, `.important`) |
| 62 | + |
| 63 | +**Error Handling** (`Sources/MattermostKit/Errors/`): |
| 64 | +- `MattermostError` enum covers: `invalidURL`, `networkError`, `invalidResponse`, `encodingError`, `invalidMessage` |
| 65 | +- Note: No `rateLimitExceeded` (not applicable to Mattermost webhooks) |
| 66 | + |
| 67 | +### Testing |
| 68 | + |
| 69 | +Tests use `MockNetworkClient` actor (`Tests/MattermostKitTests/MockNetworkClient.swift`) which: |
| 70 | +- Captures all requests for verification |
| 71 | +- Queues predefined responses or errors |
| 72 | +- Implements `NetworkClient` protocol |
| 73 | + |
| 74 | +### Codable Patterns |
| 75 | + |
| 76 | +All models use `CodingKeys` to convert camelCase Swift properties to snake_case API fields (e.g., `iconEmoji` → `icon_emoji`). |
| 77 | + |
| 78 | +## Platform Requirements |
| 79 | + |
| 80 | +- macOS 12.0+, iOS 15.0+, tvOS 15.0+, watchOS 8.0+ |
| 81 | +- Swift 6.2+ |
| 82 | +- Zero external dependencies |
0 commit comments