React UI template for consuming FastAPI backends.
This template provides a production-ready React frontend that integrates with the fastapi-template backend. It demonstrates:
- Type-safe API consumption (generated from OpenAPI)
- Authentication UI (Ory, Auth0, Keycloak, Cognito)
- Mock-first development (MSW + Faker.js)
- Modern React patterns (TanStack Query, React Router 6)
- Full DevOps (Docker, DevSpace)
# Development with mocks (no backend needed)
npm install
npm run dev:mock
# Development with real API
npm run generate:types # Requires backend at localhost:8000
npm run dev| Layer | Technology |
|---|---|
| Build | Vite 5.x |
| Framework | React 18 + TypeScript |
| Styling | Tailwind CSS + shadcn/ui |
| State | TanStack Query |
| Forms | React Hook Form + Zod |
| Testing | Vitest + Playwright |
| Container | Docker (multi-stage) |
| Orchestration | DevSpace |
Use Copier to generate a new project:
# Install Copier
pipx install copier
# Generate project with defaults
copier copy gh:mattwwarren/react-template --vcs-ref copier my-project
# Generate with custom options
copier copy gh:mattwwarren/react-template --vcs-ref copier my-project \
--data project_name="My Dashboard" \
--data auth_enabled=true \
--data auth_provider=ory| Variable | Type | Default | Description |
|---|---|---|---|
project_name |
string | required | Project name (e.g., "User Dashboard") |
project_slug |
string | auto | Package name (lowercase with hyphens) |
description |
string | "A React frontend application" | Brief project description |
port |
int | 5173 | Development server port |
api_url |
string | "http://localhost:8000" | Backend API URL |
auth_enabled |
bool | false | Enable authentication |
auth_provider |
choice | none | Auth provider: none, ory, auth0, keycloak, cognito |
use_mocks |
bool | true | Include MSW mocks for standalone development |
"Invalid template" error:
- Ensure you're using
--vcs-ref copierto pull from the template branch
npm install fails:
- Ensure you have Node.js 20+ installed
API types not generated:
- Run
npm run generate:typesafter starting your backend at the configuredapi_url
This template supports two deployment modes:
Run the frontend standalone with its own k3d cluster. Best for:
- Frontend-only development with MSW mocks
- CI/CD pipelines testing frontend in isolation
- Teams working primarily on UI
cd react-template
# Start local k3d cluster with frontend only
devspace dev
# Access at http://localhost:5173Configuration:
- Uses own cluster:
react_template - API URL defaults to mock service or external URL
- Set
VITE_USE_MOCKS=truefor mock data
Run alongside the backend in a shared cluster. Best for:
- Integration testing
- E2E development
- Staging/production environments
Method 1: Shared Cluster (Manual)
# Terminal 1: Start backend
cd fastapi-template
CLUSTER_NAME=fullstack devspace dev
# Terminal 2: Start frontend (same cluster)
cd react-template
CLUSTER_NAME=fullstack API_URL=http://fastapi-template.warren-enterprises-ltd.svc.cluster.local devspace devMethod 2: Workspace DevSpace (Recommended)
# From workspace root
cd meta-work
devspace dev
# Starts both services in coordinated cluster
# Frontend: http://localhost:5173
# Backend: http://localhost:8000See Workspace DevSpace Configuration below.
| Command | Description |
|---|---|
devspace dev |
Start development with hot reload |
devspace run build-prod |
Build production Docker image |
devspace run k3d-down |
Delete local k3d cluster |
| Variable | Default | Description |
|---|---|---|
CLUSTER_NAME |
react_template |
k3d cluster name |
NAMESPACE |
warren-enterprises-ltd |
Kubernetes namespace |
API_URL |
(in-cluster service) | Backend API URL |
VITE_USE_MOCKS |
false |
Enable MSW mock handlers |
docker build -f docker/Dockerfile --target dev -t react-template:dev .
docker run -p 5173:5173 -v $(pwd)/src:/app/src react-template:devdocker build -f docker/Dockerfile --target prod -t react-template:prod .
docker run -p 8080:80 -e API_URL=http://api.example.com react-template:prodThe production build:
- Multi-stage: builds static assets, serves via nginx
- Runtime API_URL configuration via nginx environment substitution
- Health check endpoint at
/health - Gzipped assets with proper cache headers
For full-stack development, use the workspace-level devspace.yaml at the repository root:
# meta-work/devspace.yaml
version: v2beta1
name: "meta_workspace"
# Orchestrates both frontend and backend
# See workspace root for full configurationFeatures:
- Single
devspace devcommand starts both services - Shared k3d cluster with proper networking
- Coordinated port mapping (5173 for UI, 8000 for API)
- Frontend auto-configured to reach backend via in-cluster DNS
# Unit tests with Vitest
npm test
# E2E tests with Playwright
npm run test:e2e
# Coverage report
npm run test:coverage- CLAUDE.md - Development patterns and conventions
MIT