Skip to content

AntonioDev97/api-posts

Repository files navigation

API-POSTS

Architecture

SOLID Singleton architecture with 3 layers / MCM / Monolitic

Structure files

📦api-posts
┣ 📂src
┃ ┣ 📂middlewares
┃ ┃ ┣ 📜apikey.middleware.ts
┃ ┃ ┗ 📜authentication.middleware.ts
┃ ┣ 📂modules
┃ ┃ ┗ 📂v1
┃ ┃ ┃ ┣ 📂controllers
┃ ┃ ┃ ┃ ┣ 📜post.controller.ts
┃ ┃ ┃ ┃ ┗ 📜user.controller.ts
┃ ┃ ┃ ┣ 📂interfaces
┃ ┃ ┃ ┃ ┗ 📜request.interface.ts
┃ ┃ ┃ ┣ 📂middlewares
┃ ┃ ┃ ┃ ┣ 📜post.middleware.ts
┃ ┃ ┃ ┃ ┗ 📜user.middleware.ts
┃ ┃ ┃ ┣ 📂models
┃ ┃ ┃ ┃ ┣ 📜permissions.model.ts
┃ ┃ ┃ ┃ ┣ 📜post.model.ts
┃ ┃ ┃ ┃ ┗ 📜user.model.ts
┃ ┃ ┃ ┣ 📂routes
┃ ┃ ┃ ┃ ┣ 📜post.route.ts
┃ ┃ ┃ ┃ ┗ 📜user.route.ts
┃ ┃ ┃ ┣ 📂test
┃ ┃ ┃ ┃ ┣ 📜post.test.ts
┃ ┃ ┃ ┗ 📂validators
┃ ┃ ┃ ┃ ┗ 📜user.validator.ts
┃ ┣ 📂services
┃ ┃ ┣ 📜jwt.service.ts
┃ ┃ ┣ 📜response-handler.service.ts
┃ ┃ ┣ 📜sequelize.service.ts
┃ ┃ ┣ 📜validator.service.ts
┃ ┃ ┗ 📜winston.service.ts
┃ ┣ 📂utils
┃ ┃ ┗ 📜logger.util.ts
┃ ┗ 📜app.ts
┣ 📜.env
┣ 📜.gitignore
┣ 📜README.md
┣ 📜index.ts
┣ 📜nodemon.json
┣ 📜package-lock.json
┣ 📜package.json
┗ 📜tsconfig.json

Requirements

NodeJS Version: 14.15.4
NPM Version: 6.14.10
MYSQL Version: 8.0.23

Steps

  1. Install NodeJS and MYSQL Server
  2. Set enviroment variables configuration
    • ./.env
  3. Install dependencies
    • npm install
  4. Create Database
    • Run CREATE DATABASE IF NOT EXISTS posts; Script into MYSQL Server
  5. Run project
    • npm run dev (This command automatically CREATES the necessary TABLES into DATABASE) this mode is developer mode if you need to run in production mode please check section "Build and run in JavaScript"
  6. Run seed file Script into MYSQL Server
    • ./seed.sql (This script inserts default data)
  7. You can do requests to API (check down user admin credentials)
    • You can find the postman collection at ./API_POSTS.postman_collection.json
    • You can import the postman enviroment at ./POSTS-LOCAL.postman_environment.json
    • First do login -> /login (credentiales are down).

Admin Credentials

username: admin
password: admin123

Build and run in JavaScript

  • Transform TypeScript to JavaScript with: npm run build this will create a folder ./dist with project in JavaScript
  • Run project in JavaScript with npm start

Unit Test

Run unit test:
- start test: npm run test
- generate coverage report: npm run test-report
You can find the coverage report at ./coverage once generated

Notes:

  • This is a base structure project and continue in development.
  • This effort took about 22 Hours.
  • Unit Tests are in progress but someones are ready!.

About

API Rest made with TypeScript to manage users and posts entities

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages