# Spectra

An iPhone storage assistant: it tells you which photos are safe to delete, and why, with on-device AI through Firebase AI Logic hybrid inference. Not one photo is uploaded

**Status:** completed · **Timeline:** November 2026 · **Role:** Creator · **Team:** Solo

**Technologies:** Swift, SwiftUI, iOS 26, Firebase AI Logic, Apple Foundation Models, Gemini, Firebase App Check, Vision, Core ML (CLIP), WidgetKit, App Intents, Next.js 16, Vercel

[GitHub](https://github.com/MohitGoyal09/spectra) · [Live](https://spectra.mohitx.in)

---

# Spectra: know which photos can go, and why

## Overview

Spectra is a storage assistant for the iPhone. It reads the photo library on the phone and gives every photo a reason: keep it, lock it, or let it go. It splits real photos from clutter (duplicates, WhatsApp forwards, expired OTP and payment screenshots, big videos, AI-made images), then frees space only after you review and slide to confirm.

I built it solo for **#BuildHybridAI 2026**, around **Firebase AI Logic hybrid inference**: Apple's on-device model does the AI work, and Gemini is a fallback that only ever receives masked text, with your consent. Not one photo is uploaded.

<video controls playsInline preload="metadata" poster="/project/spectra.webp" src="https://spectra.mohitx.in/media/film.mp4" style={{ width: '100%', borderRadius: '0.5rem' }}></video>

*The 90-second launch film. Every screen in it is the real app on an iPhone, running on a demo library.*

## Why I built this

Apple Photos can find your duplicates. It cannot tell you what is safe to delete. A full iPhone is mostly not memories: it is old screenshots of OTPs, forwarded good-morning images, the same photo three times and a few huge videos. People know this, but going through thousands of photos one by one is the job nobody does.

Cloud clean-up apps solve it by uploading your library. For photos that include IDs, bank screenshots and family pictures, that is the wrong trade. So the rule for Spectra was simple: the photos stay on the phone, and the app must explain every pick.

## What it does

| Feature            | What happens                                                                                                                                       |
| ------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------- |
| Sort the roll      | Real photos, duplicates, blurry shots, forwards, expired OTP and payment screenshots, receipts, IDs, big videos and AI-made images, each with a plain reason. |
| Get me space       | Pick a target such as 1 GB. Spectra builds a plan from the least risky items, you review it, then slide to confirm. Real photos, favourites and IDs are never pre-selected. |
| Ask your photos    | "What's the Wi-Fi password?" Spectra finds the screenshot, answers on the iPhone and shows the photo the answer came from.                          |
| Search by meaning  | "dog at the beach", "receipts from Swiggy", "Goa trip": words, what is in the picture, and dates.                                                    |
| Albums from a sentence | "Bills and receipts go to Tax 2026" becomes a real Photos album that keeps itself up to date.                                                  |
| Lock IDs           | Aadhaar, PAN, cards and passports are found with checksums and moved to the Hidden album. Their text never reaches any model.                       |
| Everywhere on iOS  | A full gallery, a home-screen widget, Siri and Shortcuts, a weekly digest, light and dark mode, VoiceOver and Dynamic Type.                          |

## Results

- One demo run: **322 photos** sorted into seven folders, **287 real photos** kept, **1.11 GB** freed in one slide, **0 photos** uploaded.
- The scan sorts about **500 photos in 63 seconds** on an iPhone 17, all on the phone.
- **164 automated tests**: 107 core tests, 39 app tests on a real iPhone (including the real on-device model and a real Gemini call) and 18 UI flows.

## How the hybrid AI works

```mermaid
flowchart LR
    P["Photo"] --> V["Vision on iPhone: text, labels, faces, blur"]
    V --> R["Rules on iPhone: keep / review / junk"]
    R --> FAL{"Firebase AI Logic hybrid session"}
    FAL -->|"primary"| OD["Apple Foundation Model, on device"]
    FAL -->|"fallback, with consent"| G["Gemini: masked text only"]
    OD --> UI["Titles, saved info, album rules, answers"]
    G --> UI
    G -.->|"logged"| L["Privacy log"]
```

Every structured AI call goes through one Firebase AI Logic session with a hybrid model: Apple's system model first, Gemini second. Guided generation (`@Generable` types) means the output always fits the app's own types, from a smart-album rule to the answer to a question.

## Engineering decisions

### The AI explains; rules decide

Every keep, review or junk call comes from deterministic rules on the phone, not from a model. That makes the result predictable, fast and testable, and it means no model can ever delete a photo. The model's job is the language around the decision: titles, the reason you read, saved info such as bookings and addresses, album rules from a sentence and answers to questions.

### On-device first, the cloud only with consent

On an iPhone with Apple Intelligence, everything runs on the phone. Without it, Spectra asks before it uses Gemini. Every AI answer carries a badge, *On this iPhone* or *Gemini · masked text*, so you always know where it was made.

### Mask before anything leaves

Numbers, emails, phone numbers and UPI IDs are masked on the phone before a request can leave it. ID photos and the text read from photos for Ask never go to the cloud. Each cloud request appears in a privacy log with the exact text that was sent. A demo switch simulates an iPhone without Apple Intelligence, so the fallback and the masking can be seen working.

### IDs by checksum, not by guess

An Aadhaar or PAN number is found with its real format and checksum, so a random 12-digit number is not flagged and a real ID is not missed. IDs are locked in the Hidden album and never shown to a model.

### Freeing space without regret

"Get me space" ranks items by risk, starts with the safest, and never pre-selects real photos, favourites or IDs. A slide to confirm replaces a delete button, and big videos can be re-saved in HD instead of deleted.

### Picture search on the phone

An on-device image-text model (OpenAI CLIP ViT-B/32, converted to Core ML) indexes what photos look like, so search works by meaning without uploading a pixel. Vision and CLIP only turn pixels into searchable data; every generative step goes through Firebase AI Logic, protected by App Check.

## The launch

I also made the [landing page](https://spectra.mohitx.in) (Next.js 16, static export on Vercel, Lighthouse 98 to 100 on mobile) and the 90-second launch film, built frame by frame in code with a voiceover and music mixed to streaming loudness.

## Access

Spectra is open source under Apache-2.0. [Download the .ipa](https://github.com/MohitGoyal09/spectra/releases/latest/download/Spectra.ipa) for iOS 26 and install it with AltStore or Sideloadly, or build it with Xcode from [GitHub](https://github.com/MohitGoyal09/spectra).