Node Clean Architecture Template

Preface

Writing highly scalable, testable codebases that are easy to maintain is the dream for most engineers and is some of the problems that software architectures aim to solve.

Software architecture serves as a blueprint for a system. It…


This content originally appeared on DEV Community and was authored by Jamie Livingstone

Preface

Writing highly scalable, testable codebases that are easy to maintain is the dream for most engineers and is some of the problems that software architectures aim to solve.

Software architecture serves as a blueprint for a system. It provides an abstraction to manage the system complexity and establish a communication and coordination mechanism among components.

Having worked in many JavaScript and TypeScript codebases throughout my career, I often find that they do not conform to an established architecture which is very different from more established languages such as C# and is why I decided to build this template.

The template

The template conforms to the Clean Architecture principles and encourages established practices.

Features

  • TypeScript first
  • Dependency injection via Awilix
  • CQRS (Command Query Responsibility Segregation)
  • High test coverage (unit, integration and functional tests)
  • Automatic error handling
  • Logging
  • Versioned APIs
  • Swagger
  • Prisma ORM

GitHub logo JamieLivingstone / node-clean-architecture

A Node template that follows the Clean Architecture principles and encourages good practices.

Clean Architecture Template

A Node template that follows the Clean Architecture principles and encourages good practices.

Features

  • TypeScript first
  • Dependency injection via Awilix
  • CQRS (Command Query Responsibility Segregation)
  • High test coverage (unit, integration and functional tests)
  • Automatic error handling
  • Logging
  • Versioned APIs
  • Swagger
  • Prisma ORM

Getting Started

  1. Install the latest Node.js LTS
  2. Install Docker and ensure that it is running
  3. Create .env file cp .env.example .env
  4. Install project dependencies by running yarn install
  5. Start Docker (local Postgres instance) docker-compose up -d
  6. Create database npx prisma migrate deploy
  7. Start development server yarn start
  8. Navigate to Swagger ( http://localhost:3000/api-docs)

Scripts

Build production bundle

yarn build

Lint project (eslint)

yarn lint

Start development server

yarn start

Run all tests

yarn test

Run unit tests

yarn test:unit

Run functional tests (API tests)

yarn test:functional



Why clean architecture

Clean architecture is a battle-tested software architecture that offers many benefits.

  • Highly Testable: Clean architecture is designed with testing in mind
  • Framework Independent: Doesn’t rely on tools from any specific framework (language agnostic too)
  • Business logic is encapsulated: Easy to add new entry points to the system (e.g. GraphQL)
  • Database Independent: The majority of your application will not know or need to know what database it’s drawing from. This means you can adopt a new database with no changes to the majority of the source code
  • Flexible: Refactoring and maintaining your code will become easier and will demand little effort

Learn more about the architecture by reading this blog post by Robert C. Martin (Uncle Bob).


This content originally appeared on DEV Community and was authored by Jamie Livingstone


Print Share Comment Cite Upload Translate Updates
APA

Jamie Livingstone | Sciencx (2022-04-14T13:04:04+00:00) Node Clean Architecture Template. Retrieved from https://www.scien.cx/2022/04/14/node-clean-architecture-template/

MLA
" » Node Clean Architecture Template." Jamie Livingstone | Sciencx - Thursday April 14, 2022, https://www.scien.cx/2022/04/14/node-clean-architecture-template/
HARVARD
Jamie Livingstone | Sciencx Thursday April 14, 2022 » Node Clean Architecture Template., viewed ,<https://www.scien.cx/2022/04/14/node-clean-architecture-template/>
VANCOUVER
Jamie Livingstone | Sciencx - » Node Clean Architecture Template. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/04/14/node-clean-architecture-template/
CHICAGO
" » Node Clean Architecture Template." Jamie Livingstone | Sciencx - Accessed . https://www.scien.cx/2022/04/14/node-clean-architecture-template/
IEEE
" » Node Clean Architecture Template." Jamie Livingstone | Sciencx [Online]. Available: https://www.scien.cx/2022/04/14/node-clean-architecture-template/. [Accessed: ]
rf:citation
» Node Clean Architecture Template | Jamie Livingstone | Sciencx | https://www.scien.cx/2022/04/14/node-clean-architecture-template/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.