Git Product home page Git Product logo

18w-paintthetown-backend's Introduction

Paint the Town: Backend

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.

File Structure

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
        │   ...

Implementation

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.

Configuation

  1. 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 encryption
    • MONGODB_URI - The URI of the MongoDB instance to user
  • Configuration
    • BUILDINGS_PER_RESTOCK - Given the average of all buildings avg, users will get avg * BUILDINGS_PER_RESTOCK units of paint back when their timer runs out
    • INITIAL_PAINT- Total units available for all new users
    • MAX_RESTOCK - Beyond MAX_RESTOCK units of paint, the user will stop receiving refills
    • MAX_TEAMS - Total number of teams to consider per building when determining both building color and ownership
    • RESTOCK_INTERVAL - Number of milliseconds between each timer interval
  1. Run npm install from the root folder to install all the required NodeJS modules.

## Execution

  1. During development, run npm run dev. Otherwise, run npm start.

Testing

A web client helps test all the routes. See /testing/web_client/README.md for additional information.

18w-paintthetown-backend's People

Contributors

mauesrog avatar acaish12 avatar ahoisington avatar alexander-sheehan avatar mphilie avatar shoopalapa avatar tedbausch avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar  avatar

18w-paintthetown-backend's Issues

add to building_controller and building_model

  • get list of splotches on a building and the face of the building they are on (controller)

  • calcArea() that finds the amount of splotch space on building controlled by a team (controller)

  • add list of splotches to building model

  • add top altitude and bottom altitude of building (model)

  • add control variable - var that tells which team is controlling the building (model) << we might just keep track of this on the front end. not sure

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.