# Project export: UCBMealz

This document was generated by HackStack to give an AI agent context about a hackathon project. Sections are labeled with their provenance; content marked as truncated was cut to keep this document small.

## Project metadata

- Hackathon: Cal Hacks 11.0
- Tagline: A way to create meals based on certain nutritional goals for UC Berkeley's multiple dining halls.
- Devpost: https://devpost.com/software/ucbmealz
- GitHub: https://github.com/ahugais/ucbmealz
- Video: https://www.youtube.com/embed/Y8Ex1ZEMp28?enablejsapi=1&hl=en_US&rel=0&start=&version=3&wmode=transparent
- Team: 3 GitHub contributor(s) — Ibrashoukry (20 commits), mukhtarcal (16 commits), ahugais (10 commits)

## Devpost submission (written by the team)

### Inspiration

As college students who attend UC Berkeley, we find ourselves not having time to cook healthy nutritious food that would meet our fitness goals. The next best option out there was getting food from the campus' dining halls. However, due to the vast types of foods served at these dining halls it seemed difficult to keep track of what to eat in order to maintain our health goals.

### What it does

We created a website that scrapes the UC Berkeley dining page where it is updated daily with all the food that is offered at the dining halls and its nutritional values. The website then takes the amount of calories and macro nutrients the user wants to eat and creates a personalized meal plan that abide by their specific needs.

### How we built it

We used the Gemini AI API to create the customized meals, where the base of the website was created using React.js. Finally for scraping, we used selenium for the main part.

### Challenges we ran into

Using the Gemini API took us a while to understand and make it output what we wanted. When it came to scraping, we ran into some challenges with getting hidden elements.

### Accomplishments we're proud of

We are very proud that we have a final project that we can be proud of as well as one that we made in such a limited amount of time. It took a lot of effort from us but it payed off in the end.

### What we learned

Building a web application in such a short amount of time was very challenging but through it we learned so much. We learned how to problem solve and go around many of the issues and bugs we came across. It was so much fun pushing ourselves to the limit and seeing what we come up with.

### What's next

Upscaling it to other UCs and eventually to other universities across the world.

## README (from the GitHub repository)

# Getting Started with Create React App

This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

## Available Scripts

In the project directory, you can run:

### `npm start`

Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in your browser.

The page will reload when you make changes.\
You may also see any lint errors in the console.

### `npm test`

Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

### `npm run build`

Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `npm run eject`

**Note: this is a one-way operation. Once you `eject`, you can't go back!**

If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.

You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).

### Code Splitting

This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)

### Analyzing the Bundle Size

This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)

### Making a Progressive Web App

This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)

### Advanced Configuration

This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)

### Deployment

This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)

### `npm run build` fails to minify

This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)


## Detected evidence (automated analysis)

Indexed codebase: 18 recognized source files, 112 KB.
- CSS (language) — detected in the code
- Express (technology) — detected in the code
- Google Gemini (technology) — detected in the code
- HTML (language) — detected in the code
- JavaScript (language) — detected in the code
- Python (language) — detected in the code
- React (technology) — detected in the code
- Node.js (technology) — claimed on Devpost, not found in the code

## Codebase structure (from repository index)

### Files (24 of 24)

```
.gitignore
dining_hall_data.db
package.json
public/index.html
public/manifest.json
public/robots.txt
README.md
scraping/dining_menu_scrape.js
scraping/dining_menu_scrape.py
src/App.css
src/App.js
src/App.test.js
src/components/GenerateButton.js
src/components/Header.js
src/components/RecommendedMeal.js
src/components/SelectionPanel.js
src/data.js
src/gemini_api.js
src/index.css
src/index.js
src/jsonData.js
src/meal_data.json
src/reportWebVitals.js
src/setupTests.js
```

### Dependencies

- package.json: @google/generative-ai@^0.21.0, @testing-library/jest-dom@^5.17.0, @testing-library/react@^13.4.0, @testing-library/user-event@^13.5.0, axios@^1.7.7, chromedriver@^130.0.4, express@^4.21.1, node-schedule@^2.1.1, react@^18.3.1, react-dom@^18.3.1, react-scripts@^5.0.1, selenium@^2.20.0, selenium-webdriver@^4.26.0, sqlite3@^5.1.7, web-vitals@^2.1.4

### Recent commits (newest first)

- fixing merge conflict
- scraper now in js and headless
- 11/16/2024
- nothing
- jerk chicken
- working MVP
- cleaned up
- ai works
- Merge branch 'main' of https://github.com/ahugais/ucbmealz
- nthin new
- automated scraped data being added to meal_data.json
- Merge branch 'main' of https://github.com/ahugais/ucbmealz
- json holds data
- create json file
- commits
- python to js test
- Resolved all conflicts by accepting incoming changes
- Merge branch 'main' of https://github.com/ahugais/ucbmealz
- sqlite3
- sqlite3 tests

## Key source files (fetched from GitHub, selected and truncated for size)

### package.json

