1. Knowledge Base
  2. Crowdbotics Developer Training
  3. Developer Training Part 3: Testing and Debugging

Local Setup

Learn how to run your Crowdbotics Project locally.

Part 1: Clone from Github

To get started running your project locally, you'll need to clone it from Github. To do this, first find your Github repo, which you can find on the "Settings" page on your dashboard.Screen Shot 2021-06-23 at 1.21.22 PM

Click on "View Code" to open your code in a new window. From there, click on "Code" to copy the link to your repo, which you can then clone by opening a terminal program and running: 

$ git clone https://github.com/crowdbotics-apps/<your-project-repo>

Once that operation completes, you will have access to all your code locally!


Part 2: Launching the backend

To bring your backend online, open the folder with all of your Crowdbotics code and navigate to your `backend` folder. The `backend` folder is where all of the code for your backend lives. In this folder, you'll find a complete Django application, along with any backend modules you may have installed, under the `backend/modules` folder.


Step 1: Opening the backend README.md

Within the `backend` folder, there is a specific README file that provides instructions for setting up your backend to run locally. Please read this! It contains all you need to get started. 

Step 2: Installing Requirements  Docker is the preferred way to run your Crowdbotics backend, so you should ensure that you have it installed. Also make sure you have Docker Compose installed: https://docs.docker.com/compose/

Step 3: Make sure you have. a Pipfile.lock This file should be generated when you create your application, and be located somewhere within your `backend` folder. If you don't have one for some reason, you can generate it like so:

$ docker run -it --rm -v "$PWD":/django -w /django python:3.7 pip3 install --no-cache-dir -q pipenv && pipenv lock

Step 4: Copy the `.env.template` into your own `.env` file The backend comes with a sample .env file, which you can use to bootstrap your own file. You'll need to copy this file and configure it with your application's settings for this to work. You can either do this manually, by copying and pasting the contents of `.env.template` into your own file and saving that as `.env`, or you can run: 

 $ cp .env.example .env

And edit the newly created file on your own. Note that this step is necessary to be able to run the backend locally.

Step 5: Update `docker-compose.override.yml` This file is also in `backend` and needs to be updated so you can run the application. Open it and replace the placeholders with the appropriate values. 

Step 6: Build the container Build the container for the first time like this. Note that this can take a few minutes depending on your machine.

$ docker-compose build

Step 7: Bring the container up After building the container, bring it up with the following command:

$ docker-compose up

Your app should now be running at http://localhost:8000/!

Step 8: Run Migrations and Create Superuser Almost done! Now we need to run our migrations. Leave docker running in the terminal window you were using above, and open a new terminal window in the same directory. Inside that window, run the following two commands to make and run migrations:

$ docker-compose exec web python3 manage.py makemigrations
$ docker-compose exec web python3 manage.py migrate

Make sure that these have run successfully. A good way to confirm that things are working is to take a look at the admin panel at http://localhost:8000/admin/

If you need to create a superuser, you can do so with another django management command. As above, do this in a separate terminal window open to the same directory as your project's backend.

$ docker-compose exec web python3 manage.py createsuperuser

This should prompt you to enter credentials which you can use to log in to the admin panel. Congratulations, your app should now be completely ready for local development!

Part 3: Launching the native app

Step 1: Open README.md file. Your React Native code lives one directory level higher than your backend, or, in other words, at the top level of your project. Navigate back to this folder and open the README included in this folder, which includes valuable information about how to run your app's frontend locally. 

Step 2: Yarn Install From the top level of your project, run `yarn install` to install your dependencies. If you don't have yarn installed, you will need to install it.

$ yarn install

Step 3: Make sure iOS and Android Dependencies are installed. Depending on which emulator you are running, you'll need to have either XCode or Android Studio installed, along with the requisite packages.

You'll also need to install npx:

$ npm install -g npx


Step 4: (iOS Only) Pod Install If you are running iOS, you'll need to pod install from the `ios` directory, which can be found in the top level directory. From the top level directory, you can run the following: 

$ cd ios
$ pod install

Step 5: Run the metro Server Run the metro server with the following command. Note you will still need to run the  next command to build your app.

$ npx react-native start


Step 6: Run your app Use this command to run your app. You should run this command from the root directory, not the `ios` or `android` folders. After running, you should see your app building and then running in the emulator!


$ npx react-native run-ios


$ npx react-native run-android


Additional setup instructions for your React native app can be found in the README.MD