An API that provides server functionality for the Unity app, Paint the Town. The backend consists of two main components: /app
and /testing
and deploys to Heroku.
Listing of non-standard directories:
backend
│ .env
│ README.md
│
└───app
│ │ init_script.js
│ │ router.js
│ │ server.js
│ │
│ └───config
│ │ │ index.js
│ │
│ └───controllers
│ │ │ building_controller.js
│ │ │ challenge_controller.js
│ │ │ city_controller.js
│ │ │ color_controller.js
│ │ │ reset_controller.js
│ │ │ particle_controller.js
│ │ │ team_controller.js
│ │ │ user_controller.js
│ │
│ └───models
│ │ │ building_model.js
│ │ │ challenge_model.js
│ │ │ city_model.js
│ │ │ color_model.js
│ │ │ reset_model.js
│ │ │ particle_model.js
│ │ │ team_model.js
│ │ │ user_model.js
│ │
│ └───services
│ │ │ passport.js
│ │
│ └───utils
│ │ adders.js
│ │ color.js
│ │ file.js
│ │ geometry.js
│ │ index.js
│ │ misc.js
│ │ timer.js
│
└───testing
│ clear_db.txt
│ test_scaffolding.js
│
└───web_client
│ ...
The directories in /app
include the entire implementation of the backend. Written in ES6 and compiled through Babel, the implementation follows the Airbnb JavaScript Style Guide and consists of a MongoDB-powered API that handles security and authentication through Passport.
-
Controllers: Each controller is associated with a model and determines how to handle and respond to HTTP requests. Controller actions may include alterations to MongoDB models.
-
Initialization script: Script to be run right after resetting the database. Creates default users, colors, and teams.
-
Models: Each model defines the fields that database entries should contain and determines primary keys.
-
Router: Assigns controllers to each route exposed by the API (exclusively POST and GET routes).
-
Server: Configures and initializes the NodeJS server (created with ExpressJS) to wait for HTTP requests.
-
Services: Includes all of the backend's additional services. At this point, the only service, Passport, handles user authentication through Facebook's OAuth or JWT auth with email-password pairs.
-
Utilities: Offers an implementation for commonly used routines shared throughout the backend.
- If running locally, create a
.env
file that contains all required environment and configuration variables:
- Environment
API_SECRET
- Secret to be shared between clients and server for encryptionMONGODB_URI
- The URI of the MongoDB instance to user
- Configuration
BUILDINGS_PER_RESTOCK
- Given the average of all buildingsavg
, users will getavg * BUILDINGS_PER_RESTOCK
units of paint back when their timer runs outINITIAL_PAINT
- Total units available for all new usersMAX_RESTOCK
- BeyondMAX_RESTOCK
units of paint, the user will stop receiving refillsMAX_TEAMS
- Total number of teams to consider per building when determining both building color and ownershipRESTOCK_INTERVAL
- Number of milliseconds between each timer interval
- Run
npm install
from the root folder to install all the required NodeJS modules.
## Execution
- During development, run
npm run dev
. Otherwise, runnpm start
.
A web client helps test all the routes. See /testing/web_client/README.md
for additional information.