Inspiration

A small freight forwarder, a pack-and-ship store, a mailbox shop: a few people and no back office. Every parcel that comes in raises two kinds of work:

  • right now: whose is it, is it damaged, does it carry a lithium battery, and where does it go?
  • later: what is inside, what is its harmonized (HS) code, how must it be packed, and which paperwork does this shipment need?

The first has to be fast and private: the label carries a customer's name and address. The second needs a strong model, and nobody should wait for it at the counter.

What it does

1 · Receiving station (on device only). A camera sits above the receiving table.

  • Frame 1, the label: read on the device through Firebase AI Logic's on-device path (text recognition + the on-device model, typed output): customer, carrier, tracking, weight. It never leaves the device.
  • Frame 2, the parcel: the on-device model looks at the photo and classifies it: fine, visibly damaged, or carrying a lithium battery mark (a UN number read on the box counts whatever the model says). Measured on the phone: 12 of 12 looks right over four runs of three example parcels, 2.4–3.6 s each. The photo is saved with the receipt.
  • Location: the same on-device model picks the zone from those facts. Code keeps hard limits (unknown customer → hold, damaged → damage cage, lithium battery → dangerous goods area, 50 lb or more → floor) and takes the free cell from live Firestore inventory.

2 · Shipment prep (cloud, in the background). As soon as a parcel is put away, the app prepares that customer's shipment in the background, so it is ready before anyone picks it. (The app makes these calls itself while it is open and online; there is no server. The label is never sent.)

  • Gemini reads each saved contents photo through Firebase AI Logic (multimodal, JSON schema): the goods, the quantity, the condition, and whether they can go to that country.
  • Harmonized code: BM25 on the device retrieves 10 passages from 22,729 U.S. CBP ruling subjects in about 25 ms. Gemini must pick from those passages and cite the rulings; a pick that was not retrieved is rejected. The declaration carries the international 6-digit code.
  • Shipment checklist: Gemini builds the list of what must be done before this shipment leaves (how to pack each parcel, the lithium battery mark, the documents, the filing) from contents, destination and customs facts. The app adds any item the facts make mandatory if the model left it out. The worker ticks it off; ticks are saved in Firestore.
  • Documents: the app fills in a commercial invoice, a packing list (how to pack each parcel, which labels), a customs declaration and an export filing check, laid out as forms. Value, origin and signature are left for the shipper.
  • Lithium batteries: for a parcel with lithium batteries Gemini drafts a dangerous goods sheet: UN number, how it is shipped, packing, the marks needed, limits and the rules relied on. Marks and rules are limited to a fixed list in the app (49 CFR 173.185, IATA packing instructions 965–970), so it cannot invent a section number; every item is marked for the shipper to confirm.
  • Export filing: a line worth more than USD 2,500 needs Electronic Export Information filed in AES. That rule is in code; Gemini then prepares the filing (codes, origin, the rule, what to check). The form is ready to file with the ITN left blank. FireDock does not file with AES.
  • Print: one tap prints them on the warehouse network (AirPrint, no internet needed), or queues them in Firestore for the print station, a web page any computer on the warehouse network can keep open.
  • Then the shipment is picked and the receipts are marked shipped.

How we built it (Firebase)

  • Firebase AI Logic:
    • Gemini with image input and structured output (package assessment, HS pick, placement, pick path, claim draft)
    • on-device inference for label reading and for the fallback
  • App Check (enforced) and Anonymous Auth: only the real app reaches Gemini.
  • Firestore: receipts, photos and inventory, with security rules and offline writes that sync later.
  • Stack: SwiftUI on iPhone, Kotlin on Android, a JavaScript web app on Firebase Hosting. The HS index is bundled in the app (hts_rag.json).

Measured on an iPhone, real items (Nov 28 and 29 2026)

Step Path Time
Label read on device 2.5–4.5 s
Location pick on device 1.2–1.4 s
Parcel at the station, label to stored on device 9–13 s
Parcel look: damage / lithium battery (Nov 29) on device 2.4–3.6 s
Contents photo Gemini 2.1–3.6 s
HS retrieval on device 24–27 ms
HS pick Gemini 1.1–14.7 s (slow runs triggered a second, hedged request)
Shipment of 2 parcels, prep Gemini 7–29 s
Shipment checklist, 7 items (Nov 29) Gemini 1.9–2.1 s
Dangerous goods sheet (Nov 29) Gemini 1.4–9.6 s
Export filing prepared (Nov 29) Gemini 1.1 s

Challenges

  • The on-device model made a wrong call. It sent an 11.9 lb parcel to the large-box floor. Weight became a hard limit in code; the model chooses only inside the limits.
  • A model should not decide a legal threshold. We first let Gemini decide whether an export filing was needed; at USD 2,400 it said yes. The threshold went back into code, and the model prepares the filing instead.
  • Grounding. A free-form HS guess is not good enough for customs. Retrieval plus the reject rule replaced it.
  • Privacy. The label is the one thing with a name and address on it, so on the phones it is the one thing no cloud model ever sees.

Three platforms, one warehouse

FireDock runs as an iPhone app, an Android app and a web app on the same Firestore data and the same Firebase AI Logic calls. Measured on Nov 29: on a moto g 5G (Android 13) a full shift ran on the phone, with labels read on the device in 0.2 to 0.8 s and no cloud call at receiving; a box with a UN3481 lithium mark went to dangerous goods from the text read on the box; the checklist (2.0 s), the dangerous-goods sheet (2.3 s) and the export filing (2.8 s) came from Gemini. That phone has no on-device model, so visible damage is the worker's call there. In Chrome on a desktop the web app did receiving, stock, shipment prep, the checklist and the documents against the live project. The hosted web app works from sample photos with the camera off; the label is read on the device only in a Chrome that has the built-in model, and in a browser without one it is read by Gemini and the page marks it "Cloud".

What's next

A fixed camera with automatic frame capture, carrier label printing, destination duty estimates, and filing the prepared export form in the shipper's own ACE account. On Android: a phone with Gemini Nano, so the parcel look runs on the device there too.

Built With

  • app-check
  • firebase-ai-logic
  • firebase-auth
  • firebase-hosting
  • firestore
  • foundation-models
  • gemini
  • javascript
  • kotlin
  • swift
  • swiftui
Share this project:

Updates

Submission history