Decorator (Backend)
ELI5 — The Vibe Check
A backend decorator wraps a function or class to add extra behavior without modifying the original. In NestJS, @Controller(), @Get(), @Injectable() are all decorators. In Python, @app.route and @login_required are decorators. They're like stickers you slap on code to give it superpowers.
Real Talk
In backend frameworks, decorators are functions that modify or enhance classes, methods, or properties using the decorator pattern. They enable declarative programming by annotating code with cross-cutting concerns like routing, authentication, caching, and validation. TypeScript decorators (NestJS) and Python decorators (FastAPI, Flask) are the most common implementations.
Show Me The Code
@Controller('users')
class UserController {
@Get(':id')
@UseGuards(AuthGuard)
@Cacheable(60)
async getUser(@Param('id') id: string) {
return this.userService.findById(id);
}
}
When You'll Hear This
"Add the @Cacheable decorator to cache that endpoint for 60 seconds." / "NestJS decorators handle routing, auth, and validation declaratively."
Related Terms
Decorator Pattern
You have a Coffee object. You want Coffee with Milk. Coffee with Sugar. Coffee with Milk and Sugar. With inheritance you'd need four classes.
Guard
A guard in NestJS is a gatekeeper that decides if a request should be allowed through. Auth guards check if you're logged in.
Interceptor
An interceptor catches requests and responses on the way in and out, letting you transform them.
NestJS
NestJS is Node.js with structure. Plain Express can get messy in large projects.