Back to all docs
SlashHub Docs

Enterprise Architecture

9-pillar technical blueprint: observability, API governance, resilience, security, data management, testing, and more.

For developers~12 min readLast reviewed: 2026-07-02
S

SlashAI

Cross-product AI agent platform

Open

The AI layer across the platform — 315 tools, answering from your own product data.

Layer 2 · AI Enabler2025ai.slashhub.hk
315 registered tools
Multi-agent ReAct loop
HS256 service JWT
SSE streaming
NestJS 11RedisDeepSeekMiniMax

Target: 5/5 maturity across all 9 pillars for every served repo. (The estate is three foundation services — SSO, Subscription, SlashAI — plus separate product sites, DEC-0225. A repo is not a product.) Status: Phase 1 (Quick wins) implemented. Phase 2-4 in roadmap.

Goal: See, understand, debug everything in production.

  • ✅ Structured logging: pino via AppLoggerModule in backend-core
    • JSON output in production, pretty in development
    • Auto-redacts auth headers, passwords, tokens, cookies
    • Request ID correlation across logs
  • ✅ Metrics: Prometheus via MetricsModule in backend-core
    • Pre-registered: slashhub_http_requests_total, slashhub_http_request_duration_seconds, slashhub_circuit_breaker_state, slashhub_business_events_total
    • Endpoint: GET /metrics
    • Grafana dashboards recommended
  • ⚠️ Tracing: OpenTelemetry — Phase 2
Apps → logs/metrics → [Loki / Prometheus / DataDog / Grafana Cloud]

Goal: Consistent API contract across all products.

  • Prefix: /api/v1/{resource}
  • Errors: { success: false, error: { code, message }, meta: { requestId, timestamp } }
  • Success: { success: true, data, meta: { requestId, timestamp } }
  • Pagination: { data, hasMore, nextCursor }
  • Docs: Swagger UI at /api/docs

Goal: Survive dependency failures without cascading.

  • Retry: retryWithBackoff({ maxAttempts, baseDelayMs, factor, jitter, shouldRetry })
  • Circuit Breaker: new CircuitBreaker({ failureThreshold, resetTimeoutMs })
  • Timeout: 30s default via TimeoutInterceptor
  • Graceful shutdown: SIGTERM handlers
  • Health checks: /v1/health (liveness) + /v1/health/ready (readiness)

Goal: Defense in depth, defense by default.

  • Helmet: HTTP headers (CSP, HSTS, X-Frame-Options)
  • CORS: Whitelist-based via CORS_ORIGIN env var (see docs/product/architecture/domains.md)
  • Rate limiting: 3-tier via @nestjs/throttler (10/s, 50/10s, 200/60s)
  • CSRF: Double-submit cookie via CsrfModule; @SkipCsrf() for webhooks
  • Auth: FirebaseAuthGuard for Firebase ID tokens
  • Authz: RolesGuard + @Roles('admin', 'manager')
  • Input validation: ZodValidationPipe
  • Secret guard: CI blocks committed .env* and service-account JSON
  • Audit trail: All security events logged

Goal: Data integrity, recovery, compliance.

  • Firestore backups: scripts/firestore-backup.sh <project> <bucket> [retention]
    • Automated via gcloud firestore export to GCS
    • Retention-based pruning
  • Migrations: CLI scripts with --apply flag (TimePlate pattern)
  • Audit trail: Standardized schema in auditLogs collection
  • TTL policies: Available on Firestore collections

Goal: Confidence to deploy, fast feedback.

  1. Pre-commit (Husky): ESLint + Prettier on staged files
  2. CI: lint → typecheck → test (≥70% coverage) → build
  3. Secret guard: Block committed secrets
  4. Backend-core sync check: make check-sync
LayerLinesFunctionsBranches
Backend services80%80%70%
Frontend components70%70%60%
Shared packages80%80%70%

Goal: Predictable, repeatable, recoverable.

  • Environments: dev → staging → production per product
  • Health check gate: Railway deploy waits for /v1/health to respond
  • Graceful shutdown: SIGTERM → drain → exit (no dropped connections)
  • Rollback: Railway/Vercel one-click rollback to previous deployment
  • Zero-downtime: Multi-instance with rolling deploys

Goal: Fast, resilient, accessible.

  • ErrorBoundary: At app root + critical feature boundaries
  • Loading states: loading.tsx for routes, Suspense for components
  • Type safety: TypeScript strict + Zod for runtime
  • Performance: Bundle budget 300KB warn / 500KB error
  • Observability: Sentry for error tracking
  • Accessibility: WCAG 2.1 AA target

