Skip to content

dzvid/gobarber-api

Repository files navigation

Contributors Forks Stargazers Issues MIT License LinkedIn


Logo

GoBarber

Backend module
Explore the docs »

View Demo · Report Bug · Request Feature

Table of Contents

About The Project

GoBarber is an application that aims to facilite the connection between barbers and clients. This repository contains the backend module and was developed during the Rocketseat Gostack bootcamp.

Built With

Main technologies, libraries and CLI tools used to built the API:

  • Node.js: Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine;
  • PostgreSQL: a powerful, open source object-relational database system with over 30 years of active development that has earned it a strong reputation for reliability, feature robustness, and performance;
  • Redis: Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker;
  • MongoDB: A document-based NoSQL database;
  • Docker: Docker containers wrap up software and its dependencies into a standardized unit for software development that includes everything it needs to run: code, runtime, system tools and libraries. This guarantees that your application will always run the same and makes collaboration as simple as sharing a container image;
  • node.bcrypt.js: A simple, fast, robust job/task queue for Node.js, backed by Redis;
  • Bee queue: A simple, fast, robust job/task queue for Node.js, backed by Redis;
  • Date-fns: Modern JavaScript date utility library;
  • Express: Fast, unopinionated, minimalist web framework for node;
  • jsonwebtoken: An implementation of JSON Web Tokens;
  • Mongoose: MongoDB object modeling designed to work in an asynchronous environment;
  • Multer: Node.js middleware for handling multipart/form-data;
  • Nodemailer: Send e-mails with Node.JS – easy as cake!
  • Sequelize: An easy-to-use multi SQL dialect ORM for Node.js

To manage the code style and formatting:

Getting Started

To get a local copy up and running follow these steps.

Prerequisites

  • Install Node.js: Follow the official tutorial

  • Install a package manager for node:

    • Yarn: Check yarn tutorial (Yarn 1.x (classic) was used in this project).

      or

    • npm (comes with Node.js):

      npm install npm@latest -g
  • Install Docker: Follow the official tutorial.

Installation

To install the project there are two alternatives:

  • Using Docker Compose;
  • Creating Docker containers manually.

Using Docker Compose

  1. Clone the repository and navigate to the project directory:

    Using ssh:
    
    git clone git@github.com:dzvid/gobarber-api.git
    cd gobarber-api
    
    Or using https:
    
    git clone https://github.com/dzvid/gobarber-api.git
    cd gobarber-api
  2. Create the .env file for the environment variables values of the application. You can use the .env.example as a template:

    cp .env.example .env

    Edit the file and set the values for the mailing service, relational and non-relational database services and Sentry token.

    For the mailing service you can use Mailtrap to create a email for development and testing purposes.

    For the Sentry DSN token its necessary to create an account in Sentry and follow the instructions to generate it.

    Make sure the values were declared because they are used in the docker-compose.yml file to create the containers.

  3. Create and start the containers using Composer. Open a terminal window and run the following command:

    docker-compose up
  4. Run sequelize migrations to create the PostgreSQL database tables:

    yarn sequelize db:migrate
  5. At this moment the GoBarber API service runs at: http://localhost:3333

  6. You are done with configuration! I hope everything is alright and you are ready to code! 🎉

Creating containers manually

  1. Create Docker containers, run the following commands in a terminal (feel free to change the container names and passwords as you wish):

    • Create PostgreSQL container:

      docker run --name gobarber -e POSTGRES_PASSWORD=gobarberdev -p 5432:5432 -d --restart always postgres
    • Create MongoDB container:

      docker run --name mongo_gobarber -p 27017:27017 -d -t --restart always mongo
    • Create Redis container:

      docker run --name redis_gobarber -p 6379:6379 -d -t --restart always redis:alpine
  2. Create GoBarber database in PostgreSQL:

    # Open PostgreSQL container terminal
    docker exec -it gobarber /bin/sh
    
    # Change to postgres user
    su postgres
    
    # Enter postgres CLI
    psql
    
    # Create the database
    CREATE DATABASE gobarber;
    
    # Check if the database was created, run:
    \list
  3. Clone the repository:

    Using ssh:
    git clone git@github.com:dzvid/gobarber-api.git
    
    Or using https:
    git clone https://github.com/dzvid/gobarber-api.git
  4. Install the project dependencies:

    cd gobarber-api
    
    yarn

    or using npm:

    cd gobarber-api
    
    npm install
  5. Create the .env file for the environment variables values of the application. You can use the .env.example as a template:

    cp .env.example .env

    Edit the file and set the values according to the values previously used during the creation of the containers.

    For the mailing service you can use Mailtrap to create a email for development and testing purposes.

    For the Sentry DSN token its necessary to create an account in Sentry and follow the instructions to generate it.

  6. Run sequelize migrations to create the database tables:

    yarn sequelize db:migrate
  7. Open a terminal window and start the queue service (Reponsible to deliver emails):

    yarn queue
  8. Open another terminal window and start the development server:

    yarn dev

    The GoBarber API runs at: http://localhost:3333

  9. You are done with configuration! I hope everything is alright and you are ready to code! 🎉

Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE for more information.

Contact

David Oliveira - oliveiradavid.dev@gmail.com

Project Link: https://github.com/dzvid/gobarber-api

Acknowledgements

About

Node.js API of GoBarber (an application that aims to facilite the connection between barbers and clients!)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages