Giter VIP home page Giter VIP logo

jsfest-2019-demo-hexagonal's Introduction

Hexagonal architecture demo

This is practical example of hexagonal architecture in NodeJS with Typescript.

It's a super simple event management app.

Structure

  • /core - application core, all business logic lives here.
  • /primaryAdapters - all adapters which are "use" our core to serve the user. In this example we support only REST API.
  • /secondaryAdapters - all driven adapters, which our core use via Ports. It is connection to 3rd party tools like DB, caches, notification service, SMS provider etc.

Core

/core has 3 main parts:

  • /components - actual app components with business logic. In DDD it usually called Bounded context. Each component is divided into application and domain layers. application is the layer with services which executes logic and communicates with outside world via Ports. domain layer stores our entities, values objects, domain services etc. Also component has port folder which stores component specific Ports. Common example of such port is Repository which communicates with DB (mostly with component specific tables).

  • /port - ports shared by components. It's an interfaces for 3rd party tools, like notification service, SMS service, search engine.

  • /sharedKernel - code that is shared among components. Mostly some utility functions. It should be extractable to an installable module if needed.

Tests

Testing becomes much easier with hexagonal architecture.

I propose 3 types of test which suits different purposes:

  • unit - good old unit tests. Test for the smallest parts of application - services. Test if your core works properly.

  • integration - tests for secondary adapters to check if your integrations with 3rd part tools works.

  • acceptance - kinda integration tests. This is type of test where you test whole app flow with mocked secondary adapters. You start from primary adapter, e.g. sending http request and test how your components works together. Mocking secondary adapters makes them fast to execute. They are harder to write, because you may need a lot of mocks, so recommended to write them for core applications flows.

jsfest-2019-demo-hexagonal's People

Contributors

stormteller avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.