DEV Community

Jamie Livingstone
Jamie Livingstone

Posted on

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 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 established practices.

Clean Architecture Template

License: MIT Test Coverage Maintainability Known Vulnerabilities

A Node template that follows 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

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

License

This project is licensed with the MIT license.

Credits

The project's inspiration is Jason Taylor's clean architecture template

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).

Top comments (2)

Collapse
 
milhod profile image
Milho

Sorry, but the blog link renders a 404 error page

Collapse
 
jamielivingstone profile image
Jamie Livingstone

Sorry about that, I have now updated the link, good spot!