frontend-scaffolding
Frontend Scaffolding
Scaffold a React frontend with Tailwind CSS v4, React Router v6, React Query (TanStack Query), Axios API client, and established patterns.
Structure Overview
apps/webapp/src/
├── app/
│ └── app.tsx # Main app component with routes
├── api/
│ ├── client.ts # Axios client configuration
│ └── {resource}.ts # Resource-specific API functions
├── components/
│ ├── common/ # Shared components (Button, Card, etc.)
│ ├── layouts/ # Layout components
│ └── nav/ # Navigation components
├── pages/
│ └── Home.tsx # Page components
├── hooks/
│ └── use{Resource}.ts # React Query hooks
├── lib/
│ └── queryClient.ts # React Query client
├── styles.css # Global styles and Tailwind theme
└── main.tsx # Application entry point
Installation
npm install react react-dom react-router-dom axios @tanstack/react-query
npm install -D tailwindcss @tailwindcss/vite
Implementation Steps
1. Main Entry Point (main.tsx)
import { StrictMode } from 'react';
import * as ReactDOM from 'react-dom/client';
import { BrowserRouter } from 'react-router-dom';
import { QueryClientProvider } from '@tanstack/react-query';
import App from './app/app';
import { queryClient } from './lib/queryClient';
const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);
root.render(
<StrictMode>
<QueryClientProvider client={queryClient}>
<BrowserRouter>
<App />
</BrowserRouter>
</QueryClientProvider>
</StrictMode>
);
2. React Query Client (lib/queryClient.ts)
import { QueryClient } from '@tanstack/react-query';
export const queryClient = new QueryClient({
defaultOptions: {
queries: {
staleTime: 60 * 1000, // 1 minute
retry: 1,
},
},
});
3. API Client (api/client.ts)
import axios from 'axios';
const API_BASE_URL = process.env.NX_API_URL || 'http://localhost:3333';
export const apiClient = axios.create({
baseURL: API_BASE_URL,
headers: { 'Content-Type': 'application/json' },
});
apiClient.interceptors.response.use(
(response) => response,
(error) => {
const message = error.response?.data?.message || error.message || 'An error occurred';
console.error('API Error:', message);
return Promise.reject(error);
}
);
4. App Component (app/app.tsx)
import { Route, Routes } from 'react-router-dom';
import Home from '../pages/Home';
export function App() {
return (
<Routes>
<Route path="/" element={<Home />} />
</Routes>
);
}
export default App;
5. Global Styles, Components, and Hooks
See references/examples.md for complete code examples including:
- Tailwind CSS v4 theme configuration with design tokens
- Navigation components (NavButton, HeaderNav)
- Common components (Button, Card, LoadingSpinner)
- Example API module and React Query hooks
- Page with data fetching pattern
- Form with mutation pattern
Checklist
- Install dependencies:
npm install - Start frontend:
just serve-webapp - Test home page: Open
http://localhost:4200 - Check API connection: Ensure backend is running on
http://localhost:3333
Best Practices
- Use Tailwind CSS: Style with utility classes, no component libraries
- Design tokens in CSS variables: Define colors in
:root, extend with@theme - API layer separation: Keep API functions in
api/, hooks inhooks/ - React Query for server state: Wrap API calls with
useQueryanduseMutation - Keep pages thin: Extract route params, render feature components
- Type everything: Use TypeScript for all props and functions
- Import types from @{project}/types: Share types with backend
- Handle loading/error states: Always show appropriate UI
- Use
classNameprop: Allow style overrides on components - Consistent query keys: Use predictable patterns for cache invalidation
More from workshop-ventures/skills
new-project-scaffolding
Scaffold a new Nx monorepo project with backend, frontend, shared types library, justfile commands, and direnv setup. Use when starting a fresh project or asked to "create a new project", "scaffold a monorepo", or "set up a new workspace".
11backend-metrics
Add OpenTelemetry metrics and observability to the backend. Use when asked to "add metrics", "add observability", "track requests", or "add OpenTelemetry".
10frontend-hooks-creation
Create React Query hooks for API endpoints with proper typing and cache invalidation. Use when asked to "create hooks", "add frontend hooks", "create API hooks", or "add React Query hooks".
9backend-scaffolding
Scaffold a Koa-based backend server with standard structure including config, logging, routes, models, and database setup. Use when asked to "create a backend", "scaffold backend", "set up an API server", or "initialize backend structure".
9backend-ai-tools
Create AI tools for use with Vercel AI SDK agents. Use when asked to "create AI tools", "add agent tools", "create tool for AI", or "add tools to agent".
8backend-ai-agent
Create AI agents using Vercel AI SDK with tool use, tracing, and failover. Use when asked to "create an AI agent", "add AI", "create LLM integration", or "build an assistant".
8