npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

fastify-oop-decorators

v0.2.1

Published

Lightweight TypeScript decorators for Fastify

Downloads

49

Readme

Fastify OOP Decorators

A lightweight Object-Oriented Programming (OOP) decorator ecosystem built specifically for Fastify v5.

fastify-oop-decorators is a Fastify plugin that brings a robust, modular, and decorator-based architecture (heavily inspired by Spring Boot, Angular, and NestJS) straight into your Fastify applications.

Unlike other frameworks that use heavy adapters to support multiple HTTP servers, this library is built exclusively for Fastify. This means zero abstraction overhead and 100% compatibility with the native Fastify ecosystem.


Why use this library?

  • Fastify Ecosystem First: You are not locked into a massive, restrictive framework. This is just a Fastify plugin. You maintain full access to standard Fastify plugins (like @fastify/cors, @fastify/jwt, etc.) without jumping through hoops.
  • Better Performance: Because there is no multi-framework abstraction layer (like you would find with NestJS's FastifyAdapter), it runs exceptionally fast. Early benchmarks show a ~25% performance boost on simple routes (without DTOs) and a ~20% boost with validation, compared to traditional heavy frameworks. (Detailed benchmarks coming soon).
  • Lightning-Fast Validation: Say goodbye to the heavy class-validator. We natively leverage Fastify's highly optimized JSON schemas (powered by AJV) to validate requests and responses at blazing speeds.

Installation

You have two options to get started with fastify-oop-decorators: use our CLI tool to generate a boilerplate project (recommended), or install it manually into an existing project.

Option 1: Quick Start with the CLI (Recommended)

The easiest way to get started is to use our official scaffolding CLI tool. Run the following command in your terminal:

npm create fastify-oop-decorators@latest my-awesome-api

The interactive prompt will guide you through setting up your project:

  • Choose your package manager (npm, pnpm, yarn, or bun).
  • Include ajv-decorators for class-based DTO validation.
  • Pick your preferred linter (ESLint, Biome, or none).

Once the setup is complete, navigate into your new project and start the development server:

cd my-awesome-api
npm run dev

Option 2: Manual Installation

If you prefer to add the library to an existing project, install the required dependencies:

npm install fastify-oop-decorators reflect-metadata fastify
# or
pnpm add fastify-oop-decorators reflect-metadata fastify

Note: Make sure to enable experimentalDecorators and emitDecoratorMetadata in your tsconfig.json.


Manual Usage (Quick Start)

If you chose the manual installation, here is how easy it is to get started:

import Fastify from 'fastify';
import { bootstrap, Controller, Get, Module } from 'fastify-oop-decorators';

// 1. Define your Controller
@Controller('/hello')
class HelloController {
  @Get()
  sayHello() {
    return { message: 'Hello from Fastify OOP!' };
  }
}

// 2. Define your Module
@Module({
  controllers: [HelloController],
})
class AppModule {}

// 3. Bootstrap the application
async function start() {
  const app = Fastify({ logger: true });
  
  // Attach the OOP ecosystem to Fastify
  await bootstrap(app, AppModule);

  await app.listen({ port: 3000 });
}

start();

Complementary Library: AJV-Decorators

To push optimization even further while maintaining an excellent Developer Experience (DX), I highly recommend using AJV-Decorators alongside this library.

It allows you to build your DTOs using classes and decorators (just like class-validator), but under the hood, it generates native JSON schemas for AJV.

The result? You get clean, OOP-style code without the performance penalty of class-validator, fully benefiting from AJV's speed—which is the fastest validator out there according to their own benchmarks. (This option is offered natively if you use the CLI tool).


API & Decorators (Inspired by NestJS)

Honestly, if you are familiar with NestJS, you already know how to use most of this library. The core decorators (@Module, @Controller, @Get, @Post, @Body, @UseGuards, etc.) work exactly as you'd expect.

However, we added a few Fastify-specific decorators to help you get the most out of the underlying server:

  • @InjectPlugin('pluginName'): Directly inject a Fastify plugin (like a database connection or Redis client) into your services.
  • @Plugin(): Extract the Fastify server instance directly from your route parameters.
  • @Schema(), @BodySchema(), @ResponseSchema(): Hook directly into Fastify's native AJV compiler for your routes.

(Full, detailed documentation is currently in the works).


Roadmap

The current main goal is a modular refactor. I plan to split this repository into smaller, dedicated packages (e.g., @fastify-oop/core, @fastify-oop/websockets) so you only have to install exactly what you need, keeping your final build as light as possible.


Contributing & Support

Contributions are more than welcome! Whether it's adding tests, refining benchmarks, or proposing new Fastify-centric features, feel free to open a PR or an issue.

If you like the project or if it helps you transition from NestJS to pure Fastify, please consider leaving a star (⭐) on the repository. It really helps the project grow!