Skip to content

tgmarinho/gobarber-api-gostack11

Repository files navigation

GoBarber API

A backend API for a barbershop scheduling app. It was built as the capstone of Rocketseat's GoStack 11 bootcamp, with a focus on SOLID principles, DDD-style layering, and tests.

Node.js TypeScript Express TypeORM PostgreSQL MongoDB Redis Jest

What it does

  • Books appointments between clients and service providers.
  • Lists registered providers.
  • Handles user sign up and authentication with JWT.
  • Recovers passwords by sending an email with a reset link.
  • Lets users update their profile.
  • Accepts avatar uploads.
  • Applies rate limiting to protect the API.

Architecture

The codebase follows SOLID principles and a DDD-style layout. The goal is clear separation of concerns and easy testing.

  • Domain modules. Code is split by business domain under src/modules (users, appointments, notifications). Shared infrastructure lives under src/shared.
  • Repositories. Each module exposes repository interfaces. Data access details stay behind those interfaces, so the business logic does not depend on the database.
  • Services. Each use case is a small service with a single responsibility.
  • Dependency injection. Dependencies are wired with tsyringe. Services receive their collaborators through their constructors, which keeps them decoupled and testable.

Stack

  • Node.js as the runtime.
  • TypeScript as the language.
  • Express as the web framework.
  • TypeORM as the ORM.
  • PostgreSQL as the main database.
  • MongoDB for notifications.
  • Redis for caching and rate limiting.
  • Jest for tests.
  • Other libraries: jsonwebtoken for auth, bcryptjs for password hashing, multer for uploads, nodemailer for email, celebrate for request validation, and date-fns for dates.

Run locally

This project uses Yarn. The lockfile is yarn.lock.

You will need PostgreSQL, MongoDB, and Redis running.

# install dependencies
yarn

# build the TypeScript code
yarn build

# start the dev server with hot reload
yarn dev:server

# start the server with ts-node
yarn start

Database migrations

TypeORM migrations run through the typeorm script:

# create a migration
yarn typeorm migration:create -n CreateAppointments

# run pending migrations
yarn typeorm migration:run

# revert the last migration
yarn typeorm migration:revert

# show migration status
yarn typeorm migration:show

Tests

Tests run with Jest:

yarn test

Author

Thiago Marinho

License

MIT

Releases

No releases published

Packages

 
 
 

Contributors