Git Product home page Git Product logo

project-api-boilerplate's Introduction

API Boilerplate

This is the API boilerplate which will get you started. For any questions regarding the stack, please use our #help channel in Slack.

Table of contents

Directory Layout

./
├── /src                    # Directory for the api code, a standard express app using Postgres as database
│   ├── /config/            #
│   ├── /controllers/       #
│   ├── /helpers/           #
│   ├── /lib/               #
│   ├── /migrations/        #
│   ├── /models/            #
│   ├── /routes/            #
│   ├── /seeders/           #
│   └── server.js           #
├── .env                    # Defines environment variables for the project
├── .sequelizerc            # Defines default configuration for a database helper tool called Sequelize
├── docker-compose.yml      # Defines Docker services, networks and volumes, do not touch unless you know what you are doing
├── Dockerfile              # Defines how Docker should build a custom image for the application, do not touch unless you know what you are doing
└── README.md               # The file you are reading right now

Quickstart

It's best if this is started from the project root instead of inside the api repo, but if for some reason you want to work on the API independently you can run the project from this location. Here's how to do that:

Note: Only change the environment variables for POSTGRES_USER and POSTGRES_PASSWORD if working on local machine.

Copy .env.dist to .env and change the values of the environment variables if needed.

PORT=7770
ALLOW_ORIGIN=http://localhost:7771
JWT_SECRET=jwtsecretcode
POSTGRES_PORT=5432
POSTGRES_DB=api
POSTGRES_USER=user
POSTGRES_PASSWORD=root

Then run the following commands:

yarn
yarn start

Note: The database must be created and initialized after starting the app on fresh installation. See Database using PostgreSQL and Sequelize section. See Bash Commands section for Docker.

Access the app at http://localhost:7770.

Usage

Docker

Download and install the Docker Community Edition.

Note: See Bash Commands section for Docker.

Database using PostgreSQL and Sequelize

Installing PostgreSQL

Mac: Getting Started with PostgreSQL on Mac OSX
Windows: Installing PostgreSQL, Creating a User, and Creating a Database

NOTE: For Mac users, you can run the PostgreSQL server on a separate terminal console by running the following command:

postgres -D /usr/local/var/postgres

Create and Initialize Database

Open a terminal console and run the following commands:

sequelize db:create
sequelize db:migrate
sequelize db:seed:all

To drop database, run the following command:

sequelize db:drop

See Bash Commands section for Docker.

Bash Commands

On the root directory of the project, run the following commands:

Note: To view the Docker containers, open another terminal console then enter docker ps. To manage separate Docker instance for API, open another terminal console and run the commands below.

Docker

Command Description
./bin/install Build the Docker containers, initialise database and start the app
./bin/reinstall Re-build containers, re-initialise database and start the app
./bin/start Start all the services (API and database)
./bin/stop Stop all the services
./bin/console <container ID or Name> Access the terminal console of the API container

Database

Local

Command Description
./bin/pg/local/start Start the PostgreSQL server (for Mac users only)
./bin/pg/local/resetdb Drop and re-initialise database
./bin/pg/local/migrate Run new schema migration
./bin/pg/local/migrateundo Revert the recent schema migration
./bin/pg/local/seed <seed file> Run specific data seed file with or without .js extension
./bin/pg/local/seedundo <seed file> Revert the seed of specific data seed file
./bin/pg/local/psql Access the database console

Docker

  • To run the commands for Docker database service, simply remove the local from the command
  • The start command works only in local machine
  • Used ./bin/pg/psql <database container ID or Name> to access the database console

Users

Use the following credentials to test different API responses. Default password for all accounts is password.

Name Email Description
Super Admin User [email protected] Has wildcard access
Admin User [email protected] Has wildcard access but Admin › Users › Delete is excluded
Common User [email protected] Can access My Profile, Admin › Dashboard, Users, Users › View, and Settings
Referrer User [email protected] When redirect is set without the domain, e.i. /admin/dashboard, user shall be redirected to internal page if no location path (referrer) found on the Sign In page
Redirect User [email protected] When redirect is set with complete URL, e.i. https://github.com/anthub-services, user shall be redirected to external page if no location path (referrer) found on the Sign In page
Blocked User [email protected] User is signed in but the account is blocked
Unauthorized User <any invalid email> Simply enter wrong email and/or password

project-api-boilerplate's People

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.