This is the server for the Jimo iOS app.
This is a FastAPI server that uses Firebase for authentication and Postgres as a database. We use the PostGIS extension for geospatial functionality, such as map queries.
- Install Postgres and PostGIS and create a new local database.
- Take note of the database URL. It’ll be something like "postgresql://user@localhost/database_name".
- Go to the Firebase console, click Generate new private key and Generate key. If you don't have access to the production project, create a new one.
- Save the JSON file somewhere and optionally rename it. I’ve named mine
service-account-file.json
, and this is already in .gitignore (double check you don’t commit this file). - Set the environment variables. Set the
DATABASE_URL
environment variable to the database URL. We use an async db connection so you need to changepostgresql://
topostgresql+asyncpg://
. SetGOOGLE_APPLICATION_CREDENTIALS
to the path to the service account file.
- (Optional) Create a virtual environment using pyenv, venv, or a similar tool, and activate it.
- Install Poetry here.
- Run
poetry install
.- If you created a virtual environment, the dependencies will be installed to it; otherwise, poetry will create one for you.
- Set the environment variables:
Variable | Value |
---|---|
DATABASE_URL |
Full database url (w/ credentials). |
GOOGLE_APPLICATION_CREDENTIALS |
Path to the service account JSON file. |
ALLOW_ORIGIN |
(Optional) Allow requests from the given host.. |
ENABLE_DOCS |
(Optional) If set to 1, enable the /docs , /redoc , and /openapi.json endpoints. Disabled by default. |
STORAGE_BUCKET |
The Firebase storage bucket to save images to. Defaults to goodplaces-app.appspot.com . If you're using your own Firebase project, you need to set this. |
- Run
python migrate.py
to set up the database tables. - Run
export ENABLE_DOCS=1
and then runpython runserver.py
. - View the docs at
http://localhost/docs
orhttp://localhost/redoc
. OpenAPI definitions are available athttp://localhost/openapi.json
.
Command | Action |
---|---|
flake8 . |
Lint files |
pytest |
Run tests |
alembic revision --autogenerate -m <message> |
Generate database migration (run this after changing the db schema). IMPORTANT: Double check the generated file (in alembic/versions/ ) to make sure the migration is correct. Alembic can't always generate the right migrations. |
alembic upgrade head |
Run database migrations. |
The backend is split up two main folders: core
and features
.
For every authenticated request, we receive an authorization
header, which is a bearer token used to authenticate requests.
We use Firebase for auth and verify the token by checking it with them. If you're testing locally, you can modify this to disable auth.
While the app is no longer officially maintained, issues, feature requests, and contributions are welcome!