Skip to content

Commit 5250a77

Browse files
authored
docs: add CLAUDE.md for project guidance and architecture overview (#158)
Adds rules for Claude Code. Relates to #59
1 parent c8c5116 commit 5250a77

File tree

1 file changed

+169
-0
lines changed

1 file changed

+169
-0
lines changed

CLAUDE.md

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Overview
6+
7+
This is the **Pomerium MCP Chat Demo** - a minimal chat application showcasing remote Model Context Protocol (MCP) servers secured with Pomerium. The application demonstrates how to build internal applications that use agentic frameworks and LLM APIs with MCP server integration.
8+
9+
## Technology Stack
10+
11+
- **Frontend**: React 19 with TypeScript in strict mode
12+
- **Framework**: TanStack Start (SSR routing with file-based patterns)
13+
- **Styling**: Tailwind CSS 4.0 + Shadcn/ui components
14+
- **Validation**: Zod for runtime validation and TypeScript integration
15+
- **State Management**: React Query (TanStack Query) for server state, React Context for global state
16+
- **Build Tool**: Vite 6.3
17+
- **Testing**: Vitest with jsdom environment
18+
- **Documentation**: Storybook for component documentation
19+
20+
## Development Commands
21+
22+
```bash
23+
# Development server with hot reloading
24+
npm run dev
25+
26+
# Production build
27+
npm run build
28+
29+
# Start production server
30+
npm run start
31+
32+
# Testing
33+
npm run test # Run tests once
34+
npm run test:ci # Run tests with coverage
35+
36+
# Code quality
37+
npm run lint # ESLint check
38+
npm run format # Prettier format
39+
npm run format:check # Check formatting and linting
40+
41+
# Storybook
42+
npm run storybook # Development Storybook server
43+
npm run build-storybook # Build Storybook for production
44+
```
45+
46+
## Architecture Overview
47+
48+
### Routing Pattern (TanStack Start)
49+
50+
- **File-based routing** in `src/routes/`
51+
- **Client routes**: `.tsx` files with `createFileRoute()`
52+
- **Server routes**: `.ts` files in `src/routes/api/` with `createServerFileRoute()`
53+
- All routes must include `errorBoundary` and `pendingBoundary` for proper error/loading handling
54+
55+
### State Management Strategy
56+
57+
- **Route Loaders**: For initial page data, SSR requirements, and critical path data
58+
- **React Query**: For dynamic/optional data, mutations, and client-side updates
59+
- **React Context**: For global application state (user, theme, etc.)
60+
61+
### Component Architecture
62+
63+
- **UI Components**: Primarily Shadcn/ui components in `src/components/ui/`
64+
- **Custom Components**: Application-specific components in `src/components/`
65+
- **Storybook Stories**: Every component must have a colocated `.stories.tsx` file
66+
- **Tests**: Components should have `.test.tsx` files using Vitest + Testing Library
67+
68+
### Data Validation
69+
70+
- **Zod schemas** defined in `src/lib/schemas.ts`
71+
- Validate all external data: API responses, user input, environment variables
72+
- Use `.safeParse()` for robust error handling
73+
74+
## MCP Integration Patterns
75+
76+
### MCP Client Application
77+
78+
This app runs as an MCP client behind Pomerium with `mcp.client: {}` configuration. Key patterns:
79+
80+
1. **Server Discovery**: Use `/.pomerium/mcp/routes` endpoint to get available MCP servers
81+
2. **Authentication Flow**: Direct users to `/.pomerium/mcp/connect` for upstream OAuth when needed
82+
3. **Tool Calls**: Pass the external token to LLM APIs for MCP server access
83+
4. **User Identity**: Read `X-Pomerium-Assertion` header for user claims
84+
85+
### Key MCP Features
86+
87+
- **Chat Interface**: AI-powered chat using OpenAI with tool calling capabilities
88+
- **Server Management**: Dynamic server selection and connection status
89+
- **Tool Toggles**: Enable/disable specific tools (code interpreter, web search, etc.)
90+
- **Model Selection**: Support for different OpenAI models
91+
92+
## File Organization Conventions
93+
94+
### Import Patterns
95+
96+
Always use `@/` alias for internal imports:
97+
98+
```typescript
99+
// ✅ Good
100+
import { Button } from '@/components/ui/button'
101+
import { userSchema } from '@/lib/schemas'
102+
103+
// ❌ Bad
104+
import { Button } from '../components/ui/button'
105+
```
106+
107+
### Directory Structure
108+
109+
```
110+
src/
111+
├── components/ # Shared UI components
112+
│ └── ui/ # Shadcn/ui components
113+
├── contexts/ # React Context providers
114+
├── hooks/ # Custom React hooks
115+
├── lib/ # Utilities and schemas
116+
├── mcp/ # MCP client integration
117+
├── routes/ # TanStack Start routes
118+
│ └── api/ # Server routes (.ts files)
119+
└── styles.css # Global Tailwind styles
120+
```
121+
122+
## Code Quality Standards
123+
124+
### TypeScript
125+
126+
- **Strict mode enabled** - never use `any` type
127+
- Use proper generics and type inference
128+
- Validate external data with Zod schemas
129+
130+
### Component Patterns
131+
132+
- **Function components only** with proper TypeScript interfaces
133+
- **Accessibility first** - include ARIA attributes and semantic HTML
134+
- **Error boundaries** and loading states in all routes
135+
- **Mobile-first responsive design** with Tailwind
136+
137+
### Testing Requirements
138+
139+
- Component tests using Vitest + Testing Library
140+
- Storybook stories for all custom components
141+
- Focus on user interactions and accessibility
142+
143+
## Important Development Notes
144+
145+
- **Shadcn Components**: Add new components with `npx shadcn@latest add <component-name>`
146+
- **Environment**: Uses Docker Compose setup with Pomerium for full MCP functionality
147+
- **Authentication**: Integrated with Pomerium OAuth2 flows
148+
- **Audit Logging**: MCP tool calls are logged for monitoring and compliance
149+
150+
## Pomerium MCP Configuration
151+
152+
The application expects specific Pomerium route configuration:
153+
154+
```yaml
155+
# Client route (this app)
156+
- from: https://mcp-app-demo.your-domain.com
157+
to: http://mcp-app-demo:3000
158+
mcp:
159+
client: {}
160+
161+
# Server routes (MCP servers)
162+
- from: https://mcp-server.your-domain.com
163+
to: http://mcp-server:8080/mcp
164+
name: 'Server Name'
165+
mcp:
166+
server: {}
167+
```
168+
169+
This configuration enables the app to discover MCP servers and handle authentication flows seamlessly.

0 commit comments

Comments
 (0)