Clean Architecture Nodejs Graphql Codegen

Clean Architecture Nodejs Graphql Codegen

This is an example of backend implementation by Node.js for the purpose of learning Clean Architecture.An implementation example of GraphQL backend by Node.js and frontend by Next.js for learning Clean Architecture.


This is an example of backend implementation by Node.js for the purpose of learning Clean Architecture.


The TODO app is provided as a specific example.

Operation check


  • Requires docker-compose and node.js
  • I'm using yarn
  • Since it is necessary to build the dependent files in advance, build it once as well.
yarn build
yarn docker
yarn db:migrate
yarn db:seed


yarn dev


yarn fix
yarn test
  • fix = typecheck(tsc) + lint(eslint) + format(prettier)
  • test = is (ts-is)


yarn build
yarn start

Project structure

It has a Monorepo structure, and the projects are divided according to roles.

By explicitly separating the projects, it has the meaning of enforcing Clean Architecture.

  • common
  • Commonly used by all projects, such as custom error objects
  • schema
  • Describe the project-wide schema and API configuration in a .graphql file
  • graphql-codegen automatically generates DTO, schema, resolver type information from graphql file
  • domain-model
  • Implement domain layer and usecase layer
  • Write only business logic, independent of specific backend implementation
  • backend
  • Implement interface layer and infrastructure layer
  • Uses TypeORM for persistence layer operations and provides GraphQL API as a web server
  • frontend (WIP)
  • Implementing frontend in React (Next.js)
  • Currently only supports login / logout, Done / Undone and CreateTodo use cases



GraphQL schema defines the contract between frontend and backend. Technically, the graphql file specifies the data type (type, input, enum) and API (query, mutation).

Automatic generation of TypeScript type information by graphql-codegen

graphql-codegen outputs TypeScript type information from graphql file. Since not only the entity type but also the functional type information of the resolver is output, it is possible to develop while maintaining high type safety.

Also, based on this schema information, it is possible to generate type information optimized for Apollo Client on the front end side as well. In addition to expecting DX improvement through code completion, high-quality service development protected by type information can be expected.


It implements the business logic that is the core of the project, and implements value-object, entity, usecase, etc. as elements for that. It also exposes the repository, presenter, and usecase interfaces for the outer layers.

Write only business logic, independent of specific backend implementation

The use case is complete within the domain-model, and the implementation is such that the use case holds even if there is no outer layer. In fact, the backend project only implements a usecase for business logic via the controller.

We use tests to verify the correctness of behavior. The outer layer (repository, presenter) uses a mock to check mainly the core state transitions and validations expected for usecases.


Since the core business logic is provided by the domain-model side, the main purpose of this project is to work with external layers. Specifically, we provide a server implementation that supports GraphQL and a persistence layer.

Use TypeORM to manipulate persistence layer

MySQL (Docker) is used for the persistence layer, and the repository pattern is implemented by TypeORM. TypeORM is very suitable for Clean Architecture because it provides a repository pattern as standard. It's a slapstick, but migration is excellent, and it's very easy because it automatically generates a migration file by looking at the difference between the ORM code and the DB.

Download Details:

Author: suzukalight

Source Code:

nodejs node javascript

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Node canvas is a Cairo backed Canvas implementation for NodeJS.

node-canvas is a Cairo-backed Canvas implementation for Node.js.

How to Hire Node.js Developers And How Much Does It Cost?

A Guide to Hire Node.js Developers who can help you create fast and efficient web applications. Also, know how much does it cost to hire Node.js Developers.

Hire NodeJs Developer

Looking to build dynamic, extensively featured, and full-fledged web applications? **[Hire NodeJs Developer]( "Hire NodeJs Developer")** to create a real-time, faster, and scalable...

Decoding Nodejs

The main goal of this blog is to explain the “Architecture of Nodejs” and to know how the Nodejs works behind the scenes. Generally, most of the server-side languages, like PHP, ASP.NET, Ruby, and including Nodejs follows multi-threaded architecture. That means for each client-side request initiates a new thread or even a new process.

Node.js for Beginners - Learn Node.js from Scratch (Step by Step)

Node.js for Beginners - Learn Node.js from Scratch (Step by Step) - Learn the basics of Node.js. This Node.js tutorial will guide you step by step so that you will learn basics and theory of every part. Learn to use Node.js like a professional. You’ll learn: Basic Of Node, Modules, NPM In Node, Event, Email, Uploading File, Advance Of Node.