Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/isabelle-moura/culture-power
Here's Arnia's Module 3 project.
https://github.com/isabelle-moura/culture-power
backend bcrypt dotenv express-js jwt mongoose multer node-js typescript
Last synced: 15 days ago
JSON representation
Here's Arnia's Module 3 project.
- Host: GitHub
- URL: https://github.com/isabelle-moura/culture-power
- Owner: Isabelle-Moura
- Created: 2024-01-23T00:08:50.000Z (almost 1 year ago)
- Default Branch: main
- Last Pushed: 2024-04-30T23:04:16.000Z (9 months ago)
- Last Synced: 2024-11-10T15:48:29.474Z (2 months ago)
- Topics: backend, bcrypt, dotenv, express-js, jwt, mongoose, multer, node-js, typescript
- Language: TypeScript
- Homepage: https://project-module-3-production.up.railway.app
- Size: 2.62 MB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ๐Culture Power - Back-End Project Documentation๐
## ๐ท Special Thanks
**๐ Before we start this documentation, _I would love to dedicate this entire project to_:**
- โ **God, Jesus,** and **Blessed Mary**, _that are my light and my safe harbor._ โ
- โค๐ค The most wonderful and beautiful family that I could have: **Mom, Nana, Jessie, Grandpa, and Grandma**. _I love you guys so, so, so badly!_ โค๐ค
- ๐ฆธโโ๏ธ๐ค And last but not least, to all of my amazing teachers that, pretty much, saved my life in this project: **Profยบ Victor de Souto Soares, Profยบ Lucas Perdigรฃo and Monitor Jessie Moura**. ๐ฆธโโ๏ธ๐ค
**Without any of you, _I could never do this project_. Thank you so much!๐๐**
## ๐ท Introduction:
**Culture Power** is a gamification application developed for a company, offering an engaging and interactive experience for users.
The platform revolves around three main entities: **Admin**, **User**, and **Product**, each with specific attributes contributing to the system's dynamics.
## ๐ท Entities and Attributes:
#### ๐น Admin
- **Name:** string
- **Email:** string
- **Password:** string#### ๐น Product
- **Name:** string
- **Value:** number
- **Amount:** number
- **Description:** string
- **Photo:** string#### ๐น User
- **Name:** string
- **Email:** string
- **Password:** string
- **JewelsAmount:** number
- **Products:** Product[]
- **FavoriteProducts:** Product[]
- **Photo:** string## ๐ท Use Cases from Each Functionality:
1. ๐น **User Registration:**
- Required information: name, email, password, photo.
- Does not allow registration if a user with the same email already exists.
- Encrypts the password before storing it in the database.2. ๐น **User Login:**
- Required information: email and password.
- Does not generate a token if there is no user with the provided email.
- Does not generate a token if the sent password does not match the one in the database.
- Generates a token and returns if the credentials are correct.3. ๐น **Admin Login:**
- Required information: email and password.
- Does not generate a token if there is no admin with the provided email.
- Does not generate a token if the sent password does not match the one in the database.
- Generates a token and returns if the credentials are correct.4. ๐น **View Logged-in User (PRIVATE ROUTE):**
- Returns the data of the logged-in user.
5. ๐น **Product Registration (PRIVATE ROUTE - ADMIN):**
- Required information: name, value, quantity, description, and photo.
- Does not allow submission if the user performing the action is not an administrator.6. ๐น **Product Editing (PRIVATE ROUTE - ADMIN):**
- Required information: name, value, quantity, description, and photo.
- Does not allow submission if the user performing the action is not an administrator.7. ๐น **List All Products (PRIVATE ROUTE):**
- Lists products with a quantity greater than 0.
8. ๐น **Search Product by ID (PRIVATE ROUTE):**
- ID must be provided.
- Returns the product if found.9. ๐น **Send Jewel to User (PRIVATE ROUTE - ADMIN):**
- Required information: jewel quantity, user ID.
- Does not allow sending if the user does not exist.
- Does not allow sending if the user performing the action is not an administrator.10. ๐น **Redeem Product (PRIVATE ROUTE):**
- Required information: product ID, user ID.
- Does not allow redemption if the product or user does not exist.
- Does not allow redemption if the user does not have enough jewels.
- Decreases the product value by the jewel quantity.
- Decreases the product quantity.## ๐ท Project Structure:
The project has been organized using the N-Tier architecture, where each entity has its own folder with the following subdivisions:
- **controller:** Manages the control logic of the entity.
- **service:** Contains the business logic of the entity.
- **repository:** Responsible for interacting with the database.
- **dto:** Defines data transfer objects.
- **model:** Represents the structure of the entity.
- **factory:** Creates instances of entities.
- **routes:** Defines the entity's routes in the application.
- **utils:** Contains utilities, including validation with Yup.## ๐ท Tests:
In addition, unit tests have been implemented in each layer (service, repository, and controller) using the framework **Vitest**.
Unit tests are essential for ensuring the reliability and robustness of the system. They validate individual components, ensuring they function as expected. Benefits of unit testing include early bug's detection, facilitates refactoring and saves some headaches.
## ๐ท Postman Exported File:
[Click here](https://github.com/Isabelle-Moura/project-module-3/blob/main/postman-collection.json) to have access to the Postman's routes file.
By going to this file, you'll have to go to the options above and click at the "Download raw file". Then, make sure that you import the downloaded file at your client HTTP request app, like Insomnia or Postman.
## ๐ท Technologies Used in The Project:
The project utilizes the following technologies:
#### ๐น DevDependencies:
- @faker-js/faker: Generates fake data for testing purposes.
- @types/bcrypt: TypeScript type definitions for bcrypt.
- @types/express: TypeScript type definitions for Express.
- @types/jest: TypeScript type definitions for Jest.
- @types/jsonwebtoken: TypeScript type definitions for JSON Web Token.
- @types/multer: TypeScript type definitions for Multer.
- @vitest/coverage-v8: Code coverage tool for V8 JavaScript engine.
- @vitest/ui: UI components for Vitest testing framework.
- tsup: TypeScript module bundler.
- tsx: TypeScript execution environment.
- typescript: TypeScript programming language.#### ๐น Dependencies:
- bcrypt: Library for hashing passwords.
- dotenv: Module for loading environment variables.
- express: Web application framework for Node.js.
- jsonwebtoken: Library for generating and verifying JSON Web Tokens.
- mongoose: MongoDB object modeling for Node.js.
- multer: Middleware for handling file uploads.
- ts-node: TypeScript execution environment for Node.js.
- vitest: Testing framework for JavaScript and TypeScript.
- yup: JavaScript schema builder for value parsing and validation.๐ **Obs: You can find the command to install every dependecy above at the `planning.todo` file.**
## ๐ท Database:
The project utilizes **MongoDB** as the database.
MongoDB is a **NoSQL** database that provides **flexibility and scalability**, making it suitable for applications with evolving requirements.
## ๐ท Commands to Run:
- Starts the development server using tsx watch.
```bash
npm run dev
```- Transpiles code from TS to JS using tsup.
```bash
npm run build
```- Starts the production server using compiled JS.
```bash
npm run start
```- Runs unit tests using Vitest.
```bash
npm run test
```- Seeds the database with initial data using ts-node.
```bash
npm run seed
```- Runs tests with code coverage using Vitest coverage tool.
```bash
npm run coverage
```