```
{
  "name": "ucbmealz",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@google/generative-ai": "^0.21.0",
    "@testing-library/jest-dom": "^5.17.0",
    "@testing-library/react": "^13.4.0",
    "@testing-library/user-event": "^13.5.0",
    "axios": "^1.7.7",
    "chromedriver": "^130.0.4",
    "express": "^4.21.1",
    "node-schedule": "^2.1.1",
    "react": "^18.3.1",
    "react-dom": "^18.3.1",
    "react-scripts": "^5.0.1",
    "selenium": "^2.20.0",
    "selenium-webdriver": "^4.26.0",
    "sqlite3": "^5.1.7",
    "web-vitals": "^2.1.4"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "description": "This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).",
  "main": "index.js",
  "keywords": [],
  "author": "",
  "license": "ISC"
}

```

### src/index.js

```javascript
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>
);

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();

```

### src/App.js

```javascript
import React, { useState } from 'react';
import Header from './components/Header';
import SelectionPanel from './components/SelectionPanel';
import RecommendedMeal from './components/RecommendedMeal';
import './App.css';
import { selectedData } from './data.js';

/* Global variables to store selections and nutrient values
export const selectedData = {
  diningHall: ["Crossroads", "Cafe 3", "Clark Kerr", "Foothill"],
  meal: '',
  dietaryIncludes: [],
  dietaryExcludes: [],
  calories: '',
  carbs: '',
  protein: '',
  fats: ''
};*/

function App() {
  const [clearSelections, setClearSelections] = useState(false);
  const [generateMeal, setGenerateMeal] = useState(false);
  const [diningHall, setDiningHall] = useState([]);
  const [meal, setMeal] = useState('');
  const [dietaryIncludes, setDietaryIncludes] = useState([]);
  const [dietaryExcludes, setDietaryExcludes] = useState([]);
  const [calories, setCalories] = useState('');
  const [carbs, setCarbs] = useState('');
  const [protein, setProtein] = useState('');
  const [fats, setFats] = useState('');

  const handleMealGeneration = () => {
    // Update global variables only when the button is clicked
    selectedData.diningHall = diningHall;
    selectedData.meal = meal;
    selectedData.dietaryIncludes = dietaryIncludes;
    selectedData.dietaryExcludes = dietaryExcludes;
    selectedData.calories = calories;
    selectedData.carbs = carbs;
    selectedData.protein = protein;
    selectedData.fats = fats;

    console.log('Selected Data:', selectedData); // For debugging
    setGenerateMeal(true);
    // Clear all selections after generating the meal
    setClearSelections(true);

    // Reset states after a brief delay
    setTimeout(() => {
      setClearSelections(false);
      setGenerateMeal(false);
    }, 100);
  };

  return (
    <div className="app-container">
      <Header />
      <div className="panels-container">
        <SelectionPanel
          title="Dining Halls"
          options={['Crossroads', 'Cafe 3', 'Clark Kerr', 'Foothill']}
          clearSelections={clearSelections}
          onChange={setDiningHall}
          isMultiSelect={true}
        />
        <SelectionPanel
          title="Meal"
          options={['Breakfast', 'Brunch', 'Lunch', 'Dinner']}
          clearSelections={clearSelections}
          onChange={setMeal}
          isMultiSelect={false}
        />
        <SelectionPanel
          title="Dietary Restriction"
          options={['Halal', 'Vegan', 'Vegetarian', 'Kosher']}
          excludes={['Milk', 'Gluten', 'Peanuts', 'Tree nuts']}
          clearSelections={clearSelections}
          onChangeIncludes={setDietaryIncludes}
          onChangeExcludes={setDietaryExcludes}
          isMultiSelect={true}
        />
        <SelectionPanel
          title="Nutrients"
          options={['Calories (kcal):', 'Carbs (g):', 'Protein (g):', 'Fats (g):']}
          clearSelections={clearSelections}
          onChangeCalories={setCalories}
          onChangeCarbs={setCarbs}
          onChangeProtein={setProtein}
          onChangeFats={setFats}
          isMultiSelect={true}
        />
      </div>

      {/* Generate Meal Button */}
      <button onClick={handleMealGeneration} className="generate-meal-button">
        Generate Meal
      </button>

      <RecommendedMeal generateMeal={generateMeal} />
    </div>
  );
}

export default App;

```

### src/data.js

```javascript
export const selectedData = {
    diningHall: ["Crossroads", "Cafe 3", "Clark Kerr", "Foothill"],
    meal: '',
    dietaryIncludes: [],
    dietaryExcludes: [],
    calories: '',
    carbs: '',
    protein: '',
    fats: ''
  };
```

### src/setupTests.js

```javascript
// jest-dom adds custom jest matchers for asserting on DOM nodes.
// allows you to do things like:
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom';

```

### src/App.test.js

```javascript
import { render, screen } from '@testing-library/react';
import App from './App';

test('renders learn react link', () => {
  render(<App />);
  const linkElement = screen.getByText(/learn react/i);
  expect(linkElement).toBeInTheDocument();
});

```

### src/reportWebVitals.js

