About • How to run • Usage • Tests • Technologies • Author • License
This is the backend REST API made with Node.js, Express, and TypeScript for the GoBarber project. GoBarber is a web application for appointment scheduling designed for barbershops and hair salons.
By signing up, users can schedule a new appointment with all available stylists working at the business. On the other hand, registered stylists have access to a web interface to manage their schedules with real-time updates (new or canceled appointments).
To see the web client, click here: GoBarber Web
To see the mobile client, click here: GoBarber Mobile
Demo credentials:
acc: [email protected] / password: demo-password-peppa
Initial requirements: git, yarn, docker, and a code editor of your choice.
# Clone this repository
$ git clone https://github.com/wilsonfsouza/gobarber-rest-api.git
# Access the folder in your terminal
$ cd gobarber-rest-api
# Install all dependencies
$ yarn install
# Make a copy of '.env.example' to '.env'
# and set with YOUR environment variables.
# The AWS variables do not need to be filled for development environment
$ cp .env.example .env
This project uses three databases:
Postgres
: to store most of the application data (general use)MongoDB
: to store application's notificationsRedis
: to store the application's cache and rate limit middleware
# Create the instance of postgreSQL using docker
$ docker run --name postgres -e POSTGRES_USER=postgres \
-e POSTGRES_DB=gostack_gobarber -e POSTGRES_PASSWORD=docker \
-p 5432:5432 -d postgres
# Make a copy of 'ormconfig.example.json'
# to 'ormconfig.json'
# and set YOUR default database configuration.
$ cp ormconfig.example.json ormconfig.json
# Run typeorm migrations
$ yarn typeorm migration:run
If you do not have Postgres installed on your machine, the port 5432 should be available. Otherwise, you can use port 5433 instead. Use -d flag to run your container in detached mode. This mode allows you to start and run your container in the background.
# Create the instance of mongoDB using docker
$ docker run --name mongodb -p 27017:27017 -d -t mongo
# Access your ormconfig.json and add
# YOUR mongo configuration
# How do I know if MongoDB is running? Access localhost:27017 on your browser.
# Create the instance of redis using docker
$ docker run --name gobarber-redis -p 6379:6379 -d -t redis:alpine
# Access your .env file and add your REDIS configuration
For Windows users using Docker Toolbox, you might need to set the host for your databases on your .env and ormconfig.json files to 192.168.99.100 (docker machine IP) instead of localhost or 127.0.0.1.
key | description | default |
---|---|---|
APP_API_URL | Used to mount avatars' urls. | http://localhost:3333 |
APP_WEB_URL | Used to create the reset password link (front-end) sent in the recover password email. | http://localhost:3000 |
APP_SECRET | An alphanumeric random string. Used to create signed tokens. | - |
MAIL_DRIVER | Indicate what email service use to send messages, the possible values are ethereal and ses , to use the SES service remember to to configure the AWS_ACCESS_KEY_ID , AWS_SECRET_ACCESS_KEY and AWS_DEFAULT_REGION keys. |
ethereal |
AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY | These keys are necessary to AWS allow the application to use the S3 and SES services throught API. See how to get yours keys here: Set up AWS Credentials. | - |
AWS_DEFAULT_REGION | You can see your default region in the navigation bar at the top right after login in the AWS Management Console. Read AWS service endpoints to know more about regions. | - |
STORAGE_DRIVER | Indicate where the users's avatar will be stored, the possible values are disk and s3 , to store into S3 remember to configure all the AWS_* keys. |
disk |
REDIS_HOST | Redis host. | localhost |
REDIS_PORT | Redis port. | 6379 |
REDIS_PASS | Redis password. | - |
# To start development server, run:
$ yarn dev:server
This app has open and private routes. Private routes expect a Bearer token in an Authorization
header. The token is generated after a user sign in into the application throughout the /sessions
route. This token will expire after 2 hours.
Route | HTTP Method | Params | Description | Auth method |
---|---|---|---|---|
/sessions |
POST | Body with user's email and password. | Authenticates user, return a Bearer Token and user's id and email. | ❌ |
/users |
POST | Body with user's name, email, and password. | Sign up for new users. | ❌ |
/profile |
GET | - | Shows user profile. | Bearer |
/profile |
PUT | Body with user name , email , old_password , password , and password_confirmation . |
Updates user information. | Bearer |
/users/avatar |
PATCH | Multipart payload with a avatar field with a image. |
Update user avatar. | Bearer |
/password/forgot |
POST | Body with user's email . |
Sends to user the reset password email. | ❌ |
/password/reset |
POST | Body with user's new password and password_confirmation . |
Resets user's password. | ❌ |
Route | HTTP Method | Params | Description | Auth method |
---|---|---|---|---|
/appointments |
POST | Body with appointment provider_id and date . |
Schedules a new appointment. | Bearer |
/appointments/me |
GET | day , month and year query parameters. |
Returns user's scheduled appointments in a specific date. | Bearer |
/providers |
GET | page query parameter. |
Lists providers. | Bearer |
/providers/:id/monthly-availability |
GET | month and year query parameters. |
Lists provider's monthly availability | Bearer |
/providers/:id/daily-availability |
GET | day , month and year query parameters. |
Lists provider's daily availability for a given day. | Bearer |
# Running tests
$ yarn test
# Generating test coverage
$ yarn test --coverage
The following tools were used in this project:
REST API (Node.js + TypeScript)
- Node.js
- TypeScript
- Express
- Docker
- JWT-token
- Uuid v4
- Multer
- AWS SDK
- TypeORM
- PostgreSQL
- MongoDB
- Redis / ioredis
- Date-fns
- Nodemailer
- Jest
- ESLint
- Prettier
- EditorConfig
See the file package.json
- Editor: Visual Studio Code
- Markdown: Markdown Emoji
- Fork the project.
- Start a new branch with your changes:
git checkout -b my-new-feature
- Save it and create a commit message describing what you have done:
git commit -m "feature: My new feature"
- Send your alterations:
git push origin my-feature
This project is being developed under MIT License.
Made with ❤️ by Wilson Franca 👋