This is an evaluative project developed in the BackEnd module of the Web Development course at Trybe. The project involved the use of Typescript, Sequelize, and JWT. Throughout the development, various skills were enhanced:
- Handling tests
- Using the MSC (Model-Service-Controller) architecture
- Creating routes for creating, reading, and updating information
- Route authentication
This project consisted of creating a store for medieval items using Typescript and Sequelize. The main focus was on developing the Service and Controllers layers.
- Node.js
- Express
- Typescript
- Sequelize
- MySQL
- JWT (JSON Web Token)
- Docker and Docker Compose
The project is structured according to the MSC architecture, where responsibilities are separated among Model, Service, and Controller. Below are some of the main routes implemented:
- POST /login: Logs in the user.
- POST /products: Adds a new product (validates name and price).
- GET /products: Returns all registered products.
- GET /orders: Returns all registered orders.
- POST /orders: Creates a new order (validates JWT, user ID, and product ID).
The project uses several middlewares for validation, including:
validateProducts
: Validates product data (name and price).validateUser
: Validates user data.validateProductById
: Validates the existence of the product by ID.validateJWT
: Validates the JWT token for authentication.
To run the project, follow the steps below:
- Have Docker and Docker Compose installed.
- Have Node.js installed (optional, if you want to run locally without Docker).
-
Clone the repository:
git clone https://github.com/seu_usuario/trybe-smith.git cd trybe-smith
-
Create a
.env
file in the root of the project with the following environment variables:DB_USER=root DB_PASSWORD=password DB_HOST=db DB_PORT=3306 DB_NAME=Trybesmith JWT_SECRET=secret
-
Run Docker Compose to build and start the containers:
docker-compose up --build
-
Access the API in your browser or API tool (like Postman) at
http://localhost:3001
.