kvn8888/OpenFoodJournal / .claude/skills/openfoodjournal
openfoodjournal
VerifiedLiving project knowledge for OpenFoodJournal — an iOS 26 food journaling app with AI-powered nutrition scanning. Consult this skill FIRST when starting any work on this project. Contains architecture decisions, data models, service contracts, current state, known issues, and conventions. Update this skill whenever requirements, architecture, or project state changes so it stays accurate across sessions.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 29.8 KB |
| references/models.md | markdown | 2.5 KB |
| references/services.md | markdown | 2.7 KB |
| references/views.md | markdown | 3.5 KB |
references/services.md
View on GitHub# Services Reference
## NutritionStore (`OpenFoodJournal/Services/NutritionStore.swift`)
`@Observable @MainActor` — SwiftData persistence layer.
**Init**: Takes `ModelContext` from the app's `ModelContainer`.
| Method | Signature | Notes |
|--------|-----------|-------|
| `log` | `func log(_ entry: NutritionEntry, to date: Date)` | Inserts entry, appends to DailyLog (creates if needed) |
| `fetchLog` | `func fetchLog(for date: Date) -> DailyLog?` | Matches by startOfDay |
| `fetchLogs` | `func fetchLogs(from: Date, to: Date) -> [DailyLog]` | Sorted reverse chronological |
| `fetchAllLogs` | `func fetchAllLogs() -> [DailyLog]` | All logs |
| `delete` | `func delete(_ entry: NutritionEntry)` | Removes from context |
| `delete` | `func delete(_ log: DailyLog)` | Cascade deletes entries |
| `exportCSV` | `func exportCSV() -> String` | Columns: Date,Meal,Name,ScanMode,Confidence,Cal,P,C,F,Fiber,Sugar,Sodium |
| `saveChanges` | `func saveChanges()` | Public save for edit flows |
## ScanService (`OpenFoodJournal/Services/ScanService.swift`)
`@Observable @MainActor` — Gemini Vision API client.
**Config**:
- Proxy URL from `Bundle.main` key `RENDER_PROXY_URL`, fallback: `https://macros-proxy.onrender.com`
- URLSession: 30s request timeout, 60s resource timeout
**API**:
```swift
func scan(image: UIImage, mode: ScanMode) async throws -> NutritionEntry
```
- Builds multipart/form-data with JPEG (0.85 quality) + mode string
- POSTs to `/scan` endpoint
- Parses `GeminiNutritionResponse` (Codable) into `NutritionEntry`
- Does NOT insert into SwiftData — caller reviews first
**Error enum**: `ScanError` — `imageEncodingFailed`, `networkError(Error)`, `invalidResponse`, `serverError(Int, String)`, `decodingError(Error)`
## HealthKitService (`OpenFoodJournal/Services/HealthKitService.swift`)
`@Observable @MainActor` — Apple Health integration.
**Write types**: dietaryEnergyConsumed, dietaryProtein, dietaryCarbohydrates, dietaryFatTotal, dietaryFiber, dietarySugar, dietarySodium, dietaryCholesterol
**Read types**: activeEnergyBurned
| Method | Signature | Notes |
|--------|-----------|-------|
| `requestAuthorization` | `func requestAuthorization() async` | System permission dialog |
| `write` | `func write(_ entry: NutritionEntry) async` | One HKQuantitySample per macro, metadata: FoodType = entry.name |
| `fetchActiveEnergy` | `func fetchActiveEnergy(for date: Date) async -> Double` | kcal burned that day |
**Opt-in**: Controlled by `@AppStorage("healthkit.enabled")` in SettingsView. Auth restored on app launch if flag is true.
## UserGoals (`OpenFoodJournal/Models/UserGoals.swift`)
Not a "service" per se, but injected the same way. Holds daily macro targets in `@AppStorage`. See [models.md](models.md).
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness. | Stars: 323k | Updated | Claude CodeCodex | Verified | Install |
| dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies | Stars: 323k | Updated | Claude CodeCodex | Verified | Install |
| executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available | Stars: 323k | Updated | Claude CodeCodex | Verified | Install |