A demonstration of microservices architecture using Apollo Federation.
This project implements a federated GraphQL architecture consisting of:
- Gateway: An Apollo Gateway that acts as the single entry point (Supergraph).
- Services: Independent services that compose the supergraph.
users: Manages user data and authentication.
- Clients: Frontend applications consuming the supergraph.
next: A Next.js application using Apollo Client with Automatic Persisted Queries (APQ).
- Node.js
- Yarn
Install dependencies for all workspaces:
yarn installStart the gateway and all services concurrently:
yarn devThis command will:
- Start the
userssubgraph. - Wait for the
usersservice to be ready. - Start the
gateway. - Start the
nextclient.
This project uses Commitizen and Commitlint to ensure standardized commit messages.
To create a commit, stage your changes and run:
yarn commitThis will prompt you to fill in the required fields for a conventional commit message.
Alternatively, you can run Commitizen manually without installation via npx:
npx czTo enforce conventional commits with Husky + commitlint:
yarn add -D @commitlint/cli @commitlint/config-conventional huskygateway/: Apollo Gateway service. Only for local development. Apollo Router will be used in production.services/: Directory containing subgraph services.users/: NestJS-based users subgraph.
clients/: Directory containing frontend applications.next/: Next.js-based client application.- Uses
@apollo/clientfor GraphQL communication. - Implements Automatic Persisted Queries (APQ) to reduce network overhead by sending query hashes instead of full query strings.
- Uses
Minikube is a tool that lets you run Kubernetes locally. It runs a single-node Kubernetes cluster on your personal computer (including Windows, macOS and Linux PCs) so that you can try out Kubernetes, or for daily development work.
You need to have Minikube and Docker installed.
- Docker: Please refer to the official Docker documentation for installation instructions.
- Minikube: Please refer to the official Minikube documentation for installation instructions.
- Minikube: Creates and manages a local Kubernetes cluster on your machine. It sets up a virtual machine (or uses Docker) to run the cluster nodes.
- kubectl: The command-line tool used to communicate with the Kubernetes API. You use it to inspect, manage, and deploy resources to your cluster.
- Docker: The containerization platform. We use it here to build the container images for our services (
usersandgateway) that Minikube will run.
Follow these steps to deploy the services to a local Minikube cluster.
# Start Minikube
yarn minikube:start
# Build images and apply manifests
yarn deploy:up
# Check deployment status
yarn deploy:status
# Restart deployments
yarn deploy:restart
# View logs
yarn deploy:logs:users
yarn deploy:logs:gateway
# Get the Minikube URL for the gateway
yarn deploy:url
# Stop Minikube
yarn minikube:stop
Cluster (Minikube)
└── Nodes (VMs/machines)
└── Pods (smallest deployable units)
└── Containers (your actual apps)