Skip to content

Refactor architecture to isolate metrics and enforce global API prefix#1

Merged
amiabl-programr merged 1 commit intomainfrom
feat/hide-sensitive-route
Apr 8, 2026
Merged

Refactor architecture to isolate metrics and enforce global API prefix#1
amiabl-programr merged 1 commit intomainfrom
feat/hide-sensitive-route

Conversation

@amiabl-programr
Copy link
Copy Markdown
Owner

Description

This PR fundamentally hardens the Teapot Microservice architecture by completely isolating internal Prometheus metrics from the public API boundary. In compliance with enterprise security requirements (and strict RFC 2324 guidelines), internal runtime data, such as CPU usage and refusal counters, is no longer accessible from the public internet.

Simultaneously, we have formalized our public endpoint footprint via a global /api prefix.

Architectural Changes

  • Dual-App Bootstrapping: main.ts now spins up two entirely isolated NestJS Dependency Injection containers.
    • The Public App runs on port 4180 with a global /api prefix.
    • The Internal App runs on port 3001 (bound strictly to 127.0.0.1) executing the MetricsModule.
  • Global Metric Registry: Refactored MetricsService to act as a stateless accessor to prom-client's global Node.js registry. This elegantly bypasses NestJS's container isolation, ensuring BrewModule in the public app perfectly increments the counters exposed by the internal app, without fatal Metric already defined collisions.
  • Frontend Compatibility: Verified that the Enterprise HTTP 418 Simulation Interface (/src/public) continues to accurately reflect our rigorous refusal standards.
  • E2E Infrastructure: Concurrency-tested both servers inside app.e2e-spec.ts. Verified that rate-limiting natively propagates exception messages and that the /metrics endpoint yields a rigid 404 Not Found on the public interface.

Verification

  • Local testing confirms http://localhost:4180/metrics correctly 404s.
  • Local testing confirms http://localhost:3001/metrics reliably returns prometheus data.
  • Ensure CI pipelines (Strict Coffee Rejection Check) and tests complete favorably.
  • Rate limiting behaves correctly and outputs accurate enterprise responses.

Known Issues / Warnings

  • Breaking Change: All public endpoints must now be prefixed with /api (e.g., /api/v1/brew instead of /v1/brew). Swagger docs have updated automatically.

"A robust teapot is an impenetrable teapot."

…global api prefix

- Bootstrapped dual NestJS applications in main.ts to structurally separate the public routing table (port 4180) from internal compliance monitoring (port 3001).
- Enforced a global /api prefix across all public HTTP endpoints.
- Extracted MetricsModule from the public AppModule boundary, guaranteeing zero metric exposure to the public internet.
- Refactored MetricsService to function as a stateless bridge to the prom-client global registry. This safely supports metric sharing across isolated Dependency Injection containers without collision.
- Updated e2e testing infrastructure to run concurrent server instances and verified rate-limiting compliance.
@amiabl-programr amiabl-programr self-assigned this Apr 8, 2026
@amiabl-programr amiabl-programr merged commit 434c8f3 into main Apr 8, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant