Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,17 @@ jobs:
with:
name: FoodSense-${{ runner.os }}-${{ runner.arch }}
path: target/FoodSense.jar

build:
name: Build
needs: [test-and-build]
runs-on: ubuntu-latest
if: always()
steps:
- name: Verify matrix status
run: |
if [ "${{ contains(needs.test-and-build.result, 'failure') || contains(needs.test-and-build.result, 'cancelled') || contains(needs.test-and-build.result, 'skipped') }}" = "true" ]; then
echo "Matrix test-and-build failed or was not successful: ${{ toJson(needs.test-and-build) }}"
exit 1
fi
echo "All matrix test-and-build runs passed successfully"
36 changes: 29 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ jobs:
runs-on: ${{ matrix.os }}
permissions:
contents: write
id-token: write
attestations: write
steps:
- uses: actions/checkout@v4

Expand All @@ -22,19 +24,39 @@ jobs:
distribution: 'temurin'
cache: maven

- name: Build Fat JAR
shell: bash
run: mvn -Djavacpp.platform.host --batch-mode clean package -DskipTests
- name: Build Fat JAR (Linux Headless)
if: runner.os == 'Linux'
run: |
sudo apt-get install -y xvfb
xvfb-run mvn -Djavacpp.platform.host --batch-mode clean package

- name: Print Output Size
- name: Build Fat JAR (Mac/Windows)
if: runner.os != 'Linux'
shell: bash
run: ls -lh target/FoodSense.jar
run: mvn -Djavacpp.platform.host --batch-mode clean package

- name: Rename OS/Arch-specific Artifact
shell: bash
run: mv target/FoodSense.jar target/FoodSense-${{ runner.os }}-${{ runner.arch }}.jar

- name: Upload Artifact to Release
- name: Generate SHA-256 Checksum
shell: bash
run: |
cd target
if command -v sha256sum >/dev/null 2>&1; then
sha256sum FoodSense-${{ runner.os }}-${{ runner.arch }}.jar > FoodSense-${{ runner.os }}-${{ runner.arch }}.jar.sha256
else
shasum -a 256 FoodSense-${{ runner.os }}-${{ runner.arch }}.jar > FoodSense-${{ runner.os }}-${{ runner.arch }}.jar.sha256
fi

- name: Attest Build Provenance
uses: actions/attest-build-provenance@ef244123eb79f2f7a7e75d99086184180e6d0018 # v1
with:
subject-path: target/FoodSense-${{ runner.os }}-${{ runner.arch }}.jar

- name: Upload Artifacts to Release
uses: softprops/action-gh-release@v2
with:
files: target/FoodSense-${{ runner.os }}-${{ runner.arch }}.jar
files: |
target/FoodSense-${{ runner.os }}-${{ runner.arch }}.jar
target/FoodSense-${{ runner.os }}-${{ runner.arch }}.jar.sha256
86 changes: 54 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
# FoodSense

FoodSense is a Java desktop application that scans barcodes to display nutrition data, ingredients, and Nutri-Score ratings via the Open Food Facts API.
FoodSense is a modern Java desktop application that scans grocery barcodes to display nutrition data, ingredients, allergen warnings, and official Nutri-Score ratings via the Open Food Facts API.

## Features

- Live webcam scanning for real-time barcode detection
- Manual barcode entry for quick lookups
- Auto-generated nutrition facts grid
- Nutri-Score and product image display
- Full ingredient breakdown
- **In-App Live Webcam Scanner:** Built-in modal dialog with illuminated corner reticles, animated scan guide, and automatic barcode detection.
- **Modern Adaptive Theme:** Sleek desktop interface built with FlatLaf, supporting instant Light and Dark mode toggling via an icon button.
- **Nutri-Score Spectrum Bar:** Displays the recognized European 5-pill indicator (A–E) with the active grade elevated and highlighted.
- **Nutrition Facts & Macro Visualizer:** Hero calorie callout, visual macronutrient distribution bar (Carbs, Fats, Protein), and per-100g nutrient table.
- **Allergen Alert Banners:** Highlighted alert cards parsing allergens with clear warning iconography.
- **Hardened Security & Input Validation:** Strict barcode sanitization, Swing HTML injection defenses, bounded async image loading, and SSRF prevention.
- **Headless CLI Mode:** Fast barcode query via `--barcode <code>` / `-b <code>` for headless terminal use without initializing GUI components.

## Tech Stack

- **Java 25 / Swing:** Core application and GUI
- **Java 25 / Swing:** Core desktop application and GUI
- **FlatLaf:** Modern cross-platform Look and Feel with Retina HiDPI scaling
- **JavaCV (OpenCV):** Webcam capture and computer vision
- **ZXing:** Barcode decoding
- **Gson:** JSON parsing
- **Gson:** JSON deserialization

## Deployment & Execution

