tmeu / Backend-API

Backend API for mobile and web applications for Grovi

Home Page:https://grovi-backend.herokuapp.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Grovi

A place where growers and consumers meet

CodeSize LastCommit

'Grovi' is a place for growers who's willing to take an extra income for their extra harvesting from home gardening or cultivations. The main product for 'Grovi' is a mobile application powered by React-native. This is the backend for that mobile application and the administrator web application which is done using React.

Features

  • Mobile application for Growers and Consumers
  • Web application for administrators

Tech

Grovi uses a number of open source projects to work properly:

  • ReactJS - A JavaScript library for building user interfaces
  • React-native - Mobile application development tool
  • Material UI - A popular React UI framework
  • Node.js - Evented I/O for the backend
  • Express - Fast node.js network app framework
  • PostgreSQL - Relational open source DBMS
  • PostGIS - Spatial and Geographic objects for PostgreSQL
  • Sequelize - ORM for node.js

Installation

Change the directory

cd Backend-API

Create '.env' file in the root folder

Add following details in it

# server
NODE_ENV=development
PORT=5000
HOST=localhost (if you are in production environment, use 'grovi-backend.herokuapp.com')

# authentication
JWT_SECRET=<add a secret(random string with 32 characters would be enough)>
JWT_EXPIRES_IN=90d
TWILIO_ACCOUNT_SID=<your_twilio_account_sid>
TWILIO_AUTH_TOKEN=<your_twilio_auth_token>
TWILIO_PHONE_NUMBER=<your_twilio_phone_number>
SMS_SECRET_KEY=<add a secret(random string with 32 characters would be enough)>

# database
DB_USER=postgres
DB_HOST=localhost
DB_DATABASE=grovi
DB_PWD=admin
DB_PORT=5432

# email
EMAIL_HOST=smtp.mailtrap.io
EMAIL_PORT=2525
EMAIL_USERNAME=<mailtrap_email_username>
EMAIL_PASSWORD=<mailtrap_email_password>

# image upload
IMG_CLOUD_NAME=<cloudinary_cloud_name>
IMG_API_KEY=<cloudinary_api_key>
IMG_API_SECRET=<cloudinary_api_secret>

Install the dependencies and devDependencies and start the server.

npm install
npm start

For production environments...

npm install --production
npm run start:prod

For database environments...

Execute the functions in the extra/db/functions.sql file in your database

Migrate tables into postgres database

npm run migrate

Undo Migrations for all tables

npm run undoMigrate

Populate all tables with provided data (Seeding)

npm run seed

Undo seeding for all tables

npm run undoSeed

Sequelize documentation for migrations - https://sequelize.org/master/manual/migrations.html

Open http://localhost:5000 and take a look around.

Deployment

  1. Connect Github branch to Heroku
  2. Edit config/config.json file with necessary Heroku db credentials
  3. Add following code snippet to config/config.json file under 'development', 'test', 'production' objects
"dialectOptions": {
      "ssl": {
        "require": true,
        "rejectUnauthorized": false
      }
}
  1. Change cors in app.js as following
app.use(
  cors({
    origin: `https://grovi-backend.herokuapp.com:${process.env.PORT}`,
    credentials: true,
  })
);
  1. Setup configurations as in config.env
  2. Setup deployment
  3. Setup pgAdmin remotely by giving necessary credentials.
  4. Install postgis and postgis_topology extensions from pgAdmin
  5. From Heroku dashboard CLI do the migrations

Heroku migration commands (from Heroku dashboard)

heroku run sequelize-cli db:migrate
heroku run sequelize-cli db:seed:all

License

MIT

Group No: 15

Member Index No Github username
J.P.A. Shanaka 18001582 ashanaka
D.D. Liyanaarachch i 18000932 DDhanushka
A. H. Dodampe 18000462 anjana-dodampe
A.C.Vidanagamachchi 18001769 asinduvg
G. H. G. M. Madara 18020471 ManulMax
T. M. E. U. De Silva 18000355 TMEU

About

Backend API for mobile and web applications for Grovi

https://grovi-backend.herokuapp.com/

License:MIT License


Languages

Language:JavaScript 93.0%Language:Pug 6.5%Language:PLpgSQL 0.5%