Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions backend/fastify/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
technology: Fastify
domain: backend
level: Senior/Architect
version: "5.x"
tags: [best-practices, deterministic-code, fastify, nodejs, backend, production-ready]
ai_role: Senior Fastify Backend Expert
last_updated: 2026-03-24
---

# 🚀 Fastify Production-Ready Best Practices

[🏠 Back to Home](../../README.md)

This document establishes best practices for Fastify architecture to ensure maximum throughput and deterministic validation.

---

## 1. 🛑 Schema Validation Avoidance
### ❌ Bad Practice
```javascript
app.post('/user', async (request, reply) => {
const { name } = request.body; // No validation
return { status: 'ok' };
});
```
### ⚠️ Problem
Skipping Fastify's built-in schema validation bypasses the internal optimizations and exposes the route to malicious payloads, leading to potential performance degradation and security vulnerabilities.
### ✅ Best Practice
```javascript
const schema = {
body: {
type: 'object',
required: ['name'],
properties: { name: { type: 'string' } }
}
};
app.post('/user', { schema }, async (request, reply) => {
return { status: 'ok' };
});
```

> [!NOTE]
> **Internal Routing:** For more context, refer back to the [Backend Index](../readme.md).

### 🚀 Solution
MANDATORY schema definition for all routes. Utilize JSON Schema to achieve O(1) or O(n) complexity route validation and leverage Fastify's serialization engine.

## 2. 🗂️ Request Lifecycle

```mermaid
sequenceDiagram
participant Client
participant Fastify
participant Route Handler

Client->>Fastify: HTTP Request
Fastify->>Fastify: Schema Validation
alt Validation Failed
Fastify-->>Client: 400 Bad Request
else Validation Passed
Fastify->>Route Handler: Process Request
Route Handler-->>Fastify: Return Payload
Fastify->>Fastify: Schema Serialization
Fastify-->>Client: HTTP Response
end
```
2 changes: 1 addition & 1 deletion backend/mongodb/security-best-practices.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ Enable WiredTiger encryption at rest using a robust Key Management Service (KMS)
security:
enableEncryption: true
encryptionCipherMode: AES256-CBC
encryptionKeyFile: /path/to/master/key/file
encryptionKeyFile: /path/to/primary/key/file
```
---

Expand Down
9 changes: 5 additions & 4 deletions backend/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@ last_updated: 2026-03-22


This folder acts as a container for documentation around the following backend technologies:
- [NestJS](./nestjs/readme.md)
- [ExpressJS](./expressjs/readme.md)
- [Node.js](./nodejs/readme.md)
- [Fastify](./fastify/readme.md)
- [GraphQL](./graphql/readme.md)
- [PostgreSQL](./postgresql/readme.md)
- [Microservices](./microservices/readme.md)
- [MongoDB](./mongodb/readme.md)
- [NestJS](./nestjs/readme.md)
- [Node.js](./nodejs/readme.md)
- [PostgreSQL](./postgresql/readme.md)
- [Redis](./redis/readme.md)
- [Microservices](./microservices/readme.md)

---
## 1. 🛑 Global Domain Bleeding
Expand Down
4 changes: 2 additions & 2 deletions backend/redis/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ A single Redis instance creates a single point of failure. If the node crashes,
```yaml
# Using Redis Cluster or Sentinel for high availability
services:
redis-master:
redis-primary:
image: redis:latest
redis-replica-1:
image: redis:latest
Expand All @@ -46,7 +46,7 @@ Deploy Redis in a Cluster or Sentinel topology to ensure high availability, auto
```mermaid
graph TD
A[Client Request] --> B[Redis Load Balancer / Sentinel]
B --> C[Redis Master]
B --> C[Redis Primary]
C --> D[Redis Replica 1]
C --> E[Redis Replica 2]

Expand Down
Loading
Loading