Cloud

Architecture

How @axiljs/cloud is organized, how modules relate to the AxilJS ecosystem, and how requests flow through the middleware stack.

3 min readDocumentationEdit this page

Platform Overview

@axiljs/cloud is a unified set of composable capability modules that share a single type system, event bus, and observability layer.

text
┌───────────────────────────────────────────────────────────────────┐
│                     AxilJS Cloud Platform                         │
├───────────────────────────────────────────────────────────────────┤
│                                                                   │
│  Tenancy & Access             Governance                          │
│  ─────────────────            ─────────────                       │
│  multi-tenancy                audit                               │
│  rate-limiter                 quota                               │
│  correlation                  feature-flags                       │
│                                                                   │
│  Data & Secrets               Deployment & Ops                    │
│  ─────────────────            ─────────────────                   │
│  cache                        deployment                          │
│  secrets                      dashboard                           │
│                               health-aggregator                   │
│                                                                   │
└───────────────────────────────────────────────────────────────────┘

Module Dependency Graph

text
                    ┌──────────────┐
                    │  @axiljs/    │
                    │  common      │
                    └──────┬───────┘
                           │
              ┌────────────┼────────────┐
              │            │            │
       ┌──────▼──────┐┌────▼──────┐┌────▼──────┐
       │  @axiljs/   ││ @axiljs/  ││ @axiljs/  │
       │  events     ││ observab. ││ security  │
       └──────┬──────┘└────┬──────┘└────┬──────┘
              │            │            │
              └────────────┼────────────┘
                           │
                    ┌──────▼───────┐
                    │  @axiljs/    │
                    │  cloud       │
                    └──────────────┘

Request Lifecycle

text
┌───────────────────────────────────────────────────────────────┐
│                     INCOMING HTTP REQUEST                     │
└───────────────────────────────────────────────────────────────┘
                              │
                              ▼
┌───────────────────────────────────────────────────────────────┐
│  correlationId()                                              │
│  → Generate req_xxx and corr_yyy                              │
│  → Attach to req.locals                                       │
│  → Echo in response headers                                   │
└───────────────────────────────────────────────────────────────┘
                              │
                              ▼
┌───────────────────────────────────────────────────────────────┐
│  multiTenancy()                                               │
│  → Extract tenant ID from header/subdomain/JWT                │
│  → Validate format                                            │
│  → Load tenant from database                                  │
│  → Reject if suspended/archived                               │
│  → Attach to req.locals.tenant                                │
└───────────────────────────────────────────────────────────────┘
                              │
                              ▼
┌───────────────────────────────────────────────────────────────┐
│  tenantRateLimiter()                                          │
│  → Look up tenant-specific rule                               │
│  → Increment sliding window counter                           │
│  → Set X-RateLimit-* headers                                  │
│  → Return 429 if exceeded                                     │
└───────────────────────────────────────────────────────────────┘
                              │
                              ▼
┌───────────────────────────────────────────────────────────────┐
│  auditMiddleware()                                            │
│  → Register response 'finish' and 'close' handlers            │
│  → On completion: emit 'audit.log' event                      │
└───────────────────────────────────────────────────────────────┘
                              │
                              ▼
┌───────────────────────────────────────────────────────────────┐
│                   YOUR BUSINESS LOGIC                         │
│                                                               │
│  • Use getTenant(req) for tenant context                      │
│  • Use featureFlags.isEnabled() for A/B testing               │
│  • Use quotas.increment() to track resource usage             │
│  • Use cache.get()/set() for performance                      │
│  • Use secrets.get() for credentials                          │
└───────────────────────────────────────────────────────────────┘
                              │
                              ▼
┌───────────────────────────────────────────────────────────────┐
│                    RESPONSE SENT TO CLIENT                    │
│                                                               │
│  Audit event automatically emitted on 'finish'                │
└───────────────────────────────────────────────────────────────┘

AxilJS Ecosystem Integration

PackageIntegration
@axiljs/coreUses Application, MiddlewareFn, RouteHandler types
@axiljs/commonExtends axilRequest, axilResponse, throws UnauthorizedError
@axiljs/eventsEmits audit and quota events on the global event bus
@axiljs/observabilityDashboard pulls from MetricsRegistry and HealthChecker
@axiljs/securityRate limiter complements helmet() and cors()
@axiljs/authJWT strategy extracts tenantId from req.locals.user
@axiljs/configSecrets manager pairs with defineConfig() for typed env
@axiljs/ormTenant context can be injected into query builders
@axiljs/queueAudit events can be routed to durable job queues
@axiljs/websocketCorrelation IDs propagate to WebSocket sessions

Full Integration Example

typescript
import { Application } from '@axiljs/core'
import { loadEnv, defineConfig } from '@axiljs/config'
import { helmet, cors } from '@axiljs/security'
import { JWT, authenticate } from '@axiljs/auth'
import { MetricsRegistry, HealthChecker, observabilityMiddleware } from '@axiljs/observability'
import {
  correlationId,
  multiTenancy,
  tenantRateLimiter,
  auditMiddleware,
  createDashboard,
} from '@axiljs/cloud'
 
loadEnv()
const config = defineConfig({ /* ... */ })
const jwt = new JWT(config.JWT_SECRET)
const metrics = new MetricsRegistry()
const health = new HealthChecker()
 
const app = new Application()
 
app.use(helmet())
app.use(cors({ origin: '*' }))
app.use(observabilityMiddleware({ metrics }))
app.use(correlationId())
app.use(authenticate(jwt, { required: false }))
app.use(multiTenancy({ strategy: 'jwt' }))
app.use(tenantRateLimiter({ defaultRule: { max: 100, windowMs: 60_000 } }))
app.use(auditMiddleware())
 
app.get('/dashboard', createDashboard({ title: 'Admin' }))
app.get('/health', health.handler())
 
app.listen(3000)

Help improve the documentation

AxilJS is open source and documentation improvements are welcome.

AxilJS DocumentationMIT License · Built by SyntaxilitY