Skip to content

Introduce backend-utils Option for Modern Server Scaffolding#210

Open
AyushBhagat151105 wants to merge 6 commits into
Marve10s:mainfrom
AyushBhagat151105:feat/backend-utils-2
Open

Introduce backend-utils Option for Modern Server Scaffolding#210
AyushBhagat151105 wants to merge 6 commits into
Marve10s:mainfrom
AyushBhagat151105:feat/backend-utils-2

Conversation

@AyushBhagat151105
Copy link
Copy Markdown

Goal & Overview

This Pull Request introduces the backend-utils option to the TypeScript ecosystem. This feature provides scaffolded projects with production-grade utilities for HTTP responses, async route handling, global error management, and standard health checks. It fully supports and integrates with all core backend frameworks including Hono, Express, Elysia, Fastify, feTS, and NestJS.

Additionally, this PR refines CLI integration tests by adding robust isolation for system paths (home directory, app data) to prevent tests from writing into or leaking from the user's real host directories, specifically addressing Windows-specific path issues.


Key Features & Proposed Changes

1. Schema & Stack Configuration

  • Added the backendUtils category to option metadata (packages/types/src/option-metadata.ts) with appropriate branding labels.
  • Integrated the option into stack configuration structures (apps/web/src/lib/stack-project-config-base.ts), templates, fixtures, and documentation schemas.
  • Exposed new documentation sections detailing the backend-utils option on the web platform (apps/web/content/docs/ecosystems/typescript.mdx and reference directories).

2. Interactive CLI Prompts

  • Implemented resolveBackendUtilsPrompt in apps/cli/src/prompts/backend-utils.ts to intelligently prompt when a compatible backend is chosen (Hono, Express, Elysia, Fastify, etc.) and auto-default to none for incompatible ones (Convex, AdonisJS, etc.).
  • Registered the resolver into PROMPT_RESOLVER_REGISTRY in apps/cli/src/prompts/prompt-resolver-registry.ts.
  • Introduced early project name validation in createProjectHandler in apps/cli/src/helpers/core/command-handlers.ts to prevent invalid directory/OS configurations early in execution.

3. Core Core Templates & Utility Library (server/base)

We created custom templates under packages/template-generator/templates/backend-utils/backend-utils/server/base/src/:

  • lib/api-response.ts.hbs: Declares standard HttpStatus codes and an ApiResponse wrapper. It structures standard error and success responses with uniform fields:
    • success (boolean status indicator)
    • statusCode (numerical HTTP status code)
    • message (human-readable message)
    • data (optional cargo)
    • errors (optional field for nested/validation error details)
    • timestamp (ISO standard string)
  • lib/async-handler.ts.hbs: Provides async wrapper helpers tailored to different frameworks (Express, Hono, Fastify, Elysia, NestJS) to safely delegate unhandled exceptions to the framework's native error lifecycles.
  • lib/error-handler.ts.hbs: Standardizes global exceptions:
    • Express global error middleware
    • Hono global .onError middleware
    • Fastify custom error hook
    • Elysia .onError plugin handler
    • NestJS @Catch() Exception Filter (GlobalExceptionFilter)
  • routes/health.ts.hbs: Provides a standard /health and /health/ready check endpoint pre-wired with the new asyncHandler and ApiResponse objects.

4. Framework Integration

Integrated the new middleware and health routes conditionally (#if (eq backendUtils "backend-utils")) into the entry points of:

  • Elysia: Integrated .onError(errorHandler) and .use(health) router.
  • Express: Integrated app.use("/health", health) and final app.use(errorHandler) middleware.
  • Hono: Integrated app.onError(errorHandler) and app.route("/health", health).
  • NestJS: Integrated app.useGlobalFilters(new GlobalExceptionFilter()) and wired HealthController inside AppModule.

5. Testing Infrastructure & Environment Isolation

  • Fixed environment leaks in test suites (apps/cli/test/setup.ts and apps/cli/test/add-history-commands.test.ts) by isolating directory paths. Tests now override:
    • HOME
    • XDG_CONFIG_HOME
    • XDG_DATA_HOME
    • APPDATA (critical for Windows AppData isolation)
    • LOCALAPPDATA (critical for Windows LocalAppData isolation)
  • Isolated environment overrides to prevent global workspace conflicts.
  • Stabilized CLI integration test suites by raising test timeouts to 30s for complex scenarios to accommodate differing environments.

I am open for feedback and review.🚀

@vercel
Copy link
Copy Markdown

vercel Bot commented May 30, 2026

@AyushBhagat151105 is attempting to deploy a commit to the Ibrahim's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added size:XL 500-999 effective changed lines (test files excluded in mixed PRs). vouch:unvouched PR author is not yet trusted in the VOUCHED list. labels May 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XL 500-999 effective changed lines (test files excluded in mixed PRs). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant