This repo is a full-stack app using the FastAPI web framework, MySQL for a database, and REST to interact with a simple users table. You may install MySQL natively or use the included Docker file to create a database in a containter. The init-db.sql defines a simple schema for use with the example.
You just need to have Python 3.10+ installed.
-
Create database credentials (specify your own USERNAME, PASSWORD, and ROOT_PASSWORD!)
echo "MYSQL_HOST=localhost" > .env echo "MYSQL_DATABASE=ece140" >> .env echo "MYSQL_USER=USERNAME" >> .env echo "MYSQL_PASSWORD=PASSWORD" >> .env echo "MYSQL_ROOT_PASSWORD=ROOT_PASSWORD" >> .env
-
If you have Docker installed, run the following command to start up a MySQL server (ignore this step if you already have MySQL installed and modify the
.envfile to match your database credentials!). Run the command in a separate terminal window as it will lock up the window for logging.docker compose up --build -d
Note: Just closing the terminal will not stop the database server. In order to stop it, you must issue the command
docker compose downwhen you are finished. -
Install
uv(one-time)brew install uv
If you don’t use Homebrew, see https://docs.astral.sh/uv/getting-started/ for alternatives.
-
Create a virtual environment and sync dependencies
uv sync
-
Run the server (recommended: single worker)
uv run server/main.py
- The server interacts with a MySQL database to persist user data.
- The database connection details are specified in the
.envfile. - The
init-db.sqlfile can be used to initialize the database schema if needed. - The MySQL database will persist, even if the server is stopped because we volume mount the database data to the host machine in the
docker-compose.ymlfile.
