Skip to content

A GymPass style API app for practicing the API REST on Node.js with SOLID principles.

Notifications You must be signed in to change notification settings

rcrdk/gympass-api-nodejs-solid

Repository files navigation

🏋🏼 GymPass Style App API

I developed this project during my latest studies on Node lessons at Rocketseat.

🚀 Techs and Tools

🖥️ Project

This project was developed to practice the development of a API REST in Node.js with Fastify applying concepts as SOLID, design patterns (factory pattern, repositories pattern), clean architecture and TDD.

To get started with the flow of the application, you can register a new user and authenticate, then, you can get the logged-in user profile; create a gym (only user with admin role can create one); search for gyms by name or by geo-location (check for functional requirements below for the rules); the user can check-in into a gym (check for business rules below to know about the rules); The user can get the history of check-ins and their metrics; The admin user can validate this check-in within 20 minutes.

In this project it was ensured that all application works by running all test over testing simply with routes on Insomnia. TDD (Test-Driven Development) concept was used in some tests situation, just for learning this method. It was applied unit tests to services layer and E2E test on controllers. It was used Vitest along with supertest to make requests.

It was implemented GitHub Actions to run unit tests on push and E2E tests on pull requests. Prisma was used as ORM and client alongside with PostgreSQL database to mage with data. To make the authentication it was used JWT (JSON Web Token) to persist user information with security into the application. It was applied RBAC (Role-Based Access Control) concept to assign roles to determinate kind of user.

⚙️ Get started

npm i
npm run start:dev

docker compose up -d

npx prisma migrate dev

🔗 Routes

Run in Insomnia}

📋 Business Rules and Requirements

Functional Requirements

  • It should be able to create an account;
  • It should be able to authenticate;
  • It should be able to get the authenticated user profile;
  • It should be able to get the total check-ins by the authenticated user;
  • It should be able to get all authenticated user check-ins history;
  • It should be able to find nearby gyms (around 10 kilometers);
  • It should be able to search for gyms by name;
  • It should be able to a user to check-in into a gym;
  • It should be able to validate a user check-in;
  • It should be able to create a new gym;

Business Rules

  • The user cannot create a new account with a duplicated e-mail;
  • The user cannot make more than one check-in on the same day;
  • The user cannot check-in if their not nearby the gym (around 100 meters);
  • The check-in can only be validated till 20 minutes after created;
  • The check-in can only be validated by administrators;
  • The gym can only be created by administrators;

Non Functional Requirements

  • The user password must be encypted;
  • All application data must be persisted on a postgreSQL database;
  • All data listed should be paginated with 20 itens by page;
  • The user must be identified by a JWT (JSON Web Token);