Add production-readiness features: health checks, security, pagination, sanitization#125
Merged
madhavcodez merged 2 commits intomainfrom Mar 18, 2026
Merged
Conversation
Security: session expiry (24h TTL), CORS allowlist, helmet headers, HTML sanitization for user content, env var validation with Zod. Infrastructure: Dockerfile with multi-stage build, prod docker-compose, graceful shutdown handler, real health check with DB/Redis probes. Performance: cursor-based pagination on feed/search/recently-played, missing DB indexes (ratings, reviews, activity_events), full-text search with tsvector/GIN index on albums. API: correct 201 status codes on creation, structured JSON logging with request IDs, OpenAPI/Swagger docs at /docs. DevOps: npm audit in CI, engines field in package.json, Dependabot config, migration naming conflicts fixed (003_ duplicates). Tests updated for new status codes + production readiness test suite. https://claude.ai/code/session_01HXWnSTisXW9rizJZW4mV7X
- Env validation: restore dev defaults for DATABASE_URL/REDIS_URL so tests work without running services; enforce explicit values in prod - DB client: add connection timeout (5s), Redis retry limit (3 attempts), robust close() that handles disconnected state - Server: clean up DB on migration failure to prevent orphaned connections - Pagination: guard against undefined cursor on empty result sets, validate cursor length (max 128 chars) - Sanitize: encode remaining HTML entities after tag stripping - Migration: add COALESCE for null-safe tsvector generation - Tests: fix setup() to close app on failure (prevents ioredis retry loops hanging the process), tighten status code assertions (201 exact) https://claude.ai/code/session_01HXWnSTisXW9rizJZW4mV7X
madhavcodez
pushed a commit
that referenced
this pull request
Mar 21, 2026
Merges claude/audit-production-readiness-Uc304 into main. No conflicts — PR changes are backend-only, our recent commit was iOS + contracts. PR contents: - Helmet security headers, CORS allowlist, request ID tracking - Enhanced /health endpoint with DB + Redis probes (503 on degraded) - Fastify Swagger for OpenAPI 3.1.0 docs at /docs - Cursor-based pagination on /v1/search, /v1/feed, /v1/log/recently-played - HTML sanitization (stripHtml) on reviews and list descriptions - Migration 006: session expiry, full-text search vectors, performance indexes - Zod-validated env config (enforces explicit URLs in production) - Multi-stage Dockerfile + docker-compose.prod.yml with resource limits - Production-readiness test suite - 201 Created status codes for POST endpoints - Dependabot config for automated dependency updates
madhavcodez
pushed a commit
that referenced
this pull request
Mar 21, 2026
Merges claude/audit-production-readiness-Uc304 into main. No conflicts — PR changes are backend-only, our recent commit was iOS + contracts. PR contents: - Helmet security headers, CORS allowlist, request ID tracking - Enhanced /health endpoint with DB + Redis probes (503 on degraded) - Fastify Swagger for OpenAPI 3.1.0 docs at /docs - Cursor-based pagination on /v1/search, /v1/feed, /v1/log/recently-played - HTML sanitization (stripHtml) on reviews and list descriptions - Migration 006: session expiry, full-text search vectors, performance indexes - Zod-validated env config (enforces explicit URLs in production) - Multi-stage Dockerfile + docker-compose.prod.yml with resource limits - Production-readiness test suite - 201 Created status codes for POST endpoints - Dependabot config for automated dependency updates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR hardens the backend for production deployment by adding comprehensive health checks, security headers, API documentation, cursor-based pagination, input sanitization, and improved environment configuration validation.
Key Changes
Security & Headers
x-request-idheader for observabilityHealth Checks & Observability
/healthendpoint to perform actual database and Redis connectivity probesAPI Documentation
/docsendpoint with JSON schema at/docs/jsonPagination
pagination.tsutility with cursor-based pagination supportparsePaginationParams()andbuildPaginatedResponse()helpers/v1/search,/v1/feed, and/v1/log/recently-playedendpointsInput Sanitization
sanitize.tsmodule withstripHtml()function for plain-text fieldsDatabase Improvements
006_session_expiry_and_indexes.sql:expires_atcolumnexpires_at > NOW()HTTP Status Codes
Environment Configuration
Docker & Deployment
Dockerfilewith multi-stage build (builder + production)docker-compose.prod.ymlwith resource limits and health checks.dockerignoreto optimize image sizebackend/.dockerignorefor production buildsTesting & CI
production-readiness.test.tscovering:Dependencies
@fastify/helmetfor security headers@fastify/swaggerand@fastify/swagger-uifor API documentationNotable Implementation Details
idx_sessions_expiresindexhttps://claude.ai/code/session_01HXWnSTisXW9rizJZW4mV7X