CS348: Introduction to Database Systems Fall 2025 Project (30%).
Members: Joanna Moon, Luna Nguyen, Lydia He, Mathilda Lee.
The Underground Lens is a database-driven application that provides real-time insights for riders boarding the New York City Metropolitan Transportation Authority (NYC MTA) transportation network. The database migrates MTA subway data (Trip, Station, Ridership) from Open New York (data.ny.gov) to provide basic (station information, trip times) and complex (congestion, route suggestions) information to users.
This project is a mono-repo of four milestones summarizing the final product.
- Python 3.9+
- MySQL 8.0+ (instructions below)
mysql-connector-python8.1.0+- Node.js 18+ and npm 9+ (for React frontend)
We will use MySQL on local machines with Python (mysql-connector-python).
MacOS via Homebrew:
brew install mysql
brew services start mysql
Windows via MySQL Installer:
- Setup Type: server-only is sufficient.
- Execute all default installation instructions.
Once installed, run mysql --version. Should be 8.0 or higher.
Perform the following steps based on your operating system.
Make sure you are in the cs348-project\3-milestone directory.
If MacOS / Linux, run in terminal:
python3 -m venv .venvIf Windows, run in PowerShell:
python -m venv .venvIf MacOS / Linux, run in terminal:
source .venv/bin/activateIf Windows, run in PowerShell:
.venv\Scripts\activateMacOS / Linux / Windows:
pip install -r requirements.txtCopy the .default_env file to create your .env file, then update it with your MySQL password.
Prerequisites:
- You have MySQL installed with a
rootuser (or some other admin username). - You know the password for that user.
Log in to MySQL as root (make sure you are in the cs348-project\3-milestone directory):
mysql -u root -pCreate the Database:
CREATE DATABASE IF NOT EXISTS transit_db;To use the (user: rider_user, pass: Rider_pass123 OR user: admin_user, pass: Admin_pass123) combination, create the user and grant permissions by roles:
CREATE USER IF NOT EXISTS 'rider_user'@'localhost' IDENTIFIED BY 'Rider_pass123';
CREATE USER IF NOT EXISTS 'admin_user'@'localhost' IDENTIFIED BY 'Admin_pass123';SOURCE db/administration.sql;GRANT rider_role TO 'rider_user'@'localhost';
GRANT admin_role TO 'admin_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;This is recommended, as it matches the .default_env file.
Why This is Needed:
The application uses MySQL triggers and stored procedures (for R12 Advanced Feature: Data Suggestions). When binary logging is enabled in MySQL (which is common), creating triggers requires either:
- SUPER privilege, OR
- Setting
log_bin_trust_function_creators = 1
Important: Each teammate with their own local MySQL installation will need to grant this privilege on their own machine.
While still logged in as root (from step 3.a above), grant the SUPER privilege:
GRANT SUPER ON *.* TO 'cs348_user'@'localhost';
FLUSH PRIVILEGES;Alternative: If you prefer not to grant SUPER, you can instead set the global variable (requires SUPER or SYSTEM_VARIABLES_ADMIN privilege):
SET GLOBAL log_bin_trust_function_creators = 1;For more details, see 3-milestone/db/README_privileges.md.
You can now exit MySQL:
EXIT;The app.py script will automatically:
- Create tables (station, hourly_ridership, trip, suggestion)
- Create stored procedures
- Create triggers
- Populate tables from CSV files (stations, hourly ridership, trips)
Make sure you are in the cs348-project/3-milestone directory.
If MacOS / Linux, run in terminal:
mysql -u admin_user -p < db/createtables.sqlIf Windows, run in PowerShell:
Get-Content db/createtables.sql | mysql -u admin_user -pIf MacOS / Linux, run in terminal:
mysql -u admin_user -p transit_db < db/populatetables.sqlIf Windows, run in PowerShell:
Get-Content db/populatetables.sql | mysql -u admin_user -p transit_dbIf MacOS / Linux, run in terminal:
python3 app.pyIf Windows, run in PowerShell or Git Bash:
python app.pyYou should see output confirming each step:
- Tables created!
- Stored procedures created!
- Triggers created!
- CSV data loaded
- Database setup complete!
If MacOS / Linux, run in terminal:
mysql -u cs348_user -p -t < queries/test-sample.sql > queries/test-sample.outIf Windows, run in PowerShell:
Get-Content queries/test-sample.sql | mysql -u cs348_user -p -tTo verify that your query output matches the expected results in test-sample.out:
If MacOS / Linux, run in terminal. If Windows (Git Bash), run in Git Bash:
mysql -u cs348_user -p -t transit_db < queries/test-sample.sql | diff - queries/test-sample.outNo differences should be displayed. This means the output matches the expected results.
Milestone 2 uses a React frontend instead of vanilla JavaScript.
Ensure you have Node.js 18+ and npm 9+ installed:
node --version
npm --versionIf not installed, download from nodejs.org.
cd frontendMacOS / Linux / Windows:
npm installThis will install:
- React and React DOM
- React Router (for navigation)
- Axios (for API calls)
- Recharts (for data visualization)
- Tailwind CSS (for styling)
- Vite (development server and build tool)
You need to run both the backend API and the frontend dev server.
Open a terminal in the 3-milestone directory:
If MacOS / Linux, run in terminal:
source .venv/bin/activate
./run_api.shIf Windows, run in PowerShell:
.venv\Scripts\activate
./run_api.batOr manually:
python -m flask --app api.rest_endpoints run --port 5000The API will be running at http://localhost:5000
Open a second terminal and navigate to the frontend directory:
cd 3-milestone/frontend
npm run devThe React application will be running at http://localhost:5173
Open http://localhost:5173 in your browser to use the application.
To test the REST API endpoints, see the linked README.