sfbrigade / datasci-earthquake

MIT License
0 stars 2 forks source link

This is a project of SF Civic Tech https://www.sfcivictech.org/

Introduction

This is a hybrid Next.js + Python app that uses Next.js as the frontend and FastAPI as the API backend.

Getting Started

First, install the dependencies:

npm install
# or
yarn
# or
pnpm install

Then, run the development server:

npm run dev
# or
yarn dev
# or
pnpm dev

Open http://localhost:3000 with your browser to see the result.

The FastApi server will be running on http://127.0.0.1:8000 – feel free to change the port in package.json (you'll also need to update it in next.config.js).

Learn More

To learn more about Next.js, take a look at the following resources:

You can check out the Next.js GitHub repository - your feedback and contributions are welcome!


Formatting with a Pre-Commit Hook

This repository uses Black for Python and ESLint for JS/TS to enforce code style standards. We also use MyPy to perform static type checking on Python code. The pre-commit hook runs the formatters automatically before each commit, helping maintain code consistency across the project.

Prerequisites

Usage


Docker

This project uses Docker and Docker Compose to run the application, which includes the frontend, backend, and postgres database.

Prerequisites

Starting the Application

  1. Run Docker Compose: From the project root directory (where the docker-compose.yml file is located), run: docker-compose up -d This will:
  1. Access the Application:

    • The app is running at http://localhost:3000. Note that this may conflict with your local dev server. If so, one will be running on port 3000 and the other on port 3001.
    • The API is accessible at http://localhost:8000.
    • The Postgres instance with PostGIS extension is accessible at http://localhost:5432.
    • To interact with a running container, use docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
      • To run a database query, run docker exec -it my_postgis_db psql -U postgres -d qsdatabase
      • To execute a python scrupt, run docker exec -it datasci-earthquake-backend-1 python <path/to/script>

    Note: If you modify the Dockerfile or other build contexts (e.g., .env, requirements.txt, package.json), you should run docker-compose up -d --build to rebuild the images and apply the changes!

Shutting Down the Application

To stop and shut down the application:

  1. Stop Docker Compose: In the same directory where the docker-compose.yml file is located, press Ctrl + C in the terminal where the app is running.

  2. Bring Down the Containers: If you want to stop and remove the containers completely, run: docker-compose down This will:

    • Stop all services.
    • Remove the containers, but it will not delete volumes (so the database data will persist).

    Note: If you want to start with a clean slate and remove all data inside the containers, run docker-compose down -v.


Configuration of environment variables

We use GitHub Secrets to store sensitive environment variables. A template .env.example file is provided in the repository as a reference. Only users with write access to the repository can manually trigger the Generate .env File workflow, which creates and uploads the actual .env file as an artifact.

Note: Before starting work on the project, make sure to:

  1. Get write access to the repository
  2. Trigger the Generate .env File workflow and download the artifact.
  3. Place the artifact in the root folder of the project. Make sure the file is named .env.

The file is organized into three main sections:


Disclaimer

Some versions of this code contain a streamlit app that uses an imprecise measure which may introduce errors in the output. The streamlit app should not be relied upon to determine any property’s safety or compliance with the soft story program. Please consult DataSF for most up to date information.