Skip to content

Commit 6977c37

Browse files
author
Vanshika
committed
Final project files and clean structure committed
1 parent 913cb39 commit 6977c37

File tree

32,313 files changed

+4293591
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

32,313 files changed

+4293591
-0
lines changed

.DS_Store

6 KB
Binary file not shown.

App.css

Whitespace-only changes.

App.js

Whitespace-only changes.

App.test.js

Whitespace-only changes.

README.md

Lines changed: 303 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,303 @@
1+
# Sustainable Food Tracker - EcoBite
2+
3+
A web-based application that helps users make informed food choices by providing sustainability and nutrition insights. Scan or search for products to discover their nutritional value and environmental impact.
4+
5+
## Features
6+
7+
### 🔍 Search & Scanner
8+
- **Text Search**: Enter product name or barcode to search
9+
- **Barcode Scanner**: Live camera scanning using QuaggaJS
10+
- **Auto-fetch**: Automatically fetches product data on successful scan
11+
12+
### 📊 Product Insights
13+
- **Product Information**: Name, image, brand
14+
- **NutriScore**: A-E rating for nutritional quality (color-coded)
15+
- **EcoScore**: A-E rating for environmental impact
16+
- **CO₂ Impact**: Carbon footprint in g or kg
17+
- **Ingredients**: Complete ingredients list
18+
- **Additives**: List of additives detected
19+
- **Nutrition Facts**: Detailed nutritional table (per 100g)
20+
- Calories
21+
- Proteins
22+
- Carbohydrates
23+
- Fats
24+
- Sugars
25+
- Salt
26+
- Fiber
27+
- Saturated Fat
28+
29+
### 📈 Data Visualization
30+
- **Nutrition Chart**: Interactive bar chart using Chart.js comparing all nutritional values
31+
32+
### 📜 History Tracking
33+
- Stores scan/search history in localStorage
34+
- Tracks: name, image, NutriScore, EcoScore, timestamp
35+
- Clickable history items to view products again
36+
- Clear history functionality
37+
38+
### 🎮 Gamification (Eco-Points)
39+
- **Points System**:
40+
- NutriScore A/B + EcoScore A/B → +5 points
41+
- Grade C → +2 points
42+
- Grade D/E → 0 points
43+
- **Level System**: Every 100 points = 1 level
44+
- **Profile Page**: Shows total points, level, progress bar, and recent activity
45+
46+
### 📱 Pages
47+
1. **Home** (`index.html`): Search and scanner interface
48+
2. **Product** (`product.html`): Detailed product information
49+
3. **History** (`history.html`): View scan history
50+
4. **Profile** (`profile.html`): Eco-points, level, and activity
51+
52+
## Tech Stack
53+
54+
- **HTML5**: Structure
55+
- **CSS3**: Styling with CSS variables, responsive design
56+
- **JavaScript (Vanilla)**: Application logic
57+
- **OpenFoodFacts API**: Product data source
58+
- **Chart.js**: Data visualization
59+
- **QuaggaJS**: Barcode scanning
60+
- **FontAwesome**: Icons
61+
- **localStorage**: Data persistence
62+
63+
## Setup Instructions
64+
65+
### 1. Prerequisites
66+
- A modern web browser (Chrome, Firefox, Safari, Edge)
67+
- Python 3.x (for local server) OR Node.js (alternative)
68+
- Internet connection (for API calls)
69+
70+
### 2. Installation
71+
72+
#### Option A: Using Python (Recommended)
73+
```bash
74+
# Navigate to project directory
75+
cd Sustainable-Food-Tracker
76+
77+
# Start local server
78+
python -m http.server 8000
79+
```
80+
81+
#### Option B: Using Node.js
82+
```bash
83+
# Install http-server globally (if not installed)
84+
npm install -g http-server
85+
86+
# Navigate to project directory
87+
cd Sustainable-Food-Tracker
88+
89+
# Start server
90+
http-server -p 8000
91+
```
92+
93+
#### Option C: Using npx (No installation needed)
94+
```bash
95+
# Navigate to project directory
96+
cd Sustainable-Food-Tracker
97+
98+
# Start server
99+
npx --yes serve -s . -l 8000
100+
```
101+
102+
### 3. Access the Application
103+
104+
Open your browser and navigate to:
105+
```
106+
http://localhost:8000
107+
```
108+
109+
**Important**: The app must be accessed via `http://localhost` (not `file://`) for:
110+
- API calls to work (CORS)
111+
- Camera access for barcode scanning
112+
- localStorage to function properly
113+
114+
## File Structure
115+
116+
```
117+
Sustainable-Food-Tracker/
118+
├── index.html # Home page (search & scanner)
119+
├── product.html # Product details page
120+
├── history.html # History page
121+
├── profile.html # Profile page
122+
├── app.js # Main application logic
123+
├── storage.js # localStorage management
124+
├── scanner.js # Barcode scanner (QuaggaJS)
125+
├── style.css # All styles
126+
├── placeholder.svg # Placeholder image
127+
└── README.md # This file
128+
```
129+
130+
## External Libraries (CDN)
131+
132+
The following libraries are loaded via CDN:
133+
134+
### Chart.js
135+
```html
136+
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.0/dist/chart.umd.min.js"></script>
137+
```
138+
- **Purpose**: Create nutrition charts
139+
- **Version**: 4.4.0
140+
- **Usage**: Bar charts for nutritional values comparison
141+
142+
### QuaggaJS
143+
```html
144+
<script src="https://cdnjs.cloudflare.com/ajax/libs/quagga/0.12.1/quagga.min.js"></script>
145+
```
146+
- **Purpose**: Barcode scanning from camera
147+
- **Version**: 0.12.1
148+
- **Usage**: Live camera scanning for product barcodes
149+
150+
### FontAwesome
151+
```html
152+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
153+
```
154+
- **Purpose**: Icons throughout the UI
155+
- **Version**: 6.4.0
156+
157+
## API Integration
158+
159+
### OpenFoodFacts API
160+
- **Base URL**: `https://world.openfoodfacts.org`
161+
- **Endpoints Used**:
162+
- Product by barcode: `/api/v2/product/{barcode}`
163+
- Product search: `/cgi/search.pl?search_terms={query}&json=1`
164+
- Product details: `/api/v0/product/{barcode}.json`
165+
166+
The app tries multiple API endpoints for maximum compatibility.
167+
168+
## Testing the Scanner
169+
170+
### Browser Requirements
171+
- **HTTPS or localhost**: Required for camera access
172+
- **Camera permissions**: Browser will prompt for permission
173+
174+
### Testing Steps
175+
1. Open the app at `http://localhost:8000`
176+
2. Click "Scan Barcode" button
177+
3. Allow camera permissions when prompted
178+
4. Point camera at a barcode (EAN-8, EAN-13, UPC, etc.)
179+
5. The scanner will automatically detect and navigate to product page
180+
181+
### Test Barcodes
182+
If you don't have physical products, try these test barcodes:
183+
- `3017620422003` - Nutella
184+
- `7622210945078` - Oreo
185+
- `3017620429484` - Coca Cola
186+
- `5000159461125` - Kit Kat
187+
188+
Enter these in the search box or scan if you have the products.
189+
190+
## Features Breakdown
191+
192+
### Storage Module (`storage.js`)
193+
- `saveToHistory(product)`: Save product to history
194+
- `getHistory()`: Retrieve scan history
195+
- `clearHistory()`: Clear all history
196+
- `getEcoPoints()`: Get current eco-points
197+
- `addEcoPoints(points)`: Add points
198+
- `getLevel()`: Calculate current level
199+
- `calculatePoints(nutriScore, ecoScore)`: Calculate points based on scores
200+
201+
### Scanner Module (`scanner.js`)
202+
- Initializes QuaggaJS scanner
203+
- Handles camera access
204+
- Detects barcodes and navigates to product page
205+
- Modal interface for scanning
206+
207+
### Main App (`app.js`)
208+
- Search functionality
209+
- Product fetching from API
210+
- Product display with all details
211+
- History page loading
212+
- Profile page loading
213+
- Chart creation
214+
215+
## UI Components
216+
217+
### Grade Badges
218+
Color-coded badges for scores:
219+
- **A**: Green (`--grade-a`)
220+
- **B**: Light Green (`--grade-b`)
221+
- **C**: Yellow (`--grade-c`)
222+
- **D**: Orange (`--grade-d`)
223+
- **E**: Red (`--grade-e`)
224+
225+
### Cards
226+
Modern card-based design with:
227+
- Rounded corners
228+
- Soft shadows
229+
- Border styling
230+
- Responsive layout
231+
232+
### Navigation
233+
Fixed bottom navigation bar with:
234+
- Home icon
235+
- History icon
236+
- Profile icon
237+
- Active state indication
238+
239+
## Troubleshooting
240+
241+
### Scanner Not Working
242+
- Ensure you're using `http://localhost:8000` (not `file://`)
243+
- Check browser camera permissions
244+
- Try a different browser
245+
- Ensure good lighting for barcode scanning
246+
247+
### API Errors
248+
- Check internet connection
249+
- OpenFoodFacts API might be temporarily down
250+
- Try a different product/barcode
251+
- Check browser console (F12) for detailed errors
252+
253+
### Styling Issues
254+
- Hard refresh: `Ctrl + F5` (Windows) or `Cmd + Shift + R` (Mac)
255+
- Clear browser cache
256+
- Check if all CSS files are loading
257+
258+
### localStorage Not Working
259+
- Ensure you're using `http://localhost` (not `file://`)
260+
- Check browser settings (some browsers block localStorage in private mode)
261+
- Clear browser data if needed
262+
263+
## Browser Compatibility
264+
265+
- ✅ Chrome/Edge (Recommended)
266+
- ✅ Firefox
267+
- ✅ Safari
268+
- ✅ Opera
269+
270+
**Note**: Camera access requires HTTPS or localhost in all browsers.
271+
272+
## Development
273+
274+
### Adding New Features
275+
1. **New Page**: Create HTML file and add navigation link
276+
2. **New Function**: Add to `app.js` or create new module
277+
3. **New Style**: Add to `style.css` using CSS variables
278+
279+
### CSS Variables
280+
All colors are defined in `:root`:
281+
```css
282+
--primary: hsl(158, 64%, 35%);
283+
--primary-light: hsl(158, 64%, 45%);
284+
--primary-dark: hsl(158, 64%, 25%);
285+
--secondary: hsl(158, 30%, 95%);
286+
--accent: hsl(170, 55%, 50%);
287+
/* ... and more */
288+
```
289+
290+
## License
291+
292+
This project is open source and available for educational purposes.
293+
294+
## Credits
295+
296+
- **OpenFoodFacts**: Product data API
297+
- **Chart.js**: Chart library
298+
- **QuaggaJS**: Barcode scanning library
299+
- **FontAwesome**: Icons
300+
301+
---
302+
303+
**Made with ❤️ for sustainable food choices**

0 commit comments

Comments
 (0)