This is the backend for Couchers.org built in Python. The React web frontend and React Native apps make API calls to it using gRPC which are defined via Protocol Buffers. The business logic manipulates a PostgreSQL database via SQLAlchemy. Geospatial features are provided by the PostGIS extension.
Readme last updated: 2025/01/12.
These instructions should work directly on Linux and macOS. If you are using Windows, please install Ubuntu via WSL2, then follow these instructions inside Ubuntu.
You need Docker engine installed. Please refer to the Docker install documentation for how to set it up.
Next, run the following commands to get the backend up and running:
## Check out the repo and navigate to the backend folder
git clone https://github.com/Couchers-org/couchers.git
cd couchers/app/backend
## Generate the autogenerated API definitions using protobuf and grpc
make protos
## Build and start the docker containers
docker compose up --buildThis will spin up a complete copy of the database, backend, and proxies needed to run the platform inside Docker.
If this succeeds, the backend should come up and print some info logging every few seconds about background jobs. You should be able to navigate to http://localhost:8888/status and see some JSON indicating the backend is up.
This will not currently run the frontend, to do that, please follow the instructions in app/web/readme.md under Quick Start, then Running against a local backend.
You can run all backend tests in docker with the following commands:
cd app/backend
# Run all tests
make docker-test
# Or run a single file's tests
make docker-test file=test_filename.py
# Teardown the test database when done
make teardown-docker-testYou can run the backend outside Docker and have it talk to the rest of the containerized services running inside Docker.
You'll need to install uv (a Python package/project manager) and sync dependencies before starting:
curl -LsSf https://astral.sh/uv/install.sh | sh
cd app/backend
uv syncThen start a local backend with all dependencies (postgres, maildev, etc.):
make runIf you find that the proxy/media services can't talk to your local backend, try setting the BACKEND_HOST=host.docker.internal environment variable before running the services via docker compose.
Run dependencies with docker compose:
cd app/backend
make run-depsThen execute app/backend/src/run_locally.py with your debugger of choice. It will have all the correct env variables and will connect to the services (db, etc.) running in docker.
cd app/backend
# Start the test database
make setup-db
# Now run the test against the testing postgres database
make test
# Or run a single file's tests, add your filename
make test file=[test_filename.py]A: First doublecheck what port the DB is listening on - run docker compose up postgres and it should say something like listening on IPv6 address "::", port 6545. Then doublecheck you have the right password. There are TWO passwords - one for the test db and one for the normal db! See app/postgres.dev.env and app/postgres.test.env
Here is information for debugging the backend inside VS Code
A: This happens when you either switch between branches that mutate the database or something else funny happens. The easiest way is to nuke the database:
- Stop postgres docker container
- Delete the
postgresfolder inapp/data - Re-run
docker compose up --build
If you have any trouble, send Aapeli a message on Slack. He's more than happy to spend a bit of time helping you set things up!
A: Regenerate protos using
docker run --pull always --rm -w /app -v $(pwd):/app registry.gitlab.com/couchers/grpc ./generate_protos.shA: If you are using the local backend, you can log in with the username "aapeli" and the password "Aapeli's password". This comes from the dummy data. For emails, see the next question.
If you are using the live dev api ("next"/staging), it will send you real emails so you can sign up. However, all links will point to next.couchershq.org. If you want to open them with the couchers frontend you are working on locally, change the links to http://localhost:3000/rest/of/the/url.
A: We run MailDev with the docker compose setup: it will receive emails and let you browse them. To view emails, visit http://localhost:1080.