Developer Setup
Before you get started, there are a few dependencies that you will need to make sure you have installed before contributing toToyNet.
Frontend
Backend

Getting Started with ToyNet Frontend Development

toynet-react is ToyNet's frontend service and is written in React using Typescript. To get started with local development make sure that you have the correct dependencies installed as listed above.
If you are not a not a member on Project Reclass' GitHub organization, you will first need to fork the toynet-react repository.
To fork the repository, you will need to go to the repo and click the "fork" button in the top right. You will use this new repository to make pull requests against the main Project Reclass repository.
1
git clone https://github.com/{your github username}/toynet-react.git
Copied!

Starting ToyNet for Development

  1. 1.
    Install all of the dependencies using npm i
  2. 2.
    Start ToyNet using just npm or docker-compose and npm
    1. 1.
      Start using just npm (easiest)
      npm run dev
      This starts all of the docker containers and the react development server together
    2. 2.
      Start with docker-compose
      docker-compose -f docker-compose.dev.yml up --build -d
      npm start
This will start up the development server. This server includes hot reloading so any changes made to the application will cause a re-build and will refresh your browser.

Additional Scripts

There are several npm scripts that can be used in your development that can be ran with npm run [script]
1
"start": "", // starts the development server
2
"start:dev": "", // starts the dev server and docker services
3
"build": "", // builds the project
4
"check-types": "", // runs the typescript compiler to check TS types
5
"style:check": "", // runs the linter
6
"style:fix": "", //
7
"start:docker:dev": "", // runs docker-compose -f docker-compose.dev.yml up --build
8
"test": "", // runs the unit testing suite
9
"test:cy": "" // runs in the integration test suite
Copied!

Getting Started with ToyNet Backend Development

toynet-flask is ToyNet's backend service and is written in Python. To get started with local development make sure that you have the correct dependencies installed as listed above.

venv

Create a project folder and a venv folder within:
1
$ git clone https://github.com/Project-Reclass/toynet-flask
2
$ cd toynet-flask
3
$ python3 -m venv venv
Copied!
Before you work on your project, activate the corresponding environment:
1
$ . venv/bin/activate
Copied!
Install Python Requirements (add new requirements via pip3 freeze > requirements.txt.)
1
$ pip3 install -r requirements.txt
Copied!
You can exit this virtual environment anytime via running:
1
$ deactivate
Copied!
More information here​
From there, make sure to build the toynet docker image from toynet_mininet and tag it with the same tag you use in the below environment variable for TOYNET_IMAGE_TAG. First you will need to download mininet. You can do this by initializing the submodule.
1
cd toynet_mininet
2
$ git submodule update --init --recursive
Copied!
You will then need to build the image. The default way, which will work with the Makefile here, is to go into the toynet_mininet submodule and run:
1
$ make test-image
Copied!
if you want a test image. If you want a production image then run:
1
$ make prod-image
Copied!
also in the toynet_mininet directory.
Note: See the toynet_mininet README for more information on building and developing toynet_mininet.

Run the service

Make sure that, if you are testing anything related to sessions or network emulation, that you build the appropriate image (dev or prod) in toynet-mininet.
The following tutorial applies to Linux / MacOS development environments. Visit Windows documentation here.
1
# populate environment variables for testing
2
$ source instances/env-dev
3
​
4
# Populate environment variables for production
5
$ source instances/env-prod
6
​
7
# creates instance/toynet.sqlite
8
$ flask init-db
9
Initialized the database.
10
​
11
$ flask run
12
* Serving Flask app "flasksrc" (lazy loading)
13
* Environment: development
14
* Debug mode: on
15
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
16
* Restarting with stat
17
* Debugger is active!
18
* Debugger PIN: 220-725-712
Copied!
Go to: http://127.0.0.1:5000/
​​
​
​

Makefile

The Makefile facilitates common workflows, run make help for detailed instructions. You can use it to run everything in Docker containers, as opposed to running Flask locally as described above.

Swagger API Documentation

Visit swagger documentation to generate living documentation about available API endpoints alongside your flask instance.

Test the Service

Visit testing documentation to learn how to unit test, run manual tests in development, and query SQLite files.
​
Last modified 3mo ago
Copy link