Skip to content
CAI
Software that uses CAICheck a score

Baroshem/microservice-template

49.2

Weak · 7 October 2026

831

lines of production code

TypeScript

primary language

4

measurements over time

CAI band scale
CAI trend line
CAI lens gauges

What this system is

This system is a NestJS-based microservice designed to manage item lifecycles through a Domain-Driven Design architecture. It communicates via RabbitMQ and implements CQRS to separate command and query operations, while leveraging an Event Store to handle domain events and sagas for asynchronous business logic. The service persists data using TypeORM and includes built-in health monitoring and standardized error handling.

Features

Add Microservice Health Check Module

A new health check module has been introduced to monitor the microservice's state. This includes a HealthModule that wraps TerminusModule and ScheduleModule, and a HealthService that performs automated checks every 30 minutes for TypeORM connectivity, disk storage usage (threshold 90% on root path), and memory consumption (heap and RSS limits of 150MB). The module also includes unit tests for the HealthService.

src/health · high confidence

Added CQRS command definitions and handlers for item management

This change introduces the application-layer implementation for item commands within the \src/item/application/commands\ directory. It defines four specific commands—CreateItem, UpdateItem, DeleteItemById, and NotifyItemOwner—along with their corresponding handlers. The NotifyItemOwner handler is wired to react to domain events (ItemCreated, ItemUpdated, ItemDeleted) to notify the item owner, while the other handlers manage the core item lifecycle. Unit tests have been added to verify the instantiation and basic behavior of these commands and the notification handler.

src/item/application/commands · high confidence

Added application-layer DTOs for item operations

Introduced data transfer objects in the application layer to standardize input for item management: CreateItemDto for creating items by name, UpdateItemDto for modifying items by ID and name, and GetItemsDto for querying items with limit and order parameters. Unit tests were added to verify the instantiation of these DTOs.

src/item/application/dtos · high confidence

Added domain events and handlers for item lifecycle

This change introduces the domain event definitions and their corresponding handlers for the item module, supporting the Create, Update, Delete, and Owner Notified operations. The diff adds event classes (ItemCreatedEvent, ItemUpdatedEvent, ItemDeletedEvent, ItemOwnerNotifiedEvent) implementing NestJS CQRS IEvent, along with handler classes (ItemCreatedHandler, ItemUpdatedHandler, ItemDeletedHandler, ItemOwnerNotifiedHandler) that process these events. It also includes a centralized index for exporting handlers and unit tests for all event and handler implementations to verify correct instantiation and basic handling logic.

src/item/domain/events · high confidence

Added item query definitions and handler registry

This change introduces the application-layer query classes for retrieving items, specifically \GetItemByIdQuery\ and \GetItemsQuery\, along with their corresponding handler registry. It also includes unit tests verifying the instantiation of these query objects, establishing the foundational structure for CQRS read operations within the item module.

src/item/application/queries · high confidence

Establishes the Item domain module with event sourcing infrastructure

The \src/item/domain\ location now contains the core domain module (\DomainModule\) which registers the \EventStoreModule\ to handle item-related events (\ItemCreated\, \ItemUpdated\, \ItemDeleted\, \ItemOwnerNotified\) via catch-up subscriptions on the \$ce-item\ stream. This module provides the \ItemRepository\ and \ItemSagas\ as providers, exports the repository for use by other layers, and organizes domain logic into \events\, \models\, \repositories\, \sagas\, and \types\ directories, effectively centralizing the business rules and reactive behavior for items.

src/item/domain · high confidence

Introduce global TypeORM database module with async configuration

The src/database directory now provides a DatabaseModule that wraps TypeOrmModule.forRootAsync, using a new TypeOrmConfigService to handle connection settings asynchronously. This module is marked as Global, making the TypeORM connection available across the application without requiring explicit imports in other modules. The directory also includes helper utilities for database error validation and a README documenting the module's structure.

src/database · high confidence

New Event Store configuration and wrapper module

The application now includes a dedicated event-store module that wraps the \@juicycleff/nestjs-event-store\ library. This module provides a global NestJS module (\EventStoreWrapperModule\) that registers the event store using configuration values sourced from environment variables (hostname, TCP port, and credentials). The configuration is managed by \EventStoreConfigService\, which sets default retry, reconnection, and heartbeat parameters for the connection.

src/event-store · high confidence

New database error validation helper