You can run FoodSense directly without building from source. Download the `.jar` file for your operating system from the [Releases](https://github.com/SamuelIVX/FoodSense/releases) page.
Prebuilt platform-specific JARs are published on the [Releases](https://github.com/SamuelIVX/FoodSense/releases) page for macOS (Apple Silicon ARM64), Windows (x64), and Linux (x64).

Requires **Java 25+** installed on your system.

Expand All @@ -28,21 +31,39 @@ java -jar FoodSense-macOS-ARM64.jar
# or FoodSense-Windows-X64.jar / FoodSense-Linux-X64.jar
```

*Note for macOS users:* The latest releases are built for Apple Silicon (ARM64). When launching via terminal, ensure your terminal application (Terminal.app, iTerm) has Camera permissions granted in `System Settings > Privacy & Security > Camera` for live barcode scanning to function.
### Release Verification

## Building from Source
Every release publishes cryptographic SHA-256 checksums and GitHub build provenance attestations. To verify your downloaded artifact integrity:

**macOS / Linux:**

```bash
shasum -a 256 -c FoodSense-macOS-ARM64.jar.sha256
gh attestation verify FoodSense-macOS-ARM64.jar --repo SamuelIVX/FoodSense
```

**Windows (PowerShell):**

```powershell
Get-FileHash .\FoodSense-Windows-X64.jar -Algorithm SHA256
gh attestation verify .\FoodSense-Windows-X64.jar --repo SamuelIVX/FoodSense
```
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

Compare the printed hash with the contents of `FoodSense-Windows-X64.jar.sha256`.

If you want to build the project yourself, clone the repository and use Maven.
*Note for macOS users:* When launching via terminal, ensure your terminal application (Terminal.app, iTerm) has Camera permissions granted in `System Settings > Privacy & Security > Camera` for live barcode scanning.

## Building from Source

```bash
git clone https://github.com/SamuelIVX/FoodSense.git
cd FoodSense
mvn clean package
```

The Maven build uses the `maven-shade-plugin` and `javacpp.platform.host` to pull native dependencies for your specific operating system.
The build produces a self-contained fat JAR in `target/` using `maven-shade-plugin`.

### Running locally
### Running Locally

Interactive GUI:
```bash
Expand All @@ -63,25 +84,26 @@ mvn compile exec:java -Dexec.mainClass="com.foodsense.FoodSense" -Dfoodsense.hos

```text
src/main/java/com/foodsense/
├── FoodSense.java # Main entry point (CLI springboard + GUI launcher)
├── ProductApiClient.java # API client and host resolver
├── FoodSenseGUI.java # Swing desktop renderer
├── VideoProcessor.java # Webcam capture and barcode detection
├── Product.java # Product data model
├── Nutriments.java # Nutrition data model
└── ApiResponse.java # API response wrapper
├── FoodSense.java # Main entry point (CLI springboard + GUI launcher)
├── ProductApiClient.java # API client and host resolver
├── FoodSenseGUI.java # Main desktop window & search orchestrator
├── VideoProcessor.java # Webcam capture & barcode detection pipeline
├── Product.java # Product data model
├── Nutriments.java # Nutrition data model
├── ApiResponse.java # API response wrapper
├── security/
│ ├── SecurityValidator.java # Barcode regex, HTML escaping, and HTTPS URL checks
│ └── SafeImageLoader.java # Bounded async image fetcher (5MB cap, timeouts)
└── ui/
├── FoodSenseTheme.java # Design tokens, palette scales, and Light/Dark toggle
├── CameraScanDialog.java # In-app modal camera scanner with viewfinder reticles
├── NutriScoreSpectrumView.java # 5-pill Nutri-Score spectrum (A-B-C-D-E)
├── NutritionLabelPanel.java # Nutrition card with hero calories & macro proportion bar
└── AllergenBanner.java # Danger alert card for allergen warnings
```

## Troubleshooting

**Camera Issues:**
Ensure no other applications are using the camera and check system permissions. Verify JavaCV native libraries match your OS.

**Barcode Not Detected:**
Check lighting, ensure the barcode is in focus, and make sure it is fully visible in the frame.

**Product Not Found:**
The product may not exist in the Open Food Facts database.

**Build Errors:**
Confirm JDK 25 is installed (`java -version`). Run `mvn clean` and rebuild.
- **Camera Permissions:** Ensure your OS camera permissions allow the terminal or Java process to access video device 0.
- **Barcode Validation:** Barcodes must be 3–48 characters (letters, digits, hyphens, or underscores).
- **Product Not Found:** Products must be cataloged in Open Food Facts. Check the barcode on `world.openfoodfacts.org`.
9 changes: 7 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>25</maven.compiler.source>
<maven.compiler.target>25</maven.compiler.target>
<maven.compiler.release>25</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<interleave.exclude>**/VideoProcessorModelTest.java</interleave.exclude>
</properties>
Expand Down Expand Up @@ -51,6 +50,12 @@
<version>3.5.3</version>
</dependency>

<dependency>
<groupId>com.formdev</groupId>
<artifactId>flatlaf</artifactId>
<version>3.5.4</version>
</dependency>

<!-- Test Dependencies (JUnit 5) -->
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/com/foodsense/FoodSense.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ public static void main(String[] args) {
return;
}

FoodSenseGUI foodSenseGUI = new FoodSenseGUI();
foodSenseGUI.start();
javax.swing.SwingUtilities.invokeLater(() -> {
com.foodsense.ui.FoodSenseTheme.initialize();
FoodSenseGUI foodSenseGUI = new FoodSenseGUI();
foodSenseGUI.start();
});
}
}
Loading
Loading