Skip to content

Commit 2c30572

Browse files
committed
feat(web): set up tRPC v11 API layer with React Query v5
Closes #36 - Install @trpc/server, @trpc/client, @trpc/react-query, @tanstack/react-query, zod - Scaffold server/trpc.ts: TRPCContext, publicProcedure, protectedProcedure (Bearer/cookie auth), createCallerFactory - Add routers: health (proxies Go backend), auth (session/signOut stubs), notifications (FCM token stub) - Wire /api/trpc/[trpc] fetchRequestHandler (GET + POST) - Add lib/trpc/client.tsx: TRPCProvider wrapping QueryClientProvider - Add lib/trpc/server.ts: cached createServerCaller for Server Components - Wire TRPCProvider via app/providers.tsx into root layout - Add Vitest tests for health router and protectedProcedure (UNAUTHORIZED, Bearer, cookie) - Pin postgres:16 in docker-compose.yml - Update docs: styling.md and components.md (shadcn/ui), data-fetching.md (tRPC section), new trpc.md
1 parent b471f47 commit 2c30572

24 files changed

Lines changed: 813 additions & 64 deletions

‎backend/docker-compose.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
services:
22
psql_bp:
3-
image: postgres:latest
3+
image: postgres:16
44
restart: unless-stopped
55
environment:
66
POSTGRES_DB: ${BLUEPRINT_DB_DATABASE}

‎web/AGENTS.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ Read the relevant doc before implementing. These are kept in sync with the code
5656
|---|---|
5757
| App Router, route files, layouts, navigation | [`docs/routing.md`](docs/routing.md) |
5858
| Server Components, data fetching, Server Actions | [`docs/data-fetching.md`](docs/data-fetching.md) |
59+
| tRPC routers, React Query, client/server usage | [`docs/trpc.md`](docs/trpc.md) |
5960
| Tailwind CSS v4, theme tokens, dark mode | [`docs/styling.md`](docs/styling.md) |
6061
| Component conventions, TypeScript rules | [`docs/components.md`](docs/components.md) |
6162
| Testing setup, patterns, what to test | [`docs/testing.md`](docs/testing.md) |

‎web/app/api/trpc/[trpc]/route.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { fetchRequestHandler } from '@trpc/server/adapters/fetch'
2+
import { type NextRequest } from 'next/server'
3+
import { createTRPCContext } from '@/server/trpc'
4+
import { appRouter } from '@/server/routers/_app'
5+
6+
const handler = (req: NextRequest) =>
7+
fetchRequestHandler({
8+
endpoint: '/api/trpc',
9+
req,
10+
router: appRouter,
11+
createContext: () => createTRPCContext({ req }),
12+
})
13+
14+
export { handler as GET, handler as POST }

‎web/app/layout.tsx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Metadata } from "next";
22
import { Geist, Geist_Mono } from "next/font/google";
33
import "./globals.css";
4+
import { Providers } from "./providers";
45

