JK
Projecten
JK
>LADEN // LADEN
WEERGAVE INITIALISEREN
Gebouwd en ontworpen doorJK
JK
>LADEN // PROJECT DETAILS
PARSING ARCHITECTURE, DIAGRAMS & API ENDPOINTS
Terug naar projecten
Bekijk op GitHub
Microservices Backend
Voltooidnestjspostgrestypescriptjesteslintdockergithubactionspostmanswagger

Microservices Backend

Microservices-architectuur met NestJS, PostgreSQL en Docker, aangestuurd via een centrale API Gateway.

Probleem en oplossing

Ontkoppeling van routing (API Gateway), bedrijfslogica (afzonderlijke services) en dataopslag voor onafhankelijke implementatie en schaalbaarheid.

Functies

  • Onafhankelijke microservices voor Producten en Bestellingen
  • API Gateway voor gecentraliseerde routering en beveiliging
  • PostgreSQL-database georkestreerd met Docker Compose
  • Monorepo-structuur met TurboRepo
  • CI/CD via GitHub Actions met automatische Docker Hub-implementatie
  • Uitgebreide unit tests met Jest

Technologiestack

TechnologieVersieDoelWaarom gekozen
TypeScript^5.7.3Primary language for all servicesType safety, NestJS ecosystem standard
NestJS^11.0.1Application frameworkModular architecture, dependency injection, TypeScript-first
TypeORM^0.3.27ORM for PostgreSQL accessActive Record/Repository pattern, NestJS integration
PostgreSQL15Primary databaseJSONB support, ACID compliance, reliability
Docker—Containerization for all servicesConsistent environments, reproducible deployments
Turborepo^2.5.8Monorepo task orchestrationFast parallel builds, caching, npm workspaces integration
GitHub Actions—CI/CD pipeline executionFree for public repos, tight Git integration
Jest^30.0.0Unit testing frameworkNestJS default, snapshot support
Swagger^11.2.0API documentationAuto-generates OpenAPI from decorators

Architectuur

Client

API Gateway

:3000

Products Service

:3001

Orders Service

:3002

PostgreSQL

:5432
Press enter or space to select a node. You can then use the arrow keys to move the node around. Press delete to remove it and escape to cancel.
Press enter or space to select an edge. You can then press delete to remove it or escape to cancel.

Core System Components

  • API Gateway for routing requests to internal services
  • Products & Orders service as independent NestJS services
  • Docker Compose orchestration
  • PostgreSQL container

Infrastructure

  • GitHub Actions CI (lint, test, build)
  • Docker Hub CD image deployment
  • Environment variable management

Projectstructuur

.github
workflows
apps
api-gateway
orders-service
products-service
libs
common
docker-compose.ymlOrchestrates all services and PostgreSQL database

API-endpoints

API Gateway (poort 3000)

MethodeRouteDoel
GET/productsList all products
GET/products/:idGet product by ID
POST/productsCreate product
PATCH/products/:idUpdate product
DELETE/products/:idDelete product
GET/ordersList all orders
GET/orders/:idGet order by ID
POST/ordersCreate order

Products Service (poort 3001)

MethodeRouteDoel
POST/productsCreate product
GET/productsList all products
GET/products/:idGet product by ID
PATCH/products/:idUpdate product
DELETE/products/:idDelete product

Orders Service (poort 3002)

MethodeRouteDoel
POST/ordersCreate order
GET/ordersList all orders
GET/orders/:idGet order by ID

Databaseontwerp

product

6 cols
idPK
SERIAL
code
VARCHAR
name
VARCHAR
description
VARCHAR
price
DECIMAL
image
VARCHAR

order

4 cols
idPK
SERIAL
customer
JSONB
products
JSONB
totalAmount
DECIMAL
Press enter or space to select a node. You can then use the arrow keys to move the node around. Press delete to remove it and escape to cancel.
Press enter or space to select an edge. You can then press delete to remove it or escape to cancel.

product

KolomTypeNotities
idPKSERIALAuto-generated primary key
codeVARCHARProduct SKU/code
nameVARCHARProduct display name
descriptionVARCHARProduct description
priceDECIMALProduct price
imageVARCHARImage URL

No explicit indexes beyond primary key. No unique constraints on code.

order

KolomTypeNotities
idPKSERIALAuto-generated primary key
customerJSONBStores {name, phone}
productsJSONBArray of {id, name, rate, qty}
totalAmountDECIMALTotal order amount

Products stored as JSONB snapshot — intentional denormalization. No foreign keys to product table.

No foreign key relationships. Order.products is a JSONB snapshot — orders are self-contained records that do not reference the product table. Product price changes do not affect existing orders.

Belangrijkste ontwerpbeslissingen

Shared PostgreSQL Database

Beslissing: Both services connect to the same PostgreSQL instance and database (procura_db)

Waarom: Simplifies development and deployment — one database to manage

Voordelen: Simpler infrastructure, lower resource usage, easier local development

Afwegingen: Violates database-per-service principle, creates hidden coupling, makes independent scaling harder

JSONB for Order Products

Beslissing: Order entity stores product data as JSONB rather than foreign key references

Waarom: Decouples order data from product lifecycle — orders are immutable snapshots

Voordelen: Orders are self-contained, product changes don't affect historical orders

Afwegingen: No referential integrity, data duplication, no automatic product validation on order creation

API Key Authentication

Beslissing: Simple static API key in x-api-key header, compared against environment variable

Waarom: Simplest possible authentication for demonstration purposes

Voordelen: Minimal implementation, no token management, no state

Afwegingen: No user identity, no fine-grained permissions, key is static and shared

HTTP-based Inter-service Communication

Beslissing: API Gateway communicates with downstream services via synchronous HTTP (Axios)

Waarom: Simplest approach for synchronous request-response pattern

Voordelen: Easy to understand, debug, and test; standard HTTP tooling

Afwegingen: Synchronous coupling, no retry/circuit breaker, no async processing

Multi-stage Docker Builds

Beslissing: Each service uses a 3-stage Dockerfile (deps → builder → runner)

Waarom: Minimizes final image size and attack surface

Voordelen: Production images contain only runtime dependencies and compiled code

Afwegingen: Build time for each stage, no layer caching optimization for src changes

TypeORM synchronize: true

Beslissing: Both services use synchronize: true in TypeORM config

Waarom: Auto-creates/updates database schema from entities during development

Voordelen: No migration files needed, schema stays in sync with code

Afwegingen: Dangerous in production — can cause data loss on schema changes

Tests

Jest ^30.0.0 with ts-jest ^29.2.5•34 unittests

Wat wordt getest

  • API Gateway: root health check, all proxy operations (products + orders)
  • Products Service: controller methods (create, findAll, findOne, update, remove)
  • Products Service: service methods (create, findAll, findOne, update, remove)
  • Orders Service: controller methods (create, findAll, findOne, id conversion)
  • Orders Service: service methods (create, findAll, findOne)

Ontbrekende dekking

  • Integration tests with real database
  • API Gateway ↔ Service integration tests
  • Middleware tests for API key validation
  • Validation error scenario tests
  • Error path tests (404, 500 scenarios)

Belangrijkste uitdagingen

  • Coordinating multiple services while ensuring fault isolation
  • Setting up CI/CD pipelines for multi-image Docker builds
  • Managing environment variables cleanly inside Docker

Belangrijkste lessen

  • Effective use of API Gateway pattern
  • Advanced Docker container orchestration with dependencies
  • Dependency isolation using monorepo tooling (TurboRepo)