PantryPal is a lightweight smart pantry tracker that logs grocery items, estimates their expiry dates, and surfaces what needs to be used soon — before it ends up in the trash. Built entirely on the Java 26 standard library, it showcases virtual threads, structured concurrency, sealed interfaces, and pattern matching in a real, everyday problem: reducing food waste at home.
-----------------------------------------------------------------------------------------------------------------
The ProblemFood waste is one of those "invisible" household problems. A bag of cookies gets pushed to the back of the pantry, milk quietly passes its best-by date, and canned goods get forgotten for years — until you're throwing away something you paid for and never actually used.
The information to prevent this already exists: it's printed right on the package, as a barcode. The problem is that nobody has time to manually log every item they buy into a spreadsheet, and spreadsheets don't remind you when something's about to expire anyway.
PantryPal closes that gap: point a camera at a barcode once, and the system takes care of the rest — identifying the product, estimating how long it'll stay fresh, and surfacing it the moment it needs attention.
-----------------------------------------------------------------------------------------------------------------
How It WorksThe physical flow is simple and camera-first:
1. Scan
hold a product's barcode up to a webcam connected to a Raspberry Pi.
2. Capture
The Pi decodes the barcode from the live camera feed in real time using a lightweight Python scanner script.
3. Lookup & log
The scanner sends the barcode to the PantryPal server (running on the same Pi), which looks up the product via the Open Food Facts database, estimates a shelf life for its category, and stores it.
4. Track
PantryPal continuously classifies every item as Fresh, Expiring Soon, or Expired, and the dashboard updates live to show what needs to be used first.
No app to install, no manual typing for barcoded items
just scan and walk away.
-----------------------------------------------------------------------------------------------------------------
System ArchitectureEverything server-side runs from a single Java process — no external database, no application server, no third-party dependencies. The whole thing builds and runs with nothing but a JDK 26 install.
Why Java 26?This project was as much about how it's built as what it does. Several modern Java features map naturally onto a pantry tracker's problem shape:
- Records (Product, PantryItem): both are naturally immutable value types once created, which records model perfectly — no boilerplate getters, clean equals/hashCode, and constructors that double as validation points.
- Virtual threads: the dashboard server and the HTTP client both run on virtual threads, so scanning a big grocery haul (dozens of barcode lookups) doesn't require any thread-pool tuning — the JVM handles thousands of concurrent lightweight threads transparently.
- StructuredTaskScope: when resolving a barcode, PantryPal races a local cache check against a network call to Open Food Facts as a single structured unit of work. Whichever finishes first (or the cache hit) wins, and the other subtask is automatically cancelled — no manual thread bookkeeping or leaked background calls.
- SequencedMap: the pantry's in-memory store uses SequencedMap to get cheap access to "what was added most recently" alongside normal keyed lookups, without maintaining a separate ordering structure.
- ----------------------------------------------------------------------------------------------------------------
The webcam connects to the Pi over USB. A lightweight Python script (raspberry-pi/scanner.py) continuously watches the camera feed, decodes barcodes with pyzbar, and POSTs each new scan straight to PantryPal's REST API running on the same Pi — no changes needed on the Java side to support this. Manual entry through the dashboard remains available as a fallback for items without a barcode. See raspberry-pi/README.md in the repository for full setup steps, including an optional systemd configuration so the whole station starts automatically whenever the Pi powers on.
-----------------------------------------------------------------------------------------------------------------
Getting Startedmvn clean package
java --enable-preview -jar target/pantrypal.jarThen open http://localhost:8080/ in a browser. The app seeds a few demo items on first launch so the dashboard isn't empty.
see the video on my tiktok https://www.tiktok.com/@kogamakerspace
Challenges & What I'd Improve NextThe barcode-to-product lookup currently uses lightweight regex parsing to stay dependency-free; a production version would use a proper JSON library. Shelf-life estimates are category-based heuristics rather than exact expiry dates — a nice next step would be OCR on printed expiry dates. Data is in-memory only right now; persisting to a lightweight embedded database would let the pantry survive a restart. A recipe-suggestion feature could use the needsAttention() list to recommend recipes that use up items before they expire.
-----------------------------------------------------------------------------------------------------------------
ConclusionPantryPal is a small project, but it's a good showcase of how Java's modern features — sealed types, pattern matching, virtual threads, and structured concurrency — make everyday concurrent, stateful problems easier to model correctly and read clearly, without reaching for a big framework.
![[PantryPal] Smart Pantry Tracker Built with Modern Java](https://prod.hackster-cdn.online/assets/transparent-a0c1e3063bcabc548a5f3fa7328f3c1c97f747e6e764da4c14439567baa79ae1.gif)









Comments