The src/database/helpers module now includes a validateDbError utility that translates database error codes into standardized HTTP exception objects. It maps the UniqueViolation code (23505) to a 409 Conflict response with the message 'Duplicated entry', while defaulting all other errors to a 400 Bad Request. This helper is supported by new DbErrorCodes and IErrorObject definitions to ensure consistent error handling across the application.

src/database/helpers · high confidence

New infrastructure module for TypeORM persistence

A new InfrastructureModule has been introduced to manage data persistence using TypeORM. This module registers the ItemEntity and the ItemReadRepository and ItemWriteRepository classes, providing a centralized location for database interactions and repository implementations within the item domain.

src/item/infrastructure · high confidence

Architecture

Item module restructured into DDD layers with CQRS support

The item module has been reorganized to follow Domain-Driven Design principles, splitting functionality into Application, Domain, and Infrastructure sub-modules. The new ItemModule acts as a wrapper that imports these sub-modules along with NestJS's CqrsModule, enabling event sourcing and command/query separation for item-related operations.

src/item · high confidence

Behavioural changes

Database configuration migrated to a NestJS service

The database configuration logic has been moved from a static async export into a dedicated NestJS service (TypeOrmConfigService) that implements TypeOrmOptionsFactory. This change enables the use of autoLoadEntities for automatic entity discovery and allows the configuration to leverage dependency injection, such as accessing environment variables through the service layer rather than a static module definition.

src/database/config · high confidence

Introduce application module with CQRS and repository integration

The application layer is now structured as a distinct module that coordinates business tasks using a CQRS pattern. It exposes controllers for handling microservice messages and provides services that trigger commands and queries. The module integrates with the infrastructure layer by importing read and write repositories via TypeORM and registers command and query handlers to manage data persistence and retrieval.

src/item/application · high confidence

Item entity moved to infrastructure layer with TypeORM mapping

The Item entity has been relocated to the infrastructure layer (src/item/infrastructure/entities) and is now implemented as a TypeORM entity class (ItemEntity) extending BaseEntity, featuring an auto-generated numeric ID and a name column. This change includes the corresponding unit tests for the entity's instantiation and properties, ensuring the data model is properly validated within the new architectural location.

src/item/infrastructure/entities · high confidence

Item management commands now use microservice message patterns

The ItemController has been refactored to communicate via microservice message patterns instead of standard HTTP endpoints. It now listens for specific commands (get-by-id, get-many, create, update, delete-by-id) on the 'item' role, delegating these requests to the ItemService which utilizes the CQRS pattern (QueryBus/CommandBus) to handle the underlying logic.

src/item/application/controllers · high confidence

Item model moved to domain layer with event-driven behavior

The Item model has been relocated to the domain layer (src/item/domain/models) and refactored to extend NestJS's AggregateRoot, enabling it to emit domain events (ItemCreatedEvent, ItemUpdatedEvent, ItemDeletedEvent, and ItemOwnerNotifiedEvent) via its create, update, delete, and notify operations. This change establishes the core domain logic for item lifecycle management within the new architectural structure, supported by unit tests verifying the event emission behavior.

src/item/domain/models · high confidence

Item repository moved to domain layer with unit tests

The ItemRepository implementation has been relocated to the domain layer (src/item/domain/repositories) and is now exported via an index file. This change includes the repository class which delegates item creation, deletion, updates, and owner notifications to the Item model, along with a comprehensive set of unit tests verifying these interactions.

src/item/domain/repositories · high confidence

Microservice architecture with RabbitMQ transport and modular structure

The application has been refactored from a standard HTTP-based NestJS app into a microservice that communicates via RabbitMQ (AMQP). The entry point (main.ts) now initializes a microservice using the RMQ transport, connecting to a RabbitMQ instance configured via environment variables, and listening on a dedicated queue. The root module (app.module.ts) has been updated to import specific feature modules (Database, EventStoreWrapper, Health, Item) and configuration, while the legacy HTTP controller and service files have been removed.

src · high confidence

Saga logic for item lifecycle events moved to domain layer

The saga implementations that handle item lifecycle events (created, updated, deleted) have been relocated to the domain layer under src/item/domain/sagas. This change organizes the code by moving the ItemSagas class, which listens for ItemCreatedEvent, ItemUpdatedEvent, and ItemDeletedEvent and triggers a NotifyItemOwnerCommand after a 1-second delay, into a dedicated domain directory structure.

src/item/domain/sagas · high confidence

TypeORM repositories for item persistence moved to infrastructure

The \ItemReadRepository\ and \ItemWriteRepository\ classes, which provide TypeORM-based access to the \ItemEntity\, have been relocated to the \src/item/infrastructure/repositories\ directory. These repositories are now exported via a central index, consolidating the data-access implementation details within the infrastructure layer.

