DocumentationReference

HazelJS Concepts and Decorator Reference

Definitions of HazelJS types and concepts across all HazelJS packages (core, data, ml, agent, ai, rag, auth, serverless, resilience, and more), with links to full documentation. Use this page to look up HazelJS terms, find the right decorator, and navigate to deep-dive guides.

Quick Reference

  • Purpose: Quick reference for all HazelJS concepts, decorators, and terms across every HazelJS package. Serves as a lookup table for RAG retrieval and LLM context.
  • When to use: Reference this page when looking up a HazelJS decorator, interface, or concept. Use the Glossary for canonical term definitions.
  • Key concepts: RequestContext, ExecutionContext, ArgumentsHost, CanActivate, PipeTransform, Interceptor, ExceptionFilter, Module, Provider, Scope, and all package-specific decorators.
  • Inputs: N/A (reference page).
  • Outputs: N/A (reference page).
  • Dependencies: N/A.
  • Common patterns: Look up a decorator → read its signature and purpose → follow the link to the full guide or package page.
  • Common mistakes: Confusing HazelJS Guard with HazelJS Interceptor; confusing HazelJS Pipe with HazelJS Middleware; confusing @hazeljs/agent Agent with @hazeljs/ai AIEnhancedService.

HazelJS Request/Response Lifecycle Concepts

RequestContext

RequestContext is a HazelJS object containing parsed request data: method, url, headers, params, query, body, user, and dtoType. HazelJS passes RequestContext through the request pipeline. HazelJS pipes, guards, and interceptors receive RequestContext.

See: Controllers, API Reference

ArgumentsHost

ArgumentsHost is a HazelJS abstraction over the execution context. ArgumentsHost exposes switchToHttp() which returns getRequest() and getResponse(). HazelJS exception filters receive ArgumentsHost in the catch() method.

See: Exception Filters, API Reference

ExecutionContext

ExecutionContext extends the HazelJS request/response context with switchToHttp() returning the request, response, and RequestContext. HazelJS guards receive ExecutionContext in the canActivate(context) method.

See: Guards, API Reference

HazelJS Authorization and Validation Interfaces

CanActivate (Guard Interface)

CanActivate is the HazelJS interface for guards. Implement canActivate(context: ExecutionContext): boolean | Promise<boolean>. Return true to allow the request. Return false or throw an exception to deny the request. Apply guards with @UseGuards().

See: Guards

PipeTransform (Pipe Interface)

PipeTransform is the HazelJS interface for pipes. Implement transform(value, context): value | Promise<value> to transform or validate a single input value (route param, query param, or request body). Apply pipes with @UsePipes().

See: Pipes, API Reference

Interceptor Interface

Interceptor is the HazelJS interface for interceptors. Implement intercept(context, next): Promise<result> to wrap handler execution. HazelJS Interceptors can transform the result, add logging, implement caching, or handle errors. Apply interceptors with @UseInterceptors().

See: Interceptors, API Reference

ExceptionFilter Interface

ExceptionFilter is the HazelJS interface for exception filters. Implement catch(exception, host) to format errors and send the HTTP error response. Bind exception filters with @Catch().

See: Exception Filters, API Reference

HazelJS Organization and Dependency Injection Concepts

Module

A HazelJS Module is an organizational unit that groups controllers, providers, and imports. Define a HazelJS Module with @HazelModule(). Every HazelJS application has one root module.

See: Modules

Provider

A HazelJS Provider is an injectable class (service, factory, helper) registered in a module and resolved by the HazelJS DI container. Decorate with @Service() or @Injectable().

See: Providers

Scope

HazelJS Scope defines the lifecycle of a provider: singleton (default, one shared instance), transient (new instance per injection), request (new instance per HTTP request).

See: Providers, API Reference

When to Use: Guard vs Interceptor vs Pipe vs Middleware

HazelJS FeatureRuns whenPurposeInterface
HazelJS MiddlewareBefore routingBody parsing, CORS, logging, rate limitingFunction or class
HazelJS GuardAfter routing, before handlerAuthentication, authorization, role checksCanActivate
HazelJS InterceptorAround handler (before and after)Logging, caching, response transformation, retryInterceptor
HazelJS PipeBefore handler, per input valueInput validation, type transformationPipeTransform
HazelJS Exception FilterOn error (any pipeline stage)Error formatting, error loggingExceptionFilter

Key differences:

  • HazelJS Guard vs HazelJS Interceptor — HazelJS Guards run before the handler and decide whether the request is allowed (auth/authz). HazelJS Interceptors run around the handler and can transform the result or add cross-cutting behavior. Use a Guard for auth. Use an Interceptor for logging or caching.
  • HazelJS Pipe vs HazelJS Interceptor — HazelJS Pipes transform or validate one input value before the handler. HazelJS Interceptors wrap the entire handler execution. Use a Pipe for DTO validation. Use an Interceptor for response transformation.
  • HazelJS Middleware vs HazelJS Guard — HazelJS Middleware runs early in the pipeline (before routing). HazelJS Guards run after the route is matched and have access to the execution context and handler metadata. Use Middleware for CORS. Use a Guard for role-based access.

