Skip to content

pedromoraisf/hexagonal-architecture-distilled

Repository files navigation

Hexagonal Architecture Distilled in JavaScript

The guide to understand Hexagonal Architecture (a.k.a Ports and Adapters) in JavaScript.

Click here to see my publication on my blog →


ℹ️ This publication is being maintained right now. This means that some topics may be out of date.

Presentation

This is a sample repository for my "Hexagonal Architecture Distilled in JavaScript" publication.

The code writing style was motivated by the familiarity of JavaScript programmers.

The design was as simple as possible in order not to obscure the practical examples of Hexagonal Architecture concepts.

I suggest that the consumer of this content does not get attached to peripheral concepts (Decorator design pattern, etc). Focus on Ports and Adapters!

Glossary

Component Vision of the Ports and Adapters

The diagram below is designed to be familiar with the C4 pattern component diagram.

How to Run

Local:

  • Install Node.js >= 14
  • Open this repo and install dependencies
  • Run: npm run start

Docker 🐳:

  • Having the node installed, open this repo and run: npm run docker:up
  • If you want to disassemble the composition, run: npm run docker:down

How to Test

Unit and Integration:

  • Unitary tests, run: npm run test:unit
  • Integration tests, run: npm run test:integration
  • Both tests, run: npm run test

e2e:

  • Having the environment mounted (both local or docker), run: npm run test:create-a-post and copy the "_id" returned property
  • Input above returned property in TESTABLE_POST_ID variable on e2e/docker/get-a-specific-post.test.js and run: npm run test:get-a-specific-post
  • Input above returned property in TESTABLE_POST_ID variable on e2e/docker/edit-a-specific-post.test.js and run: npm run test:edit-a-specific-post
  • Run: npm run test:list-all-posts