Goal: Easy to onboard, easy to ship.

  • Onboarding: docs/CONTRIBUTING.md, .nvmrc, docker-compose.dev.yml
  • PR template: .github/PULL_REQUEST_TEMPLATE.md
  • Conventional commits: Enforced via PR review
  • Local dev: pnpm dev, make sync, make check
  • Makefile: 36+ per-product targets + 6 cross-product targets

                              DEVELOPER
                                  │
                                  ▼
                        ┌──────────────────┐
                        │     GitHub       │
                        │  + Husky (local) │
                        └────────┬─────────┘
                                 │
                                 ▼ PR + CI
                        ┌──────────────────────────────────────────┐
                        │           GitHub Actions                    │
                        ├──────────────────────────────────────────┤
                        │  1. secret-guard    (block .env, JSON)    │
                        │  2. lint            (eslint)               │
                        │  3. typecheck       (tsc)                  │
                        │  4. test            (vitest ≥70% cov)     │
                        │  5. build           (turbo)                │
                        │  6. backend-core sync check                 │
                        └──────────────────┬───────────────────────┘
                                            │
                ┌───────────────────────────┼───────────────────────────┐
                │                           │                           │
          ┌─────▼─────┐              ┌──────▼──────┐             ┌──────▼──────┐
          │  Vercel   │              │   Railway   │             │  Firebase   │
          │  (FE)     │              │   (BE)      │             │  (data)     │
          │  .hk      │              │   .space    │             │  (Firestore │
          │           │              │             │             │   Auth,     │
          │  Next.js  │              │   NestJS    │             │   Storage)  │
          │  + Sentry │              │   + pino    │             │             │
          │  + Vercel │              │   + Prometheus            │             │
          │   Insights│              │   + Redis   │             │             │
          └───────────┘              └──────┬──────┘             └──────┬──────┘
                                            │                          │
                                            ▼                          ▼
                                    ┌─────────────────────────────────────────┐
                                    │           Observability                  │
                                    ├─────────────────────────────────────────┤
                                    │  Grafana / DataDog / Sentry / Loki       │
                                    └─────────────────────────────────────────┘

  • Add pino structured logging to backend-core
  • Add retry + circuit breaker utilities
  • Add Prometheus metrics module
  • Add CSRF module
  • Add Throttler module
  • Add AuditTrail module
  • Add FeatureFlags module
  • Add EnvValidator
  • Add secret guard to all CI workflows
  • Add Vitest to the product APIs and web apps
  • Add ErrorBoundary to slashbooks/web + slashone/web
  • Add Firestore backup script
  • Add docker-compose.dev.yml template
  • Add PR template + docs/CONTRIBUTING.md
  • Sync enhanced backend-core to every product that consumes it
  • OpenTelemetry instrumentation in backend-core
  • Standardize all NestJS backends to use AppLoggerModule (replace NestJS Logger)
  • Standardize API versioning to /api/v1
  • Add Swagger/OpenAPI to all NestJS backends (currently only SlashBooks)
  • Add HTTP-Retry-After headers to throttler responses
  • Add CSRF token endpoint (GET /csrf) for frontend
  • Add OpenTelemetry traces to all NestJS backends
  • Standardize audit trail schema across all products
  • Add staging environment to Railway for each product
  • Add SonarQube to CI (or CodeClimate as lighter alternative)
  • Add E2E smoke tests to all backends
  • Add Firestore rules CI to all products with Firestore
  • Add graceful shutdown to all backends
  • Performance/load testing (k6)
  • Bundle size budgets in CI for all frontends
  • Zero-downtime deployment verification
  • Conventional commits enforcement
  • Documentation: API docs (Swagger), runbooks, on-call

# Quality checks
make check                  # All 6 products: lint + typecheck + sync-check

# Sync backend-core
make sync                   # Push canonical → all 6
make check-sync             # Verify drift

# Per-product
make <product>-lint
make <product>-build
make <product>-test

# Local dev
docker compose -f shared-infra/docker-compose.dev.yml up -d

# Backups
bash scripts/firestore-backup.sh <project> <bucket> [retention-days]

# Smoke test
bash scripts/smoke-test.sh <api-url> [auth-token]

Last reviewed: 2026-11-17 — estate statement moved to DEC-0225 (foundation services + separate product sites); the Phase 1 checklist no longer names an archived repo; nothing else in this file was re-measured, so the maturity claims below remain at their 2026-06-27 evidence.

Prior: 2026-06-27 — standardization checks + 9 enterprise modules pass.