```javascript
const reportWebVitals = onPerfEntry => {
  if (onPerfEntry && onPerfEntry instanceof Function) {
    import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
      getCLS(onPerfEntry);
      getFID(onPerfEntry);
      getFCP(onPerfEntry);
      getLCP(onPerfEntry);
      getTTFB(onPerfEntry);
    });
  }
};

export default reportWebVitals;

```

### src/index.css

```css
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
    'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
    sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

code {
  font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
    monospace;
}

```

### public/index.html

```html
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta name="theme-color" content="#000000" />
    <meta
      name="description"
      content="Web site created using create-react-app"
    />
    <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
    <!--
      manifest.json provides metadata used when your web app is installed on a
      user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
    -->
    <link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
    <!--
      Notice the use of %PUBLIC_URL% in the tags above.
      It will be replaced with the URL of the `public` folder during the build.
      Only files inside the `public` folder can be referenced from the HTML.

      Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
      work correctly both with client-side routing and a non-root public URL.
      Learn how to configure a non-root public URL by running `npm run build`.
    -->
    <title>React App</title>
  </head>
  <body>
    <noscript>You need to enable JavaScript to run this app.</noscript>
    <div id="root"></div>
    <!--
      This HTML file is a template.
      If you open it directly in the browser, you will see an empty page.

      You can add webfonts, meta tags, or analytics to this file.
      The build step will place the bundled scripts into the <body> tag.

      To begin the development, run `npm start` or `yarn start`.
      To create a production bundle, use `npm run build` or `yarn build`.
    -->
  </body>
</html>

```

### src/App.css

```css
body {
  background-color: #1A2B44;
  color: #fff;
  font-family: 'Arial', sans-serif;
  margin: 0;
  padding: 0;
}

/* The container for the whole thing */
.app-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px;
}

/* The container behind the selection panel */
.panels-container {
  display: flex;
  justify-content: center;
  gap: 20px;
  flex-wrap: wrap;  /* Wrapping on smaller screens */
  margin-bottom: 20px;
}

/* The panel inside of the container for the selection */
.panel {
  background-color: #2C3E57;
  padding: 20px;
  border-radius: 15px;  
  width: 250px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.2);
  transition: transform 0.2s; 
  text-align: center;
}

.panel:hover {
  transform: translateY(-5px);  /* Adds a lift effect on hover */
}

.dietary-columns {
  display: flex;
  justify-content: space-between; /* Distribute space between columns */
  gap: 20px; /* Space between the two columns */
}

.dietary-column {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
}

/* The container for the options */
.option {
  display: flex;
  align-items: center;
  gap: 10px;  /* Adds spacing between checkbox/radio and label */
  margin: 5px 0;
}

.nutrient-option {
  display: flex;
  align-items: center;
  justify-content: space-between;  /* Aligns label and input on opposite ends */
  gap: 10px;
  margin: 5px 0;
}

input[type="checkbox"],
input[type="radio"] {
  appearance: none;
  width: 18px;
  height: 18px;
  margin: 0;
  margin-right: 10px;
  cursor: pointer;
  border: 2px solid #FFD700;
  background-color: #441a1a;
}

input[type="checkbox"]:checked,
input[type="radio"]:checked {
  background-color: #FFD700;
}

input[type="checkbox"] {
  border-radius: 4px;  /* Squared for checkboxes */
}

input[type="radio"] {
  border-radius: 50%;  /* Circled for radio buttons */

}

/* Aligns nutrient inputs on the right side */
.nutrient-input {
  width: 80px;
  padding: 5px;
  margin-left: auto;  /* Pushes the input to the right */
  border-radius: 4px;
  border: 1px solid #FFD700;
  background-color: #1A2B44;
  color: #fff;
}

/* Changes border color for the nutrient box when typing */
.nutrient-input:focus {
  outline: none;
  border-color: #FFA500;  
}

.recommended-meal {
  width: 95%;
  max-width: 1170px;
  background-color: #2C3E57;
  padding: 30px;
  border-radius: 12px;
  margin-top: 20px;
  box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.2);
}

/* Text box for the recommendation */
.meal-content {
  margin-top: 20px;
  background-color: #1A2B44;
  padding: 20px;
  border-radius: 12px;
  max-height: 300px; /* Sets a maximum height */
  overflow-y: auto; /* Allows vertical scrolling */
  word-wrap: break-word; /* Breaks long words when there is no space */
  resize: vertical; /* manual resizing */
}

.header {
  text-align: center;
  margin-bottom: 20px;
}

.header img {
  max-width: 2000px; 
  height: auto;
}

.generate-button,
.generate-meal-button {
  margin-top: 20px;
  padding: 12px 24px;
  font-size: 16px;
  background-color: #FFD700;
  color: #1A2B44;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.2s, transform 0.2s;
}

.generate-button:hover,
.generate-meal-button:hover {
  background-color: #FFA500;
  transform: translateY(-3px);  /* Lifting effect */
}

.generate-button:active,
.generate-meal-button:active {
  background-color: #FF8C00;  /* Darker color on click */
  transform: translateY(2px);  /* Pushdown effect */
}

```

[7 more indexed source files omitted to keep this export small. The full file list is in the Codebase structure section above.]