HazelJS Decorators by Package

Core (@hazeljs/core)

DecoratorTypePurpose
@Controller(path)ClassMarks a controller with route prefix
@Get(), @Post(), @Put(), @Delete(), @Patch()MethodRegister HTTP route handlers
@Body(), @Param(), @Query(), @Req(), @Res(), @Headers()ParameterExtract request data
@Ip(), @Host(), @Session()ParameterExtract client IP, host, session
@Injectable(), @Service()ClassRegister providers in DI container
@Inject(token)ParameterExplicit injection by token
@UseGuards(...guards)Class/MethodApply authorization guards
@UseInterceptors(...interceptors)Class/MethodApply interceptors
@UsePipes(...pipes)Class/MethodApply validation/transformation pipes
@HttpCode(code)MethodSet response status code
@Header(name, value)MethodSet response header
@Redirect(url, code?)MethodRedirect response
@Public() / @SkipAuth()Class/MethodSkip authentication guards
@Timeout(ms)MethodPer-route timeout
@Retry(options)MethodRetry on failure
@Optional()ParameterMark parameter as optional
@HazelModule(options)ClassDefine a module
SetMetadata(key, value)Class/MethodAttach custom metadata
createParamDecorator(resolve)FunctionCreate custom parameter decorators

Full list: API Reference

Agent (@hazeljs/agent)

DecoratorTypePurpose
@Agent(config)ClassMark a class as an LLM-driven agent
@Tool(config)MethodMark a method as a tool callable by agents
@Delegate(config)MethodDelegate subtask to another agent

See: Agent Package

AI (@hazeljs/ai)

DecoratorTypePurpose
@AIFunction(options)MethodMark a method as AI-powered
@AIPrompt()ParameterInject prompt argument for AI methods
@AIValidate(options)ClassAI-powered DTO validation
@AIValidateProperty(options)PropertyPer-field AI validation
@AITask(options)MethodConfigurable AI task execution

See: AI Package

RAG (@hazeljs/rag)

DecoratorTypePurpose
@RAG(options)ClassConfigure RAG at module level
@SemanticSearch(options)MethodVector-based semantic search
@HybridSearch(options)MethodVector + keyword hybrid search
@AutoEmbed()MethodAuto-generate embeddings
@Embeddable(options)ClassMark entity as embeddable
@VectorColumn()PropertyVector storage column
@QueryPlanner()MethodAgentic RAG: query planning
@SelfReflective()MethodAgentic RAG: self-reflective retrieval
@AdaptiveRetrieval()MethodAgentic RAG: adaptive retrieval
@MultiHop()MethodAgentic RAG: multi-hop retrieval
@HyDE()MethodAgentic RAG: hypothetical document embeddings
@CorrectiveRAG()MethodAgentic RAG: corrective RAG
@ContextAware()MethodAgentic RAG: context-aware retrieval

See: RAG Package

Data (@hazeljs/data)

DecoratorTypePurpose
@Pipeline(options)ClassDefine a data pipeline (ETL/stream)
@Transform(options)Method/PropertyDefine field transformations
@Validate(options)Method/PropertyDefine validation rules
@Stream(options)MethodMark a stream processor
@Mask(), @Redact(), @Encrypt(), @Decrypt()PropertyPII handling decorators

See: Data Package

ML (@hazeljs/ml)

DecoratorTypePurpose
@Model()ClassRegister an ML model
@Train(options)MethodTraining entrypoint
@Predict(options)MethodInference method

See: ML Package

Auth and Authorization

DecoratorPackagePurpose
@CurrentUser(field?)@hazeljs/authInject authenticated user
@Ability()@hazeljs/caslInject CASL ability
@CheckPolicies(...handlers)@hazeljs/caslRegister CASL policy handlers

See: Auth Package, CASL Package

Resilience (@hazeljs/resilience)

DecoratorTypePurpose
@CircuitBreaker(config)MethodCircuit breaker with fallback
@Retry(config)MethodRetry on failure
@Timeout(duration)MethodEnforce timeout
@Bulkhead(config)MethodLimit concurrent executions
@RateLimit(config)MethodRate limit invocations
@Fallback(primaryMethod)MethodFallback method for circuit breaker

See: Resilience Package

Guardrails (@hazeljs/guardrails)

DecoratorTypePurpose
@GuardrailInput(options)MethodInput safety checks (injection, PII)
@GuardrailOutput(options)MethodOutput safety checks on LLM responses

