Building Enterprise-grade GraphQL APIs with Domain-Driven Design and Clean Architecture

Rate this content
Bookmark
Slides
The video discusses how to build enterprise-grade GraphQL APIs using domain-driven design (DDD) and clean architecture. It explains the importance of a GraphQL schema for efficient data fetching and improving application performance. Schema merging is used to create a single schema for clients, and the implementation involves technologies like Node.js, Express, TypeScript, Apollo Server, and GraphQL. DDD emphasizes understanding the business domain and using a ubiquitous language for clear communication among stakeholders. Bounded contexts help define logical boundaries within the domain, such as account management and billing management. Clean architecture promotes separation of concerns and easier maintenance, with entities, domain services, and application services forming key components. The talk also highlights the lessons learned, including the need for constant observation and adaptation.

From Author:

In this talk, we will explore how to build scalable and maintainable GraphQL APIs for enterprise applications using Domain-Driven Design and Clean Architecture patterns. We will discuss the importance of modularizing your API around the business domain and better subdomain organization. We will briefly go through the main components of a GraphQL API, including resolvers, domain layer, and database layer and how we've evolved them to our new architecture.

This talk has been presented at React Day Berlin 2023, check out the latest edition of this React Conference.

Watch video on a separate page

FAQ

Peter Ivanov is a developer at the outsourcing consulting company Ant S6, based in Sofia, Bulgaria. He considers himself a T-shaped developer and shares his knowledge through his personal website and newsletter.

The purpose of Peter Ivanov's presentation is to share his experience in building a scalable and maintainable GraphQL API by embracing TypeScript, domain-driven design (DDD), and clean architecture.

A T-shaped developer is a professional who has deep knowledge in a specific area (the vertical bar of the 'T') and a broad understanding of general skills (the horizontal bar of the 'T'). Peter Ivanov has written a blog post about it on his personal website.

Backstadium.com is a service similar to DigitalOcean or AWS for Mac infrastructure. It allows users to run applications on virtual Mac hardware without purchasing the physical Mac.

GraphQL was chosen for its ability to serve as a central place for all business-related logic, making it easier to refactor and improve the design of the database and overall architecture.

The technologies used include Node.js, Express, TypeScript, Apollo Server, and GraphQL.

Domain-driven design (DDD) emphasizes the importance of understanding the business domain and helps teams focus on core business logic. It ensures that software aligns with business requirements through concepts like ubiquitous language and bounded contexts.

Clean architecture is a layered architecture pattern that allows for better separation of concerns, making the codebase easier to test and maintain. Each layer points inward, ensuring a single flow of dependencies.

Key components include entities, domain services, application services, repositories, GraphQL schema, GraphQL resolvers, and module APIs. Each bounded context, such as account management and billing management, defines its own structure.

Some lessons learned include the difficulty of getting it right from the beginning, the importance of scheduling time for paying off technical debt, and the need to adapt DDD and clean architecture principles to suit specific needs and experiences.

Petar Ivanov
Petar Ivanov
22 min
12 Dec, 2023

Comments

Sign in or register to post your comment.

Video Transcription

1. Introduction to Building GraphQL APIs

Short description:

Today, I'm going to talk about building enterprise-grade GraphQL APIs with domain-driven design and clean architecture. I'll share my experience of building a scalable and maintainable GraphQL API by embracing TypeScript, domain-driven design, and clean architecture. You can find me on social media and check out my blog and newsletter. I work for Ant, S6, an outsourcing consulting company based in Sofia, Bulgaria.

Hello everyone. I'm Peter, and today I'm going to talk about building enterprise-grade GraphQL APIs with domain-driven design and clean architecture. So a few words about myself. So as I said, I'm Peter Ivanov. Here is my handle, so you can find me on social media with this handle. And I also consider myself as a T-shaped developer. If you're not sure what's a T-shaped developer, you can check one of my latest blog posts on my personal website, peterivanov.me. And I also have a newsletter, the T-Shaped Dev. So if you're interested, you can check it out. And yeah, here are my links to LinkedIn and my GitHub account. I'm Ant, S6 is the company that I'm working for. We are an outsourcing consulting company based here in Sofia, Bulgaria. And the purpose of my presentation is to share my experience of building a scalable and maintainable GraphQL API by embracing TypeScript, domain-driven design and clean architecture.

2. Introduction to Architecture and GraphQL API

Short description:

Don't take everything I share in this presentation as absolute. We won't go into much detail about what's GraphQL, DDD and clean architecture. We are talking about backstadium.com, think of it like DigitalOcean or AWS for Mac infrastructure. Let's start with the first version of our architecture, two web applications, one public and one internal. The second version is the current version, with the whole business logic inside the GraphQL API. The GraphQL API is the central place for all business related logic. We have a single user, the GraphQL API, which makes it easier to refactor and improve the design of the whole database.

And I would like to start with a few disclaimers. And the first one is that don't take everything I share in this presentation as absolute, because software can be built in multiple ways. And also, since we have only 20 minutes for this presentation, we won't go into much detail about what's GraphQL, DDD and clean architecture, because we will focus on how to design and build our API.

