That's a simple project that presents an implementation for multiple input and output ports following the hexagonal architecture :).
In this one I implemented somethings with Accounts, Foods and Demands. You can see the database.json to have an idea about what entities this project consider.
I've made some implementations focusing to show how the hexagonal architecture works with multiple input (user interface) and output (infrastructure) ports using the same application (core - business logic) code.
There are some interesting things inside the src
folder:
- the
infra
folder contains implementations for output ports (postgres database
,filesys
andapi
) - the
core
folder contains all the application (business logic) code - it's simple, but can give you a good idea of how it can look like - the
ui
folder has theapi
andgraphql
representing input ports - the
dicontainer
folder has a class for eachui
implementation to say which business logic and output port it should use, making theui
layer agnostic about what is after the business logic wall.
To run some of these application, please follow the steps below:
- clone the repo with
git clone https://github.com/wallrony/hexagonal-architecture
- create a copy of the
.env.example
file called.env
in the root of the project and fill it with an available postgres database - use the tools/migrations/0001_init.sql to create the database and the tables
- make sure you have
node
in version 16 or later andnpm
oryarn
available - run
npm install
oryarn
to install all dependencies - run
npm run ts-node src/ui/api/index.ts
to run theexpress
server - run
npm run ts-node src/ui/graphql/index.ts
to run thegraphql
server
NOTES:
- you need to run the commands shown above in the root of the project
- the GraphQLDIContainer is using the API out port. So if you want to use the
graphql
application, you must run theapi
application in parallel or change the out port in the GraphQLDIContainer - instead of using the
api
application, you can use thejson-server
with the following command:npm run json-server database.json --routes routes.json