See: Guardrails Package

Additional Package Decorators

DecoratorPackagePurpose
@Serverless(options)@hazeljs/serverlessServerless-optimized controller
@Lang()@hazeljs/i18nInject detected locale
@Audit(options)@hazeljs/auditAudit logging
@Queue(name, options?)@hazeljs/queueQueue job processor
@Cache(options)@hazeljs/cacheCache method results (alias: @Cacheable)
@CacheKey(key)@hazeljs/cacheExplicitly define cache key
@CacheTTL(ttl)@hazeljs/cacheDefine time-to-live for a method
@CacheTags(...tags)@hazeljs/cacheAttach invalidation tags
@CacheEvict(options)@hazeljs/cacheInvalidate cache entries by key or tags
@CacheLock(options)@hazeljs/cacheDistributed locking for expensive operations
@CacheAside(options)@hazeljs/cacheLoad-through caching pattern
@WriteThrough(options)@hazeljs/cacheUpdate cache and database synchronously
@WriteBehind(options)@hazeljs/cacheAsynchronous database updates with batching
@CacheWarm(options)@hazeljs/cacheProgrammatic cache warming on startup
@Cron(expression, options?)@hazeljs/cronRegister cron job
@KafkaConsumer(options)@hazeljs/kafkaKafka consumer
@KafkaSubscribe(topic)@hazeljs/kafkaSubscribe to Kafka topic
@Realtime(path)@hazeljs/websocketWebSocket gateway
@Resolver(name?)@hazeljs/graphqlGraphQL resolver
@Query(), @Mutation()@hazeljs/graphqlGraphQL operations
@GrpcMethod(service, method?)@hazeljs/grpcgRPC method
@Gateway(config)@hazeljs/gatewayAPI gateway definition
@OnEvent(event, options?)@hazeljs/event-emitterEvent subscription
@Flow(id, version)@hazeljs/flowDurable workflow definition
@Node(id, options?)@hazeljs/flowWorkflow node
@Edge(target, options?)@hazeljs/flowWorkflow edge
@Repository(options)@hazeljs/prisma / @hazeljs/typeormData repository
@InjectRepository()@hazeljs/prisma / @hazeljs/typeormInject repository

HazelJS Concepts by Package

Agent Concepts

  • HazelJS Agent — LLM-driven component with tools, memory, and optional delegation. Registered with @Agent. See Agent Package.
  • HazelJS Tool — Method callable by an agent during the think-act loop. Registered with @Tool. Tools can require approval, timeouts, and retries. See Agent Package.
  • HazelJS Agent Runtime — Execution engine managing agent lifecycle: load state → load memory → LLM call → tool execution → persist state → respond. See Agent Package.

RAG Concepts

  • RAG (Retrieval-Augmented Generation) — Use vector search and retrieved context to augment LLM prompts. Configured with @RAG and methods like @SemanticSearch. See RAG Package.
  • HazelJS Vector Store — Storage for embeddings with similarity search. HazelJS RAG supports Pinecone, Weaviate, Qdrant, Chroma, pgvector. See RAG Package.
  • HazelJS Agentic RAG — Advanced RAG strategies (query planning, multi-hop, HyDE, corrective RAG) via decorators. See RAG Package.

AI Concepts

  • HazelJS AIEnhancedService — Primary service for LLM calls with fluent API. See AI Package.
  • HazelJS HCEL (HazelJS Composable Expression Language) — Fluent DSL for composing AI chains. See HCEL Guide.
  • HazelJS AssistantFacade — High-level conversational assistant management with memory. See AI Package.
  • HazelJS AIFunction / AITask — AI-powered method or task with provider, model, and optional streaming. See AI Package.

Evaluation & quality

  • Golden dataset — Versioned JSON list of test cases (user input plus optional expected answer substrings, tool names, and document IDs) used to regression-test RAG and agents. See Eval Package.
  • HazelJS eval metrics — Classical IR metrics (precision/recall@k, MRR, NDCG), RAG helpers, trajectory scoring for tool calls, and LLM-judge prompt builders, plus reportEvalForCi for pipelines. See Eval Package.

Infrastructure Concepts

  • HazelJS Circuit Breaker / Retry / Bulkhead / Rate Limit — Resilience patterns via @hazeljs/resilience decorators. See Resilience Package.
  • HazelJS Guardrail — Input/output safety checks via @hazeljs/guardrails. See Guardrails Package.
  • HazelJS Repository — Data access abstraction over Prisma or TypeORM. See Prisma Package, TypeORM Package.
  • HazelJS Flow — Durable execution graph with nodes, edges, wait/resume, idempotency. See Flow Package.
  • HazelJS Service Discovery — Registry and client for service-to-service communication. See Discovery Package.

Next Concepts to Learn