25th project of the Trybe Web Development course.
TFC is a full-stack application that provides information about games and soccer rankings.
I was responsible for developing the dockerized back-end using data modeling through Sequelize so that the front-end could properly consume the API data. The architecture follows the MSC model and the principles and concepts of OOP and SOLID were applied.
ℹ️ Front-end was developed and provided by Trybe.
🧱 If you want to go deeper into the structure of the project, just click here.
The project consists of 4 entities:
1️⃣ Database:
- It is a pre-configured MySQL docker container in the
docker-compose
file through a service defined asdb
; - It is responsible for providing data to the back-end service;
- You can also connect to a MySQL client (Workbench, Beekeeper, DBeaver, etc.), using the credentials configured in the
docker-compose
file for thedb
service.
2️⃣ Back-end:
- Runs on port
3001
oflocalhost
, which is the default port for the front-end to make requests; - The application is initialized from the
app/backend/src/server.ts
file; express
is executed and the application listens on the port from the environment variables;- All extra dependencies (such as
joi
,boom
,express-async-errors
, etc.) must be listed inapp/backend/packages.npm
.
3️⃣ Front-end:
- Runs on port
3000
oflocalhost
; - The front-end communicates with the back-end service through the URL
http://localhost:3001
.
4️⃣ Docker:
- The
docker-compose
file is responsible for joining all containerized services (backend, frontend, and db) and running the entire project with the commandnpm run compose:up
ornpm run compose:up:dev
.
🎞️ Click to see a demo of the project.
Project.TFC.demo.mp4
To ensure code quality, ESlint was used. To virtualize the application in containers, Docker was chosen.
Below you can see a list of all the technologies used in the project.
- There are three ways to view the ranking: overall (which includes all matches), home games, and away games.
- It's possible to view the results of finished games and those that are still in progress.
- With the logged-in admin user, it's possible to edit the scores of matches in progress and finish them. Matches that have already ended cannot be changed.
- With the logged-in admin user, it's possible to add a new match.
To run the project locally, follow the steps below.
- Verify that your machine meets the minimum requirements for running the project;
- Unix Distribution Operating System;
- Node version equal to or greater than
16.14.0 LTS
; - Docker;
- Docker-compose version equal to or greater than
1.29.2
.
- Clone the repository;
git clone [email protected]:garciaagui/trybe-futebol-clube.git
- Navigate to the root of the project;
cd trybe-futebol-clube/
- At the root of the project, install the dependencies with the command below;
npm run postinstall
- At the root of the project, go to the app directory and run the command below to start the containers. By doing so, three containers will be initialized:
- app_backend: related to the back-end;
- app_frontend: related to the front-end;
- db: related to the database.
cd app/ && npm run compose:up:dev
- In your browser, visit
http://localhost:3000
. If everything went well, you should be able to use the application.
ℹ️ For additional instructions, click here.
- To run the back-end tests, go to the
app/backend/
directory and use the command below.
npm run test:coverage
- To start the application outside the container and connect to your local database, follow the steps below.
- Go to the
app/backend/
directory; - Rename the
.env.example
file to.env
; - Configure the values according to the scenario of your environment (database credentials, desired secrets, etc.).
Below you can find a breakdown of the endpoints used in the project. To make HTTP requests and check the behavior of each endpoint, you can use the Thunder Client extension.
⚠️ Please pay attention to the token generated during login, it will be necessary for other operations. Also remember that its expiration time is 1 hour.
Login
- Validates the user's login and returns a token generated with jsonwebtoken (JWT).
- The generated token must be inserted in the
Authorization
Header to authenticate other operations. Remember to save it and keep in mind that its expiration time is 1 hour. - URL:
http://localhost:3001/login
- The request body must have the following format:
{
"email": "string",
"password": "string"
}
- Validates the user's login and returns the user's
role
(admin or user). - 🔑 The token is validated on this endpoint.
- URL:
http://localhost:3001/login/validate
Teams
- Returns all teams registered in the database.
- URL:
http://localhost:3001/teams
- Returns the team according to the id passed in the endpoint.
- Example URL:
http://localhost:3001/teams/1
Matches
- Returns all matches registered in the database.
- URL:
http://localhost:3001/matches
- Registers a new match.
- 🔑 The token is validated in this endpoint.
- URL:
http://localhost:3001/matches
- The request body must have the following format:
{
"homeTeamId": number, // The value must be the id of the home team
"awayTeamId": number, // The value must be the id of the away team
"homeTeamGoals": number,
"awayTeamGoals": number,
}
- Updates the score of the match whose id was passed in the endpoint.
- Example URL:
http://localhost:3001/matches/42
- The request body must have the following format:
{
"homeTeamGoals": number,
"awayTeamGoals": number
}
- Finishes the match whose id was passed in the endpoint.
- Example URL:
http://localhost:3001/matches/42/finish
- No request body is needed.
Leaderboard
- Returns the overall classification of the championship (considers all matches).
- URL:
http://localhost:3001/leaderboard
- Returns the classification based only on matches played at home.
- URL:
http://localhost:3001/leaderboard/home
- Returns the classification based only on matches played away.
- URL:
http://localhost:3001/leaderboard/away
"Trybe is a future school for anyone who wants to improve their lives and build a successful career in technology, where the person only pays when they get a good job."
"The program features over 1,500 hours of online classes covering introduction to software development, front-end, back-end, computer science, software engineering, agile methodologies, and behavioral skills."
Project developed by Guilherme Garcia. Below are my social networks and means of contact. 🤘