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
infrafolder contains implementations for output ports (postgres database,filesysandapi) - the
corefolder contains all the application (business logic) code - it's simple, but can give you a good idea of how it can look like - the
uifolder has theapiandgraphqlrepresenting input ports - the
dicontainerfolder has a class for eachuiimplementation to say which business logic and output port it should use, making theuilayer 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.examplefile called.envin 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
nodein version 16 or later andnpmoryarnavailable - run
npm installoryarnto install all dependencies - run
npm run ts-node src/ui/api/index.tsto run theexpressserver - run
npm run ts-node src/ui/graphql/index.tsto run thegraphqlserver
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
graphqlapplication, you must run theapiapplication in parallel or change the out port in the GraphQLDIContainer - instead of using the
apiapplication, you can use thejson-serverwith the following command:npm run json-server database.json --routes routes.json