Backend Architecture
Docs/Backend Core/Backend Architecture

Backend Architecture

ENGINE

Firebreak's backend follows a strict layered pattern dividing responsibilities into HTTP Gateways, Security Guards, Domain Services, Infrastructure Adapters, and Persistence.

4 min read
•
Production Verified

Gateways and Ingestion Endpoints

External signals enter Firebreak through two hardened endpoints:

apps/web/src/app/api/v1/alerts/[serviceId]/route.ts
// HMAC SHA-256 validation using constant-time comparison
const expected = crypto.createHmac("sha256", secret).update(rawBody).digest("hex");
if (!crypto.timingSafeEqual(Buffer.from(signature), Buffer.from(expected))) {
  return NextResponse.json({ error: "Invalid signature" }, { status: 401 });
}

// Deduplicate alert & dispatch durable workflow
const incident = await AlertService.ingestAlert(serviceId, payload);
await inngest.send({ name: "firebreak/incident.created", data: { incidentId: incident.id } });
return NextResponse.json({ status: "accepted", incidentId: incident.id }, { status: 202 });

Core Domain Services

ServicePathCore Responsibility
alerts.tspackages/core/src/services/alerts.tsAlert ingestion, sliding window deduplication, and fingerprint calculation.
trace.tspackages/core/src/services/trace.tsCoordinates deployment identification and commit delta retrieval.
ranking.tspackages/core/src/domain/ranking.tsThe 8-factor commit blame scoring algorithm and path normalizer.
preflight.tspackages/core/src/domain/preflight.tsPure evaluation of the 6 rollback safety checks.
actions.tspackages/core/src/services/actions.tsStages proposals with 15-min TTL, enforces approval, and executes rollback.
probe.tspackages/core/src/adapters/probe.tsRuns automated canary health checks requiring a 3x consecutive 200 OK streak.