src/item/infrastructure/repositories · high confidence

Test coverage

Added test mocks for TypeORM and configuration services; Added unit tests for item command handlers; Added unit tests for item event handlers; Added unit tests for item query handlers.

Dependencies

Upgrade NestJS ecosystem and add event store, CQRS, and database dependencies

The project's dependency manifest has been updated to version 1.1.1, upgrading core NestJS packages (common, core, platform-express) from 7.0.0 to 7.6.x and adding several new libraries: @nestjs/config for configuration management, @nestjs/cqrs for command-query responsibility segregation, @nestjs/microservices for microservice communication, @nestjs/schedule for task scheduling, @nestjs/terminus for health checks, @nestjs/typeorm and typeorm for database access, amqp-connection-manager and amqplib for RabbitMQ integration, node-nats-streaming for NATS streaming, node-eventstore-client for event sourcing, and @juicycleff/nestjs-event-store for event store integration. Development dependencies including TypeScript (upgraded to 4.1.3), ESLint, Jest, and Prettier have also been updated, and module aliases for infrastructure, domain, application, and database layers have been configured in both Jest and runtime module resolution.

(dependencies) · high confidence

Written by watchdog.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.

How this codebase got here

Baseline

  • First survey — no prior run to compare against. CAI 49.

Lenses

  • Code Health 74
  • Architecture 69
  • Maturity 61
  • Readiness 38
  • Security 79
  • Domain Modelling 48
  • Performance 100

Changes since last survey

  • 170 commits — 163 feature/other, 7 fixes

By area

  • src/item — 86 commits
  • (root) — 29 commits
  • (repo) — 16 commits
  • src/utils — 9 commits
  • src/database — 8 commits
  • src/health — 5 commits
  • src/app.module.ts — 4 commits
  • src/db — 3 commits
  • .github/ISSUE_TEMPLATE — 2 commits
  • .github/workflows — 2 commits
  • src/event-store — 2 commits
  • .github/PULL_REQUEST_TEMPLATE.md — 1 commit
  • src/README.md — 1 commit
  • src/main.ts — 1 commit
  • test/mocks — 1 commit

Notable commits

  • fix: Merge pull request #14 from otasoft/fix/build-errors
  • fix: feat-#4: fix problem wtih deleteItemById handler
  • fix: feat-#5: fix delete item by id handler
  • fix: fix: fix problem with build errors
  • fix: fix: upgrade @nestjs/terminus from 7.0.1 to 7.1.0
  • fix: fix: upgrade multiple dependencies with Snyk
  • fix: test: fix remaining tests
  • change: Merge pull request #11 from otasoft/feat-#3/add-sagas
  • change: Merge pull request #13 from otasoft/feat-#9/rename-db-module
  • change: Merge pull request #17 from otasoft/feat-#10/add-event-store
  • change: Merge pull request #19 from otasoft/feat-#16/implement-ddd
  • change: Merge pull request #22 from otasoft/feat-#21/create-typeorm-config-service
  • change: Merge pull request #25 from otasoft/feat-#23/refactor-health-module
  • change: Merge pull request #27 from otasoft/feat-#12/add-readme
  • change: Merge pull request #30 from otasoft/feat-#28/refactor-utils
  • change: Merge pull request #31 from otasoft/feat-#18/add-aliases
  • change: Merge pull request #32 from otasoft/feat/add-code-analysis
  • change: Merge pull request #33 from otasoft/test-#24/add-tests
  • change: Merge pull request #34 from otasoft/snyk-upgrade-08efcec62b6ac5612b54dd95fdf655e5
  • change: Merge pull request #37 from otasoft/snyk-upgrade-f2038e7ce056372c8374e10efea1035f
  • …and 150 more

Written by watchdog.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.

Survey your own repository

Baroshem/microservice-template was measured the same way every project in this corpus was: the same rubric, at a pinned commit, with the result published in full. Point a surveyor at a repository you know and see whether you agree with it.

About this page

  • The score is its most recent published measurement, taken on 7 October 2026 at a pinned commit. It is not a live figure and does not change until the project is measured again.
  • Measured at commit beca13e14042566bb20edfaf6a2881baacce0173 — the exact code this score is about.
  • Scored under rubric-2026.10.1 — the same rubric and the same method as every other entry in this index.
  • Measured by watchdog.canine.dev using codehealth-analyzer preprod-8d8088103122.