The codebase is divided into 2 main parts:
frontend
: The frontend is a React app that is served by the backend. It is located in thefrontend
folder.backend
: The backend is a Python Flask app that provides the API. Most of the code is located in thebackend
folder. Thewsgi.py
file is the entrypoint of the backend.database
: The database is a PostgreSQL database with the PostGIS extension. The database is used by the backend to store data.
Copy example.env to localizer.env with the following command:
cp example.env localizer.env
Now you can edit the localizer.env
file to set the environment variables. The following environment variables are required to run the app:
API_BASE_URL
: The base URL of the API. This is used by the frontend to make API calls. The default value ishttp://127.0.0.1:5000/
MAPTILER_API_TOKEN
: The api token for the maptiler style API. This is used by the frontend to display the map.MAX_CHALLENGE_AREA
: The maximum area of a challenge in square meters. This is used by the backend and frontend to validate challenges. The default value is200
.CHANGES_UPLOAD_LIMIT
: The maximum number of changes that can be uploaded at once. This is used by the frontend to stop users making too many changes at once to ensure changes are being uploaded consistently to OSM. The default value is25
.APP_SECRET_KEY
: The secret key of the app. This is used by the backend to sign tokens.
Create an OAuth2 application on the OpenStreetMap website. It is important to provide Read user preferences
and Modify the map (read and write)
scopes. The redirect URI should be set to http://127.0.0.1:3000/authorized
while developing locally.
OAUTH2_CLIENT_ID
: The client ID of the OAuth2 application.OAUTH2_CLIENT_SECRET
: The client secret of the OAuth2 application.OAUTH2_REDIRECT_URI
: The redirect URI of the OAuth2 application. This should be set tohttp://127.0.0.1:3000/authorized
.OAUTH2_SCOPE
: The scope of the OAuth2 application. This should be set toread_prefs
andwrite_api
.
The following environment variables are required to connect to the database:
POSTGRES_DB
: The name of the database.POSTGRES_USER
: The username of the database user.POSTGRES_PASSWORD
: The password of the database user.POSTGRES_ENDPOINT
: The host of the database. The default value islocalhost
.POSTGRES_PORT
: The port of the database. The default value is5432
.
- Install PostgreSQL (version 13 or higher recommended)
- Install PostGIS (version 3.1 or higher recommended)
- Create a database user with the following command:
sudo -u postgres createuser -P -s -e <username>
- Create a database with the following command:
sudo -u postgres createdb -O <username> <database_name>
- Create the PostGIS extension with the following command:
sudo -u postgres psql -d <database_name> -c "CREATE EXTENSION postgis;"
- Set the environment variables in the
localizer.env
file.
- Install Docker (version 20.10 or higher recommended)
- Install Docker Compose (version 1.29 or higher recommended)
- Install Docker (version 20.10 or higher recommended)
- Install Docker Compose (version 1.29 or higher recommended)
- Set the environment variables in the
localizer.env
file. ThePOSTGRES_PORT
environment variable should be set to5535
as this is the port that is exposed by thedb
service in thedocker-compose.yml
file. The docker-compose will create user, database and password with the specifiedPOSTGRES_USER
,POSTGRES_PASSWORD
andPOSTGRES_DB
env variables while creating the database container. - Comment out all other services in the
docker-compose.yml
file except for thedb
service if you want to run only the database in Docker. - Run the following command to start the database container:
docker-compose up -d
- You need to setup the backend to create the tables. Follow the steps in the backend setup section.
Your database should now be set up. Let's move on to the backend setup.
Using PDM (Recommended)
- Install the dependencies by running
pdm install
in the project root with the following command:
pdm install
- Set the environment variables in the
localizer.env
file. - Run the following command to create the tables / apply migrations (skip this if
flask db upgrade
is done):
pdm run upgrade
- Start the backend with the following command:
pdm run start
Using Pip
- Export the dependencies from
pdm.lock
torequirements.txt
with the following command:
pdm export --without-hashes > requirements.txt
- Create a virtual environment with the following command:
python -m venv venv
- Activate the virtual environment with the following command:
source venv/bin/activate
- Install the dependencies from
requrements.txt
with the following command:
pip install -r requirements.txt
- Set the environment variables in the
localizer.env
file. - Run the following command to create the tables:
flask db upgrade
- Start the backend with the following command:
python wsgi.py
- Install Docker (version 20.10 or higher recommended)
- Install Docker Compose (version 1.29 or higher recommended)
- Set the environment variables in the
localizer.env
file. - Run the following command to start the backend container:
docker-compose up -d
- All the tables should be created automatically. You can check if the tables are created by running the following command:
docker-compose logs -f backend
Your backend should now be set up.
Hit GET API /api/system/
For health check of API to ensure backend is running successfully it should return healthy
Let's move on to the frontend setup.
- Install Node.js (version 18 or higher recommended)
- Install Yarn (version 1.22 or higher recommended)
- Install the dependencies by running
yarn install
in thefrontend
folder with the following command:
cd frontend
yarn install
- Start the frontend with the following command:
yarn start
- The frontend should now be running on http://localhost:3000
- Now you need to navigate to http://127.0.0.1:3000 as login functionality doesn't work on http://localhost:3000. You should now be able to login with your OSM account.
- After successful setup and login you will encounter permission issue during creation of challenge , Open Users table in your database , Alter your users role to 1 , Logout from frontend and Login again , You should be READY TO ROCK