Skip to content

Commit 5a0ea00

Browse files
committed
update docs for starter packages
1 parent 8534a56 commit 5a0ea00

10 files changed

Lines changed: 2149 additions & 159 deletions

File tree

‎starters/actuator/README.md‎

Lines changed: 148 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,27 @@
33
[![npm version](https://img.shields.io/npm/v/@nodeboot/starter-actuator.svg)](https://www.npmjs.com/package/@nodeboot/starter-actuator)
44
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
55

6-
> **Node-Boot Actuator Starter** provides production-ready monitoring, health checks, and application insights for Node-Boot applications, following Spring Boot Actuator patterns for the Node.js ecosystem.
6+
> **Node-Boot Actuator Starter** provides production-ready monitoring, health checks, and application insights for
7+
> Node-Boot applications, following Spring Boot Actuator patterns for the Node.js ecosystem.
78
89
## Overview
910

10-
The Node-Boot Actuator Starter brings comprehensive application monitoring and observability to your Node.js applications. It automatically exposes operational endpoints for health checks, metrics collection, application information, and more. This starter is the Node.js equivalent of Spring Boot Actuator, providing the same level of production-ready monitoring capabilities.
11+
The Node-Boot Actuator Starter brings comprehensive application monitoring and observability to your Node.js
12+
applications. It automatically exposes an `/actuator` family of operational endpoints for health checks, Prometheus
13+
metrics, build/git information, memory diagnostics, and introspection of your application's controllers,
14+
interceptors and middlewares — with zero manual route wiring.
1115

1216
### Key Features
1317

14-
✅ **Auto-Configuration** – Zero-configuration setup with sensible defaults
15-
✅ **Health Checks** – Built-in health endpoints with custom health indicators
16-
✅ **Prometheus Metrics** – Automatic metrics collection and exposure
17-
✅ **Application Info** – Git information, build details, and environment data
18-
✅ **Multi-Framework Support** – Works with Express, Fastify, Koa, and native HTTP
19-
✅ **Production-Ready** – Battle-tested monitoring patterns from Spring Boot
18+
✅ **Auto-Configuration** – Zero-configuration setup, endpoints are bound automatically at bootstrap
19+
✅ **Health Checks** – Liveness/readiness endpoints that reflect real application lifecycle state
20+
✅ **Prometheus Metrics** – Default Node.js process metrics plus HTTP request count/duration histograms
21+
✅ **Application Info** – Runtime info (host, Node version, uptime, active profiles) and build metadata from
22+
`package.json`
23+
✅ **Git Info** – Optional endpoint exposing commit/branch metadata from a `git.properties` file
24+
✅ **Introspection Endpoints** – Inspect registered controllers, interceptors, and middlewares at runtime
25+
✅ **Multi-Framework Support** – Works with Express, Fastify, Koa, and native `http` servers
26+
✅ **Production-Ready** – Battle-tested monitoring patterns from Spring Boot Actuator
2027

2128
---
2229

@@ -25,8 +32,9 @@ The Node-Boot Actuator Starter brings comprehensive application monitoring and o
2532
### Prerequisites
2633

2734
- Node.js 18+
28-
- Node-Boot 2.0+
29-
- One of the supported servers: Express, Fastify, Koa, or native HTTP
35+
- A Node-Boot application using one of the supported servers: Express, Fastify, Koa, or native HTTP
36+
- `@EnableDI(Container)` on your application class — the actuator resolves core services (`ConfigService`,
37+
`CoreInfoService`, `HealthService`, `Logger`) from the DI container and **throws at bootstrap** if it's missing
3038

3139
### Install the Starter
3240

@@ -41,53 +49,164 @@ npm install @nodeboot/starter-actuator
4149
yarn add @nodeboot/starter-actuator
4250
```
4351

44-
### Auto-Configuration
45-
46-
This starter provides auto-configuration when added to your Node-Boot application. No additional setup required for basic usage.
47-
4852
---
4953

5054
## ⚡ Quick Start
5155

5256
### 1️⃣ Enable Actuator in Your Application
5357

5458
```typescript
55-
import {NodeBootApplication, NodeBoot, ExpressServer} from "@nodeboot/core";
59+
import "reflect-metadata";
60+
import {Container} from "typedi";
61+
import {NodeBoot, NodeBootApp, NodeBootApplication, NodeBootAppView} from "@nodeboot/core";
62+
import {ExpressServer} from "@nodeboot/express-server";
63+
import {EnableDI} from "@nodeboot/di";
64+
import {EnableComponentScan} from "@nodeboot/aot";
5665
import {EnableActuator} from "@nodeboot/starter-actuator";
5766

67+
@EnableDI(Container)
5868
@EnableActuator()
69+
@EnableComponentScan()
5970
@NodeBootApplication()
60-
export class Application {
71+
export class Application implements NodeBootApp {
6172
start(): Promise<NodeBootAppView> {
6273
return NodeBoot.run(ExpressServer);
6374
}
6475
}
6576
```
6677

67-
### 2️⃣ Basic Usage
68-
69-
Once enabled, the actuator automatically exposes monitoring endpoints:
78+
`@EnableActuator()` registers an `ActuatorAdapter` on the application context. At bootstrap, the framework picks the
79+
concrete adapter implementation (Express/Fastify/Koa/native HTTP) matching your chosen server and binds all
80+
`/actuator/*` routes directly on your application's router — no extra wiring required.
7081

71-
### 3️⃣ Verify Setup
82+
### 2️⃣ Verify Setup
7283

7384
```bash
7485
# Start your application
7586
pnpm start
7687

7788
# Access the actuator endpoints:
78-
# Health check
7989
curl http://localhost:3000/actuator/health
80-
81-
# Application info
8290
curl http://localhost:3000/actuator/info
83-
84-
# Prometheus metrics
8591
curl http://localhost:3000/actuator/metrics
92+
curl http://localhost:3000/actuator/prometheus
8693

8794
# Look for these log messages indicating successful setup:
88-
# ✅ Actuator endpoints enabled
89-
# ✅ Health checks registered
90-
# ✅ Metrics collection started
95+
# =====> 🏭 Actuator is Active :) = http://localhost:3000/actuator
96+
# =====> 🚥 Prometheus monitoring endpoint is live :) = http://localhost:3000/actuator/prometheus
97+
```
98+
99+
---
100+
101+
## 📡 Available Endpoints
102+
103+
| Endpoint | Description |
104+
| -------------------------------- | ------------------------------------------------------------------------------------------------ |
105+
| `GET /actuator` | Lists all available actuator endpoints. |
106+
| `GET /actuator/info` | Runtime info: hostname, Node version, load average, uptime, active profiles, build info. |
107+
| `GET /actuator/git` | Git branch/commit metadata, read from a `git.properties` file (see below). |
108+
| `GET /actuator/config` | The fully resolved application configuration (see ⚠️ security note below). |
109+
| `GET /actuator/memory` | Memory diagnostics: `os.freemem/totalmem`, `process.memoryUsage()`, V8 heap statistics. |
110+
| `GET /actuator/metrics` | All registered Prometheus metrics, as JSON. |
111+
| `GET /actuator/prometheus` | All registered Prometheus metrics, in Prometheus text exposition format. |
112+
| `GET /actuator/controllers` | Introspection of all registered Node-Boot controllers, routes, and actions. |
113+
| `GET /actuator/interceptors` | Introspection of all registered interceptors. |
114+
| `GET /actuator/middlewares` | Introspection of all registered middlewares. |
115+
| `GET /actuator/health` | Combined readiness + liveness payload, plus links to the individual endpoints below. |
116+
| `GET /actuator/health/readiness` | `200` once the app (and persistence layer, if enabled) has finished starting; `503` otherwise. |
117+
| `GET /actuator/health/liveness` | Always `200 {"status": "ok"}` while the process is running — suitable for basic liveness probes. |
118+
119+
## ❤️ Health Checks and Application Lifecycle
120+
121+
`/actuator/health/readiness` is not a static "OK" — it's wired to Node-Boot's application lifecycle:
122+
123+
- If `@nodeboot/starter-persistence` (`@EnableRepositories()`) is **not** enabled, readiness flips to `true` as
124+
soon as the `application.started` lifecycle event fires.
125+
- If persistence **is** enabled, readiness stays `503 {"message": "Backend has not started yet"}` until the
126+
`persistence.started` event fires (i.e. the datasource has actually connected), so orchestrators (Kubernetes,
127+
ECS, ...) won't route traffic to an instance whose database connection isn't ready yet.
128+
- `/actuator/health/liveness` always reports `200`, and is intended purely to detect whether the process itself is
129+
alive/hung — use `readiness` for traffic-routing decisions and `liveness` for restart decisions.
130+
131+
```bash
132+
curl http://localhost:3000/actuator/health/readiness
133+
# {"status":"ok"} # once ready
134+
# {"message":"Backend has not started yet","status":"error"} (HTTP 503, before ready)
135+
```
136+
137+
## 📈 Prometheus Metrics
138+
139+
The actuator registers a dedicated `prom-client` `Registry` and collects:
140+
141+
- **Default Node.js process metrics** (event loop lag, GC duration, memory, CPU, etc.) via
142+
`Prometheus.collectDefaultMetrics()`.
143+
- **`app_http_request_count`** — a `Counter` labeled by `method`, `route`, and `statusCode`, incremented on every
144+
request that finishes.
145+
- **`app_http_request_duration_milliseconds`** — a `Histogram` labeled by `method`, `route`, and `code`, recording
146+
request duration.
147+
148+
Metrics recording is offloaded via `setImmediate` so it never blocks the response.
149+
150+
```bash
151+
# Prometheus text format, ready to be scraped:
152+
curl http://localhost:3000/actuator/prometheus
153+
154+
# Same metrics as JSON:
155+
curl http://localhost:3000/actuator/metrics
156+
```
157+
158+
Point your Prometheus `scrape_configs` at `/actuator/prometheus` to start collecting these metrics.
159+
160+
## 🌱 Git Info
161+
162+
`/actuator/git` follows the same convention as Spring Boot's `git-commit-id-plugin`: it reads a `git.properties`
163+
file from your application's working directory (via the `properties-reader` library) with keys such as:
164+
165+
```properties
166+
git.branch=main
167+
git.commit.id=1a2b3c4d5e6f7890abcdef1234567890abcdef12
168+
git.commit.id.abbrev=1a2b3c4
169+
git.commit.time=2025-01-15T10:30:00Z
170+
git.commit.user.name=Jane Doe
171+
git.commit.user.email=jane@example.com
172+
git.commit.message.full=Fix actuator health check
173+
git.commit.message.short=Fix actuator health check
91174
```
92175

93-
TO BE CONTINUED...
176+
Node-Boot itself does not generate this file — since there's no Node.js equivalent of the Maven/Gradle
177+
`git-commit-id-plugin`, generate it yourself as a prebuild step, for example:
178+
179+
```json
180+
{
181+
"scripts": {
182+
"generate:git-info": "echo \"git.branch=$(git rev-parse --abbrev-ref HEAD)\ngit.commit.id=$(git rev-parse HEAD)\ngit.commit.id.abbrev=$(git rev-parse --short HEAD)\ngit.commit.time=$(git log -1 --format=%cI)\" > git.properties",
183+
"prebuild": "pnpm run generate:git-info"
184+
}
185+
}
186+
```
187+
188+
If `git.properties` is missing, `/actuator/git` simply returns `undefined`/an empty body instead of failing.
189+
190+
## ⚠️ Security Note on `/actuator/config`
191+
192+
`/actuator/config` returns your **entire resolved configuration tree**, including any secrets interpolated from
193+
environment variables at load time. Treat all `/actuator/*` endpoints as internal/operational surface: put them
194+
behind network-level restrictions (VPC, internal load balancer, sidecar auth) or a reverse-proxy rule, rather than
195+
exposing them on the public internet alongside your API.
196+
197+
## 🖥️ Framework Support
198+
199+
The actuator binds routes through a framework-specific adapter chosen automatically based on which Node-Boot server
200+
you use (`ExpressServer`, `FastifyServer`, `KoaServer`, or `HttpServer`). If `@EnableActuator()` is applied with an
201+
unsupported server type, bootstrap fails fast with a clear error asking you to remove the decorator.
202+
203+
## 🎉 Conclusion
204+
205+
`@nodeboot/starter-actuator` brings Spring Boot Actuator-style production readiness to Node-Boot applications:
206+
health checks tied to real lifecycle state, Prometheus metrics out of the box, and introspection endpoints for
207+
controllers, interceptors and middlewares — all with a single `@EnableActuator()` decorator.
208+
209+
## 📚 Resources
210+
211+
- [Spring Boot Actuator (reference inspiration)](https://docs.spring.io/spring-boot/docs/current/reference/html/actuator.html)
212+
- [prom-client (Prometheus client for Node.js)](https://github.com/siimon/prom-client)

‎starters/aws/README.md‎

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ dependency injection and auto-configuration for AWS clients such as DynamoDB, S3
77

88
## Enabling AWS Services
99

10-
1. Firs install the AWS Starter package for NodeBoot:
10+
1. First install the AWS Starter package for NodeBoot:
1111

1212
```sh
1313
npm install @nodeboot/starter-aws
@@ -21,7 +21,7 @@ import {Container} from "typedi";
2121
import {NodeBoot, NodeBootApp, NodeBootApplication, NodeBootAppView} from "@nodeboot/core";
2222
import {ExpressServer} from "@nodeboot/express-server";
2323
import {EnableDI} from "@nodeboot/di";
24-
import {EnableComponentScan} from "@nodeboot/scan";
24+
import {EnableComponentScan} from "@nodeboot/aot";
2525
import {EnableAws} from "@nodeboot/starter-aws";
2626

2727
@EnableDI(Container)
@@ -93,6 +93,10 @@ region=us-east-1
9393
> to
9494
> [Setting_AWS_Credentials](https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/configuring-the-jssdk.html#Setting_AWS_Credentials)
9595
96+
> ⚠️ If `integrations.aws.credentials` is not set in `app-config.yaml`, each client is still created — the starter
97+
> logs a warning and falls back to the AWS SDK's default credentials provider chain (environment variables, shared
98+
> `~/.aws/credentials` file, or an attached IAM role), so explicit config is optional in environments like EC2/ECS/Lambda.
99+
96100
## AWS Service-Specific Instructions
97101

98102
### DynamoDB
@@ -299,6 +303,31 @@ com:
299303
queue-url: "https://sqs.us-east-1.amazonaws.com/123456789012/my-queue"
300304
```
301305
306+
> `@SqsListener` only registers when the current active profiles satisfy any `@Profile(...)` metadata declared on the
307+
> target class (see `@nodeboot/core`'s `@Profile` decorator). If the profiles don't match, or AWS SQS isn't enabled
308+
> via `@EnableAws()`/`integrations.aws.sqs.region`, the listener logs a warning and is skipped instead of throwing.
309+
310+
#### The `MessageEnvelop` Payload
311+
312+
Every `@SqsListener` handler receives a `MessageEnvelop<M>` — a parsed wrapper around the raw SQS message body,
313+
rather than the raw `sqs-consumer` `Message` object:
314+
315+
```typescript
316+
type MessageEnvelop<M = JsonObject> = {
317+
messageId: string; // AWS-assigned message ID
318+
timestamp: string; // SNS/SQS delivery timestamp
319+
signature: string; // SNS signature, when the message originated from an SNS->SQS subscription
320+
message: M; // The actual, JSON-parsed message payload
321+
};
322+
```
323+
324+
```typescript
325+
@SqsListener("${com.example.aws.sqs.queue-url}")
326+
async onMessage(envelop: MessageEnvelop<{orderId: string}>): Promise<void> {
327+
console.log(`Processing order ${envelop.message.orderId} (messageId=${envelop.messageId})`);
328+
}
329+
```
330+
302331
#### SQS Message Handling
303332

304333
- The queue is polled continuously for messages using [long polling](https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-long-polling.html).

0 commit comments

Comments
 (0)