Skip to content

feat: add backend-trpc module #11

@ronak-create

Description

@ronak-create

Summary

Add tRPC as a backend option (or as an add-on layer) for building fully type-safe APIs with no schema or codegen step.

Why

tRPC is the default choice for Next.js + Express stacks where the frontend and backend share a TypeScript monorepo.
It eliminates an entire class of type/contract mismatches between client and server.


Design consideration

tRPC is unusual: it's not a standalone server — it runs on top of an existing HTTP framework (Express, Hono, Next.js API routes).

This means it likely fits better as an add-on (foundation add trpc) rather than a backend replacement.
Discussion on the right category is welcome.


Files to generate

  • src/trpc/router.ts — root router with example procedure
  • src/trpc/context.ts — context factory
  • src/trpc/trpc.tsinitTRPC initialisation
  • src/trpc/client.ts — typed client (for use in frontend)
  • Integration patch into existing:
    • server.ts (Express middleware mount)
    • OR src/app/api/trpc/[trpc]/route.ts (Next.js App Router adapter)

Implementation hints

  • Key dependencies:

    • @trpc/server
    • @trpc/client
    • @trpc/react-query (if TanStack Query is also selected)
  • compatibility.requires:

    • at least one of:
      • backend-express
      • backend-hono
      • frontend-nextjs
  • When both tRPC and TanStack Query are selected:

    • @trpc/react-query bridge should be wired automatically
  • This is a cross-cutting module:

    • onBeforeCompose hook may be needed to inspect selected backend and inject the correct adapter

Contributor guidance

Refer to CONTRIBUTING.md → "Adding a New Module"


Acceptance criteria

  • foundation add trpc (or create-time selection) wires tRPC into the selected backend
  • Generated router and client type-check end-to-end with zero errors
  • React client is wired when frontend-nextjs + TanStack Query are also selected
  • Snapshot tests for Express + tRPC and Next.js + tRPC combinations

Metadata

Metadata

Assignees

No one assigned

    Labels

    module: backendRelated to backend frameworks, APIs, server logic, or routing.new-modulebuild something here

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions