A modern, responsive dashboard for monitoring and managing API gateway traffic, built with React, TypeScript, and TanStack Router.
-
Real-time WebSocket Integration: Live streaming of monitoring metrics
- Traffic monitoring (RPS/TPS, response time distribution)
- Error tracking and availability monitoring
- Resource metrics (CPU, memory, connection pools)
- Security monitoring (rate limiting, authentication failures)
- Business metrics and SLA compliance tracking
- Geographic distribution and client analysis
-
Advanced Chart Visualizations:
- Line charts for time-series data
- Bar charts for API usage rankings
- Pie charts for status code distribution
- Heatmaps for geographic traffic
- Gauge charts for resource utilization
- Progress bars for real-time metrics
-
Network Path Visualization: Interactive network topology view using React Flow
- Real-time traffic flow animation
- Node status monitoring with health indicators
- Auto-layout functionality for optimal graph arrangement
- Custom styled nodes for different service types
-
Distributed Tracing: Advanced trace analysis with multiple view modes
- Gantt Chart View: Timeline visualization of distributed traces
- Waterfall View: Sequential execution flow with wait time indicators
- Flame Graph View: Hierarchical performance visualization
- Zoom controls and export functionality
- Real-time span details on hover/click
- TanStack Query Integration: Optimized data fetching for traces
- Automatic caching with 5-minute retention
- Background refetching every minute
- Prefetching on hover for instant loading
- Smart retry logic with exponential backoff
- Loading, error, and success state management
- Enhanced Auth Flow: Robust authentication handling
- Automatic token refresh before expiration
- Persistent sessions with localStorage
- Mock authentication for development (admin/admin123)
- Graceful error handling without forced redirects
- Comprehensive Documentation: Two documentation formats
- Swagger UI: Interactive API testing at
/api-docs - Markdown Docs: Detailed documentation at
/docs - OpenAPI 3.0 specification
- Request/response examples
- Authentication guide
- Swagger UI: Interactive API testing at
- Dynamic Trace Generation: Realistic distributed trace simulation
- Random service topology generation (5-15 spans per trace)
- 10 different service types with appropriate operations
- Weighted status distribution (85% success, 10% warning, 5% error)
- Service-specific metadata (database queries, cache hits, payment info)
- Hierarchical parent-child relationships
- Optimized React Flow rendering with memoization
- Reduced unnecessary re-renders in trace timeline
- Efficient D3.js chart updates
- TypeScript type safety improvements
- Removed unused imports and variables
- Better error boundary implementation
- Hot module replacement (HMR) for all components
- Better error messages and debugging info
- Development mode query state indicators
- Real-time Monitoring: Live system metrics (CPU, memory, network)
- Traffic Analytics: Request volume, status distribution, and performance metrics
- Interactive Charts: Built with D3.js for rich data visualization
- Mock Server: Full-featured development server with simulated data
- Static Site Generation: Pre-rendered pages for optimal performance
- Responsive Design: Tailwind CSS with dark mode support
- Frontend: React 19, TypeScript, TanStack Router, TanStack Query
- Styling: Tailwind CSS v4, shadcn/ui components
- Charts: D3.js with custom React components
- Visualizations: React Flow for network topology
- Build Tool: Vite
- Testing: Vitest, React Testing Library, @testing-library/jest-dom
- Mock Server: Express.js with SQLite
- API Documentation: Swagger UI + OpenAPI 3.0
- Code Quality: Biome for linting and formatting
├── src/
│ ├── components/ # Reusable UI components
│ │ ├── trace/ # Distributed tracing components
│ │ ├── charts/ # D3.js chart components
│ │ └── ui/ # shadcn/ui components
│ ├── hooks/ # Custom React hooks
│ │ ├── useTraces.ts # TanStack Query hooks for traces
│ │ └── useAuth.ts # Authentication hooks
│ ├── lib/ # Utilities and configurations
│ │ ├── api-client.ts # API client with auth
│ │ └── auth.ts # Authentication service
│ ├── routes/ # TanStack Router pages
│ └── app/ # Application-specific components
├── server/ # Mock API server
│ ├── src/
│ │ ├── routes/ # API endpoints
│ │ ├── services/ # Business logic
│ │ ├── swagger.js # API documentation config
│ │ └── db/ # Database operations
│ ├── API_DOCUMENTATION.md # Detailed API docs
│ └── package.json
├── scripts/ # Build and utility scripts
└── dist-ssg/ # Static build output
- Node.js 18+
- pnpm (recommended) or npm
- Clone the repository:
git clone <repository-url>
cd tanstack-start-test- Install dependencies:
pnpm install- Install mock server dependencies:
pnpm run server:install- Set up environment variables:
cp .env.example .envEdit .env file:
VITE_API_URL=http://localhost:4001/apipnpm run dev:allThis starts:
- Frontend dev server on http://localhost:3000
- Mock API server on http://localhost:4001
- Swagger UI on http://localhost:4001/api-docs
- Markdown docs on http://localhost:4001/docs
Frontend only:
pnpm run devMock server only:
pnpm run dev:server- Demo User: username:
demo, password:demo123 - Admin User: username:
admin, password:admin123
The mock server provides comprehensive API documentation:
- URL: http://localhost:4001/api-docs
- Test endpoints directly from the browser
- OpenAPI 3.0 specification
- Try it out functionality
- URL: http://localhost:4001/docs
- Detailed endpoint descriptions
- Request/response examples
- Authentication guide
Build pre-rendered static pages:
pnpm run buildThis generates:
- Optimized static HTML for each route
- Code-split JavaScript bundles
- Minified CSS
- Output in
dist-ssg/directory
Build and run the static site with mock server:
pnpm run build:serveGET /health- Health checkGET /api/metrics/current- Current system metricsGET /api/metrics/history- Historical metrics dataGET /api/dashboard/*- Dashboard statisticsGET /api-docs- Swagger UI documentationGET /docs- Markdown documentation
GET /api/traces- List distributed tracesGET /api/traces/:id- Get trace detailsGET /api/todos- Todo managementGET /api/posts- Blog postsGET /api/users- User management
POST /api/auth/login- User loginPOST /api/auth/logout- User logoutPOST /api/auth/refresh- Refresh access token
- Real-time trace monitoring
- Multiple visualization modes
- Service dependency mapping
- Error tracking and analysis
- Interactive network topology
- Real-time traffic flow
- Node health monitoring
- Connection metrics
- CPU, Memory, Disk usage
- Network I/O monitoring
- Request rate tracking
- Error rate analysis
The project uses Vitest for unit testing React components and utility functions.
Run all tests once:
pnpm testRun tests in watch mode (auto-reruns on file changes):
pnpm test:watchGenerate coverage report:
pnpm test:coverageTests are located alongside the source files:
src/
├── components/
│ ├── ui/
│ │ ├── button.tsx
│ │ ├── button.test.tsx # Button component tests
│ │ ├── card.tsx
│ │ └── card.test.tsx # Card component tests
│ ├── Header.tsx
│ └── Header.test.tsx # Header component tests
└── lib/
├── utils.ts
└── utils.test.ts # Utility function tests
Example test for a React component:
import { describe, it, expect, vi } from 'vitest'
import { render, screen, fireEvent } from '@testing-library/react'
import { Button } from './button'
describe('Button Component', () => {
it('renders button with text', () => {
render(<Button>Click me</Button>)
expect(screen.getByRole('button', { name: 'Click me' })).toBeInTheDocument()
})
it('handles click events', () => {
const handleClick = vi.fn()
render(<Button onClick={handleClick}>Click me</Button>)
fireEvent.click(screen.getByRole('button'))
expect(handleClick).toHaveBeenCalledTimes(1)
})
})Vitest is configured in vitest.config.ts:
- Environment: jsdom (for DOM testing)
- Global test APIs enabled
- Coverage provider: V8
- Testing utilities: @testing-library/react, @testing-library/jest-dom
After running pnpm test:coverage, view the HTML coverage report:
# Open coverage report in browser
open coverage/index.htmlTest SSG build:
pnpm run test:ssgFormat code:
pnpm run formatLint code:
pnpm run lintRun all checks:
pnpm run check| Script | Description |
|---|---|
pnpm run dev |
Start frontend development server |
pnpm run dev:server |
Start mock API server |
pnpm run dev:all |
Start both frontend and mock server |
pnpm run build |
Build static site (SSG) |
pnpm run serve |
Serve built static site |
pnpm run build:serve |
Build and serve with mock server |
pnpm test |
Run unit tests with Vitest |
pnpm run test:watch |
Run tests in watch mode |
pnpm run test:coverage |
Run tests with coverage report |
pnpm run test:ssg |
Test SSG build |
pnpm run format |
Format code with Biome |
pnpm run lint |
Lint code with Biome |
pnpm run check |
Run all Biome checks |
pnpm run server:install |
Install mock server dependencies |
| Variable | Description | Default |
|---|---|---|
VITE_API_URL |
API server URL | http://localhost:4001/api |
PORT |
Mock server port | 4001 |
- Chrome/Edge 90+
- Firefox 88+
- Safari 14+
- Lighthouse Score: 95+ (Performance)
- First Contentful Paint: < 1.2s
- Time to Interactive: < 2.5s
- Bundle size: ~750KB (before gzip)
The dist-ssg folder can be deployed to any static hosting service:
# Build command
pnpm run build
# Publish directory
dist-ssg{
"buildCommand": "pnpm run build",
"outputDirectory": "dist-ssg"
}# Deploy using gh-pages
npx gh-pages -d dist-ssg- Clear localStorage:
localStorage.clear() - Use demo credentials: username
demo, passworddemo123 - Check token expiration in browser DevTools
- Verify mock server is running on port 4001
- Ensure mock server is running on port 4001
- Check
VITE_API_URLenvironment variable - Verify CORS settings in
server/src/index.js
- Ensure authentication token is valid
- Check browser console for errors
- Verify mock server is generating data
- Try refreshing the page
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
MIT
For issues and questions, please use the GitHub issues page.