Skip to content

Node.js RESTful API with Express.js, Typescript, TypeORM and Postgres. Following the clean architecture way!!

License

Notifications You must be signed in to change notification settings

ayoubhr/central-system-api

Repository files navigation

Central System Api

NodeJS Express.js TypeScript Postgres Docker

This project consists of a NodeJS RESTful API that serves two domains:
  • Organizations.

  • Chargepoints.

Important Notes

  • If you run Docker-compose use "make up" in wsl, check Makefile for context.

  • The Docker-compose container is slow in build up, bear with it please.

  • There is a Postman collection (if you prefer this) in root directory with the endpoints and a few skeletons on how request bodies should look like.

  • You can also run the application locally with NPM, instruction below.

Structure of the application

Lously coupled API following a domain driven design architecture split into different layers following the "Inversion of Control" principle (Onion Architecture), where implementations (outer layers) depend upon specifications (inner layers).

Image

  • Domain: holds the entities folder with the Domain objects Organization and Chargepoint. It is also the place where the specification of the CRUD operations sits (later implemented in the outer layers).

  • Application: this is the use-case layer of the API where both the bussiness logic layer (services) and the CRUD operations interfaces (previously mentioned) are implementated. The Datasource needed to run operation on the database is also set here.

  • Infrastructure: outer layer where the routing layer sits, here is where the controller endpoint classes are implemented. Input data from the Request object is validated on each route with the correspondant DTO object before accessing the Service layer.

Relevant commands to run the Docker container:
  • npm run docker: transpiles the typescript application into a javascript module in the /dist folder and then runs the application on localhost. Datasource host on this command is set as "pg_container" to properly build the image. This command is run automatically inside the docker-compose container.

  • make up: Make script that builds the docker compose image of the application and runs it in localhost:5000.

  • make down: Make script that shuts down the current running docker compose container.

Make is a Linux CLI tool to run scripts easly. If you don't have it installed just go inside the "Makefile" that is sitting on the root folder and get the docker-compose command to run from there.

How to launch with Docker:
  1. Run --> make up.
Relevant commands to run locally:
  • npm run dev: runs ts-node + nodemon on index.ts for development purposes.

  • npm start: transpiles the typescript application into a javascript module in the /dist folder and then runs the application on localhost.

Application is launched in PORT 5000 (localhost:5000 if you wanna try in local).

How to launch locally:
  1. Run --> npm install.
  2. Make sure a Postgres server is setup.
  3. Run --> npm run dev or npm start.

TODO LIST:

  • Testing.
  • Swagger implementation.

About

Node.js RESTful API with Express.js, Typescript, TypeORM and Postgres. Following the clean architecture way!!

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages