Skip to content

Latest commit

 

History

History
172 lines (120 loc) · 4.47 KB

CONTRIBUTING.md

File metadata and controls

172 lines (120 loc) · 4.47 KB

Getting Started

To get started, check out the Project tracker.

Developing

To get started developing:

  1. Clone the repository
  2. Install the React dependencies and create a .env.local file
  3. Install the FastAPI dependencies
  4. Start the Redis and DynamoDB databases
  5. Initialize the test databases
  6. Serve the FastAPI application
  7. Serve the React frontend

Important

You MUST access the locally run website through 127.0.0.1:3000 and NOT localhost:3000. This is because the CORS policy is configured to only allow requests from the exact domain 127.0.0.1:3000.

Database

DynamoDB/S3

When developing locally, install the aws CLI and use the localstack/localstack Docker image to run a local instance of AWS:

docker pull localstack/localstack # If you haven't already
docker run -d --name localstack -p 4566:4566 -p 4571:4571 localstack/localstack

Then, if you need to kill the database, you can run:

docker kill store-db || true
docker rm store-db || true

Initialize the test databases by running the creation script:

python -m store.app.db create

And initialize the image bucket:

aws s3api create-bucket --bucket images

Admin Panel

DynamoDB Admin is a GUI that allows you to visually see your tables and their entries. To install, run

npm i -g dynamodb-admin

To run, source the same environment variables that you use for FastAPI and then run

DYNAMO_ENDPOINT=http://127.0.0.1:4566 dynamodb-admin

Redis

For Redis, use the redis Docker image:

docker pull redis  # If you haven't already
docker run --name store-redis -d -p 6379:6379 redis  # Start the container in the background

Then, if you need to kill the database, you can run:

docker kill store-redis || true
docker rm store-redis || true

FastAPI

Create a Python virtual environment using either uv or virtualenv with at least Python 3.11. This should look something like this:

uv venv .venv --python 3.11  # If using uv
python -m venv .venv  # Using vanilla virtualenv
source .venv/bin/activate

Install the project:

uv pip install -e '.[dev]'  # If using uv
pip install -e '.[dev]'  # Using vanilla pip

Serve the FastAPI application in development mode:

fastapi dev 'store/app/main.py' --port 8080  # On port 8080 to avoid conflicts with Docker

Configuration

Settings for the app backend live in the store/settings/ directory. To configure which set of settings you are using, set ROBOLIST_ENVIRONMENT. It is the stem of one of the config files in the store/settings/configs/ directory. When developing locally this should usually just be local

To locally develop, setting the following environment variables will work (presuming you have set everything else up):

export ROBOLIST_ENVIRONMENT=local
export AWS_DEFAULT_REGION='us-east-1'
export AWS_ACCESS_KEY_ID=test
export AWS_SECRET_ACCESS_KEY=test
export AWS_ENDPOINT_URL_DYNAMODB=http://127.0.0.1:4566
export AWS_ENDPOINT_URL_S3=http://127.0.0.1:4566
export REACT_APP_BACKEND_URL=http://127.0.0.1:8080
export ROBOLIST_SMTP_HOST=smtp.gmail.com
export ROBOLIST_SMTP_SENDER_EMAIL=
export ROBOLIST_SMTP_PASSWORD=
export ROBOLIST_SMTP_SENDER_NAME=
export ROBOLIST_SMTP_USERNAME=
export ROBOLIST_REDIS_HOST=
export ROBOLIST_REDIS_PASSWORD=

React

To install the React dependencies, use nvm and npm:

cd frontend
nvm use 20.10.0
npm install

To serve the React frontend in development mode:

npm start

To build the React frontend for production:

npm run build

To run code formatting:

npm run format

Google Client ID

You will need to set REACT_APP_GOOGLE_CLIENT_ID. To do this, first create a Google client id (see this LogRocket post). Then create a .env.local file in the frontend directory and add the following line:

REACT_APP_GOOGLE_CLIENT_ID=your-client-id

Additionally, you should set REACT_APP_BACKEND_URL to the URL of the FastAPI backend. This should be http://127.0.0.1:8080 when developing locally.

Testing

To run the tests, you can use the following commands:

make test
make test-frontend  # Run only the frontend tests
make test-backend  # Run only the backend tests