56
const geistSans = Geist({
67
variable: "--font-geist-sans",
@@ -27,7 +28,9 @@ export default function RootLayout({
2728
lang="en"
2829
className={`${geistSans.variable} ${geistMono.variable} h-full antialiased`}
2930
>
30-
<body className="min-h-full flex flex-col">{children}</body>
31+
<body className="min-h-full flex flex-col">
32+
<Providers>{children}</Providers>
33+
</body>
3134
</html>
3235
);
3336
}

‎web/app/page.tsx‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1+
import About from "@/components/home/about";
2+
import Hero from "@/components/home/hero";
3+
14
const page = () => {
25
return (
3-
<div></div>
6+
<div>
7+
<Hero />
8+
<About />
9+
</div>
410
);
511
};
612

7-
export default page;
13+
export default page;

‎web/app/providers.tsx‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use client'
2+
3+
import { TRPCProvider } from '@/lib/trpc/client'
4+
5+
export function Providers({ children }: { children: React.ReactNode }) {
6+
return <TRPCProvider>{children}</TRPCProvider>
7+
}

‎web/components/home/about.tsx‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const About = () => {
2+
return <section></section>;
3+
};
4+
5+
export default About;

‎web/components/home/hero.tsx‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const Hero = () => {
2+
return <section></section>;
3+
};
4+
5+
export default Hero;

‎web/docs/_index.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ The `docs` agent reads this index first to locate the right file.
66
| Topic | File | Source files covered |
77
|---|---|---|
88
| App Router structure & route conventions | [routing.md](routing.md) | `app/layout.tsx`, `app/page.tsx`, `next.config.ts` |
9-
| Data fetching patterns | [data-fetching.md](data-fetching.md) | `app/page.tsx`, `app/layout.tsx` |
9+
| Data fetching patterns | [data-fetching.md](data-fetching.md) | `app/page.tsx`, `app/layout.tsx`, `lib/trpc/server.ts`, `lib/trpc/client.tsx` |
10+
| tRPC v11 + React Query v5 — routers, context, client/server usage | [trpc.md](trpc.md) | `server/trpc.ts`, `server/routers/_app.ts`, `lib/trpc/client.tsx`, `lib/trpc/server.ts`, `app/providers.tsx` |
1011
| Styling with Tailwind CSS v4 | [styling.md](styling.md) | `app/globals.css`, `postcss.config.mjs` |
1112
| Component conventions | [components.md](components.md) | `app/` (all component files) |
1213
| Testing patterns | [testing.md](testing.md) | `vitest.config.ts`, `vitest.setup.ts`, `__tests__/page.test.tsx` |

‎web/docs/components.md‎

Lines changed: 91 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
---
22
topic: components
3-
last_verified: 2026-06-14
3+
last_verified: 2026-06-23
44
sources:
5-
- app/layout.tsx
6-
- app/page.tsx
5+
- components/ui/button.tsx
6+
- components/common/container.tsx
7+
- components/common/h1.tsx
8+
- components/common/h2.tsx
9+
- components/common/h3.tsx
10+
- components/common/loader.tsx
11+
- components/home/hero.tsx
12+
- components/home/about.tsx
13+
- lib/utils.ts
714
---
815

916
# Component Conventions
@@ -21,44 +28,99 @@ Only when you need:
2128

2229
Do not add `"use client"` to layouts, pages, or wrapper components just because a child needs it — push `"use client"` down to the smallest possible component.
2330

24-
## File placement
31+
## Directory structure
2532
```
26-
app/ # route files only (page.tsx, layout.tsx, loading.tsx, error.tsx)
27-
components/ # shared reusable components
28-
ui/ # generic primitives (Button, Input, Modal, etc.)
29-
[feature]/ # feature-specific components (e.g., components/auth/)
30-
lib/ # utility functions, helpers, non-React code
31-
types/ # shared TypeScript type definitions
33+
components/
34+
ui/ — shadcn primitives (avatar, badge, button, card, dialog, dropdown-menu,
35+
input, label, separator, skeleton, sonner)
36+
common/ — cross-feature reusable UI (container, h1, h2, h3, loader)
37+
home/ — feature-scoped components (hero, about)
38+
layout/ — layout wrappers (navbar, footer, etc.)
39+
lib/
40+
utils.ts — cn() utility and other non-React helpers
41+
types/ — shared TypeScript type definitions
3242
```
3343

34-
## Component file structure
44+
Route files (`page.tsx`, `layout.tsx`, `loading.tsx`, `error.tsx`) live in `app/` only.
45+
46+
## `cn()` utility
47+
All conditional class merging uses `cn()` from `lib/utils.ts`:
48+
```ts
49+
// lib/utils.ts
50+
import { clsx, type ClassValue } from "clsx"
51+
import { twMerge } from "tailwind-merge"
52+
53+
export function cn(...inputs: ClassValue[]) {
54+
return twMerge(clsx(inputs))
55+
}
56+
```
57+
Import it as `import { cn } from "@/lib/utils"` in every component that merges classes.
58+
59+
## `components/ui/` — shadcn primitives
60+
Generated by shadcn/ui. Use `class-variance-authority` (`cva`) for variant logic and `Slot` from `radix-ui` for the `asChild` pattern. Do not hand-edit these files directly; re-run the shadcn CLI to update them.
61+
62+
Pattern from `button.tsx`:
3563
```tsx
36-
// components/ui/Button.tsx
37-
import type { ButtonHTMLAttributes } from 'react';
64+
import { cva, type VariantProps } from "class-variance-authority"
65+
import { Slot } from "radix-ui"
66+
import { cn } from "@/lib/utils"
3867

39-
type ButtonProps = ButtonHTMLAttributes<HTMLButtonElement> & {
40-
variant?: 'primary' | 'secondary';
41-
};
68+
const buttonVariants = cva("<base-classes>", {
69+
variants: {
70+
variant: { default: "...", outline: "...", secondary: "...", ghost: "...", destructive: "...", link: "..." },
71+
size: { default: "...", xs: "...", sm: "...", lg: "...", icon: "...", "icon-xs": "...", "icon-sm": "...", "icon-lg": "..." },
72+
},
73+
defaultVariants: { variant: "default", size: "default" },
74+
})
4275

43-
export function Button({ variant = 'primary', children, ...props }: ButtonProps) {
76+
function Button({
77+
className,
78+
variant = "default",
79+
size = "default",
80+
asChild = false,
81+
...props
82+
}: React.ComponentProps<"button"> &
83+
VariantProps<typeof buttonVariants> & {
84+
asChild?: boolean
85+
}) {
86+
const Comp = asChild ? Slot.Root : "button"
4487
return (
45-
<button
46-
className={variant === 'primary' ? 'bg-foreground text-background' : 'bg-background text-foreground border'}
88+
<Comp
89+
data-slot="button"
90+
data-variant={variant}
91+
data-size={size}
92+
className={cn(buttonVariants({ variant, size, className }))}
4793
{...props}
48-
>
49-
{children}
50-
</button>
51-
);
94+
/>
95+
)
5296
}
97+
98+
export { Button, buttonVariants }
99+
```
100+
101+
## `components/common/` — hand-crafted cross-feature components
102+
These are hand-written and use `cn()` with Tailwind classes directly. They do not use `cva`.
103+
104+
`Container` — constrains max width and centers content:
105+
```tsx
106+
const Container = ({ children, className }: { children: React.ReactNode; className?: string }) => (
107+
<div className={cn("mx-auto max-w-7xl", className)}>{children}</div>
108+
)
53109
```
54110

111+
`H1`, `H2`, `H3` — semantic heading wrappers that forward a `className` prop through `cn()`. `H2` makes `className` optional; `H1` and `H3` require it.
112+
113+
`Loader` — accepts a required `className` prop and renders a `div` with those classes applied via `cn()`.
114+
115+
## `components/home/` — feature-scoped components
116+
Components specific to the home feature. Scoped to avoid polluting `common/`.
117+
55118
## TypeScript rules
56119
- No `any`. Use proper interfaces or `unknown`.
57-
- Extend native HTML element types (`ButtonHTMLAttributes`, `InputHTMLAttributes`) for wrapper components.
58-
- Keep component prop types in the same file as the component unless shared across multiple files.
59-
- Shared types → `types/` directory.
120+
- For shadcn primitives, extend `React.ComponentProps<"element">` (not `ButtonHTMLAttributes`) and combine with `VariantProps<typeof variantsFn>`.
121+
- For common/feature components, inline prop types in the same file unless the type is shared across multiple files — then move it to `types/`.
122+
- Import types with `import type` to keep runtime bundles clean.
123+
- React 19: JSX transform is automatic — no `import React from "react"` needed unless you reference `React.*` directly.
60124

61125
## Imports
62-
- Use TypeScript path aliases from `tsconfig.json` — check it before writing relative import chains.
63-
- Import React only when needed (React 19 — JSX transform is automatic, no `import React` needed).
64-
- Import types with `import type` to keep runtime bundles clean.
126+
Use TypeScript path aliases (`@/`) from `tsconfig.json`. Do not write deep relative import chains.

0 commit comments

Comments
 (0)