# Encapsulation और Scope — Fastify

Source: https://www.geekswithgeeks.com/hi/fastify/ff-encapsulation

> Conflicts से बचने के लिए plugins, routes, और hooks को ठीक से scoped रखें।

## Plugin scope isolation

एक plugin के अंदर registered plugins उस plugin के लिए scoped होते हैं। Decorators, hooks, और routes sibling plugins में leak नहीं होते।

## Nested plugins

एक plugin को register करके sub-apps बनाएँ जो child plugins को register करता है।

```javascript
// routes/v1.js
export default async function v1Routes(fastify, opts) {
  fastify.get('/health', async () => ({ version: '1' }));
}

// routes/v2.js
export default async function v2Routes(fastify, opts) {
  fastify.get('/health', async () => ({ version: '2' }));
}

// server.js
fastify.register(v1Routes, { prefix: '/v1' });
fastify.register(v2Routes, { prefix: '/v2' });
// GET /v1/health -> { version: '1' }
// GET /v2/health -> { version: '2' }
```