And now, a few words about it to give you some context and what kind of software and what kind of business we are talking about. So we are talking about backstadium.com, and you can think of it like DigitalOcean or AWS for Mac infrastructure. So if you don't want to buy the physical Mac, the actual hardware, but you want to run something on Mac, you can go there and you can purchase virtually the Mac and its infrastructure. So basically, we have the same things that we have in DigitalOcean or AWS. So we have billing, we have accounts, companies, users and stuff like that. So just to give you what kind of context and what kind of software we are going to be building and we are going to talk about throughout the presentation.

And now let's start with the first version of our architecture. And here it is. So we have two web applications, one public and one internal. The public one is built with React, KXPHP, and the other one is built only with KXPHP. And those two services call directly either the database or third-party services. Very, very simple one. And now let's move to the second version of the architecture, and this is the current version of the architecture. And here it is. Again, we have those two web applications, but now the whole business logic is inside the so-called the GraphQL API. And here you can see the GraphQL API. We have some account management, billing management, you'll see what it is. And here we have the API which calls the database or third-party services. Don't worry. Now we're going to drill down and explore how we actually managed to accomplish this and how we did it.

The first question that we have to answer is why we need the GraphQL API and what's its purpose. And one of the core reasons is that it's the central place for all business related logic. This is the GraphQL API. And also in this, by introducing the GraphQL API, we have in this case the database. We have a single user, in our case the GraphQL API, which will make it easier to refactor and improve the design of the whole database. As you saw in the first version of architecture, we had two clients, but most of the time they are more old. And now a few words about technologies that we decided to use.

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

From GraphQL Zero to GraphQL Hero with RedwoodJS
GraphQL Galaxy 2021GraphQL Galaxy 2021
32 min
From GraphQL Zero to GraphQL Hero with RedwoodJS
Top Content
Tom Pressenwurter introduces Redwood.js, a full stack app framework for building GraphQL APIs easily and maintainably. He demonstrates a Redwood.js application with a React-based front end and a Node.js API. Redwood.js offers a simplified folder structure and schema for organizing the application. It provides easy data manipulation and CRUD operations through GraphQL functions. Redwood.js allows for easy implementation of new queries and directives, including authentication and limiting access to data. It is a stable and production-ready framework that integrates well with other front-end technologies.
Local State and Server Cache: Finding a Balance
Vue.js London Live 2021Vue.js London Live 2021
24 min
Local State and Server Cache: Finding a Balance
Top Content
This Talk discusses handling local state in software development, particularly when dealing with asynchronous behavior and API requests. It explores the challenges of managing global state and the need for actions when handling server data. The Talk also highlights the issue of fetching data not in Vuex and the challenges of keeping data up-to-date in Vuex. It mentions alternative tools like Apollo Client and React Query for handling local state. The Talk concludes with a discussion on GitLab going public and the celebration that followed.
Batteries Included Reimagined - The Revival of GraphQL Yoga
GraphQL Galaxy 2021GraphQL Galaxy 2021
33 min
Batteries Included Reimagined - The Revival of GraphQL Yoga
Envelope is a powerful GraphQL plugin system that simplifies server development and allows for powerful plugin integration. It provides conformity for large corporations with multiple GraphQL servers and can be used with various frameworks. Envelope acts as the Babel of GraphQL, allowing the use of non-spec features. The Guild offers GraphQL Hive, a service similar to Apollo Studio, and encourages collaboration with other frameworks and languages.
Rock Solid React and GraphQL Apps for People in a Hurry
GraphQL Galaxy 2022GraphQL Galaxy 2022
29 min
Rock Solid React and GraphQL Apps for People in a Hurry
The Talk discusses the challenges and advancements in using GraphQL and React together. It introduces RedwoodJS, a framework that simplifies frontend-backend integration and provides features like code generation, scaffolding, and authentication. The Talk demonstrates how to set up a Redwood project, generate layouts and models, and perform CRUD operations. Redwood automates many GraphQL parts and provides an easy way for developers to get started with GraphQL. It also highlights the benefits of Redwood and suggests checking out RedwoodJS.com for more information.
Adopting GraphQL in an Enterprise
GraphQL Galaxy 2021GraphQL Galaxy 2021
32 min
Adopting GraphQL in an Enterprise
Today's Talk is about adopting GraphQL in an enterprise. It discusses the challenges of using REST APIs and the benefits of GraphQL. The Talk explores different approaches to adopting GraphQL, including coexistence with REST APIs. It emphasizes the power of GraphQL and provides tips for successful adoption. Overall, the Talk highlights the advantages of GraphQL in terms of efficiency, collaboration, and control over APIs.
Step aside resolvers: a new approach to GraphQL execution
GraphQL Galaxy 2022GraphQL Galaxy 2022
16 min
Step aside resolvers: a new approach to GraphQL execution
GraphQL has made a huge impact in the way we build client applications, websites, and mobile apps. Despite the dominance of resolvers, the GraphQL specification does not mandate their use. Introducing Graphast, a new project that compiles GraphQL operations into execution and output plans, providing advanced optimizations. In GraphFast, instead of resolvers, we have plan resolvers that deal with future data. Graphfast plan resolvers are short and efficient, supporting all features of modern GraphQL.

