This is a simple example of Hexagonal Architecture in Node.js using TypeScript. I made this example to show how to implement the Hexagonal Architecture in Node.js using TypeScript with my underestanding of the concept.
Hexagonal Architecture is an architectural pattern that helps us to create applications that are more independent of the external world. It is also known as Ports and Adapters Architecture or Onion Architecture.
pre-requisites:
- Node.js
- npm
- prisma =>
npm install -g prisma
-
Clone the repository
-
Run
npm install
-
cd into the
src/infrastructure/db
folder
cd src/infrastructure/db
npx prisma migrate dev --name init
-
Run
npm run start
to start the application -
Run
npm run test
to run the tests
this is the list of the usecases that the application supports,this usecases will be changed in the future to be more realistic.
I want to create a user with the following data:
- name
- password
{
"name": "John Doe",
"email": "[email protected]",
"password": "123456"
}
I want to authenticate a user with the following data:
- password
{
"email": "[email protected]",
"password": "123456"
}
I want to create a post with the following data:
- title
- content
{
"title": "My first post",
"content": "This is my first post",
}