Workshops on related topic

Build with SvelteKit and GraphQL
GraphQL Galaxy 2021GraphQL Galaxy 2021
140 min
Build with SvelteKit and GraphQL
Top Content
Featured WorkshopFree
Scott Spence
Scott Spence
Have you ever thought about building something that doesn't require a lot of boilerplate with a tiny bundle size? In this workshop, Scott Spence will go from hello world to covering routing and using endpoints in SvelteKit. You'll set up a backend GraphQL API then use GraphQL queries with SvelteKit to display the GraphQL API data. You'll build a fast secure project that uses SvelteKit's features, then deploy it as a fully static site. This course is for the Svelte curious who haven't had extensive experience with SvelteKit and want a deeper understanding of how to use it in practical applications.

Table of contents:
- Kick-off and Svelte introduction
- Initialise frontend project
- Tour of the SvelteKit skeleton project
- Configure backend project
- Query Data with GraphQL
- Fetching data to the frontend with GraphQL
- Styling
- Svelte directives
- Routing in SvelteKit
- Endpoints in SvelteKit
- Deploying to Netlify
- Navigation
- Mutations in GraphCMS
- Sending GraphQL Mutations via SvelteKit
- Q&A
Build Modern Applications Using GraphQL and Javascript
Node Congress 2024Node Congress 2024
152 min
Build Modern Applications Using GraphQL and Javascript
Featured Workshop
Emanuel Scirlet
Miguel Henriques
2 authors
Come and learn how you can supercharge your modern and secure applications using GraphQL and Javascript. In this workshop we will build a GraphQL API and we will demonstrate the benefits of the query language for APIs and what use cases that are fit for it. Basic Javascript knowledge required.
End-To-End Type Safety with React, GraphQL & Prisma
React Advanced Conference 2022React Advanced Conference 2022
95 min
End-To-End Type Safety with React, GraphQL & Prisma
Featured WorkshopFree
Sabin Adams
Sabin Adams
In this workshop, you will get a first-hand look at what end-to-end type safety is and why it is important. To accomplish this, you’ll be building a GraphQL API using modern, relevant tools which will be consumed by a React client.
Prerequisites: - Node.js installed on your machine (12.2.X / 14.X)- It is recommended (but not required) to use VS Code for the practical tasks- An IDE installed (VSCode recommended)- (Good to have)*A basic understanding of Node.js, React, and TypeScript
GraphQL for React Developers
GraphQL Galaxy 2022GraphQL Galaxy 2022
112 min
GraphQL for React Developers
Featured Workshop
Roy Derks
Roy Derks
There are many advantages to using GraphQL as a datasource for frontend development, compared to REST APIs. We developers in example need to write a lot of imperative code to retrieve data to display in our applications and handle state. With GraphQL you cannot only decrease the amount of code needed around data fetching and state-management you'll also get increased flexibility, better performance and most of all an improved developer experience. In this workshop you'll learn how GraphQL can improve your work as a frontend developer and how to handle GraphQL in your frontend React application.
Build a Headless WordPress App with Next.js and WPGraphQL
React Summit 2022React Summit 2022
173 min
Build a Headless WordPress App with Next.js and WPGraphQL
Top Content
WorkshopFree
Kellen Mace
Kellen Mace
In this workshop, you’ll learn how to build a Next.js app that uses Apollo Client to fetch data from a headless WordPress backend and use it to render the pages of your app. You’ll learn when you should consider a headless WordPress architecture, how to turn a WordPress backend into a GraphQL server, how to compose queries using the GraphiQL IDE, how to colocate GraphQL fragments with your components, and more.
Relational Database Modeling for GraphQL
GraphQL Galaxy 2020GraphQL Galaxy 2020
106 min
Relational Database Modeling for GraphQL
Top Content
WorkshopFree
Adron Hall
Adron Hall
In this workshop we'll dig deeper into data modeling. We'll start with a discussion about various database types and how they map to GraphQL. Once that groundwork is laid out, the focus will shift to specific types of databases and how to build data models that work best for GraphQL within various scenarios.
Table of contentsPart 1 - Hour 1      a. Relational Database Data Modeling      b. Comparing Relational and NoSQL Databases      c. GraphQL with the Database in mindPart 2 - Hour 2      a. Designing Relational Data Models      b. Relationship, Building MultijoinsTables      c. GraphQL & Relational Data Modeling Query Complexities
Prerequisites      a. Data modeling tool. The trainer will be using dbdiagram      b. Postgres, albeit no need to install this locally, as I'll be using a Postgres Dicker image, from Docker Hub for all examples      c. Hasura