A comprehensive React/TypeScript frontend application for managing CrowdSec security infrastructure with Shadcn UI.
- Complete API Coverage: All 43 backend API endpoints integrated
- Type-Safe: Full TypeScript support with strict mode
- Modern UI: Shadcn UI components with Tailwind CSS
- Real-time Updates: TanStack Query with auto-refetch
- Responsive Design: Mobile-first, works on all devices
- Error Handling: Toast notifications for user feedback
- Loading States: Proper loading indicators throughout
- Confirmation Dialogs: For all destructive actions
- React 18 - UI library
- TypeScript - Type safety
- Vite - Build tool
- React Router - Client-side routing
- TanStack Query - Data fetching and caching
- Axios - HTTP client
- Shadcn UI - Component library
- Tailwind CSS - Styling
- Lucide React - Icons
- Sonner - Toast notifications
web/
├── public/
│ └── index.html
├── src/
│ ├── components/
│ │ ├── ui/ # Shadcn UI components
│ │ │ ├── button.tsx
│ │ │ ├── card.tsx
│ │ │ ├── dialog.tsx
│ │ │ ├── input.tsx
│ │ │ ├── label.tsx
│ │ │ ├── select.tsx
│ │ │ ├── separator.tsx
│ │ │ ├── switch.tsx
│ │ │ ├── tabs.tsx
│ │ │ ├── table.tsx
│ │ │ ├── badge.tsx
│ │ │ ├── alert-dialog.tsx
│ │ │ └── tooltip.tsx
│ │ ├── Layout.tsx # Main layout wrapper
│ │ ├── Sidebar.tsx # Navigation sidebar
│ │ └── Header.tsx # Top header
│ ├── lib/
│ │ ├── api.ts # API client with all 43 endpoints
│ │ └── utils.ts # Utility functions
│ ├── pages/
│ │ ├── Dashboard.tsx # Overview dashboard
│ │ ├── Health.tsx # Health & diagnostics
│ │ ├── IPManagement.tsx # IP management
│ │ ├── Whitelist.tsx # Whitelist management
│ │ ├── Scenarios.tsx # Scenario management
│ │ ├── Captcha.tsx # Captcha configuration
│ │ ├── Logs.tsx # Logs & monitoring
│ │ ├── Backup.tsx # Backup management
│ │ ├── Update.tsx # Stack updates
│ │ ├── Cron.tsx # Cron job management
│ │ └── Services.tsx # Service management
│ ├── App.tsx # Main app component
│ ├── main.tsx # Entry point
│ └── index.css # Global styles
├── package.json
├── tsconfig.json
├── vite.config.ts
├── tailwind.config.js
└── components.json
# Navigate to web directory
cd web
# Install dependencies
npm install# Start development server (runs on http://localhost:3000)
npm run dev
# Build for production
npm run build
# Preview production build
npm run preview
# Run linter
npm run lintThe application connects to the backend API at http://localhost:8080/api. All 43 endpoints are mapped in src/lib/api.ts:
-
Health & Diagnostics (2 endpoints)
- Check stack health
- Complete diagnostics
-
IP Management (4 endpoints)
- Get public IP
- Check if IP is blocked
- Check IP security
- Unban IP
-
Whitelist Management (7 endpoints)
- View whitelists
- Whitelist current IP
- Whitelist manual IP
- Whitelist CIDR
- Add to CrowdSec whitelist
- Add to Traefik whitelist
- Comprehensive whitelist setup
-
Scenarios (2 endpoints)
- Setup custom scenarios
- List scenarios
-
Captcha (2 endpoints)
- Setup captcha
- Get captcha status
-
Logs (5 endpoints)
- Get CrowdSec logs
- Get Traefik logs
- Analyze Traefik logs
- Get service logs
- Stream logs (WebSocket)
-
Backup (6 endpoints)
- List backups
- Create backup
- Restore backup
- Delete backup
- Cleanup old backups
- Get latest backup
-
Update (3 endpoints)
- Get current tags
- Update with CrowdSec
- Update without CrowdSec
-
Cron (3 endpoints)
- Setup cron job
- List cron jobs
- Delete cron job
-
Services (3 endpoints)
- Verify services
- Graceful shutdown
- Service actions (start/stop/restart)
-
CrowdSec Specific (4 endpoints)
- Get bouncers
- Get decisions
- Get metrics
- Enroll CrowdSec
-
Traefik Specific (2 endpoints)
- Check integration
- Get config
- System status overview
- Container health cards
- Active decisions count
- Bouncers count
- Quick action links
- Stack health display
- Complete diagnostics
- Bouncers list with status
- Metrics visualization
- Traefik integration check
- IP security checker
- Unban IP functionality
- Blocked IPs table
- Public IP display
- Tabbed interface (CrowdSec/Traefik)
- View current whitelists
- Add IP/CIDR forms
- Comprehensive setup wizard
- List installed scenarios
- Custom scenario setup
- Scenario details
- Provider selection
- Site key/secret key input
- Status indicator
- Service selector dropdown
- Real-time log viewer
- WebSocket streaming
- Advanced log analysis
- Auto-refresh toggle
- Backups table with details
- Create backup button
- Restore with confirmation
- Delete with confirmation
- Cleanup old backups
- Current image tags display
- New tags input form
- Update with/without CrowdSec options
- Update progress indicator
- Cron jobs table
- Add new job form
- Schedule picker
- Delete with confirmation
- Service status cards
- Start/stop/restart buttons
- Graceful shutdown option
- Real-time status updates
- Create the page component in
src/pages/ - Add route in
src/App.tsx - Add navigation item in
src/components/Sidebar.tsx - Use TanStack Query for data fetching:
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
import { yourAPI } from '@/lib/api'
import { toast } from 'sonner'
export default function YourPage() {
const queryClient = useQueryClient()
// Fetch data
const { data, isLoading, error } = useQuery({
queryKey: ['yourDataKey'],
queryFn: () => yourAPI.getData(),
refetchInterval: 30000, // Optional: auto-refetch
})
// Mutation
const mutation = useMutation({
mutationFn: yourAPI.updateData,
onSuccess: () => {
toast.success('Success!')
queryClient.invalidateQueries({ queryKey: ['yourDataKey'] })
},
onError: (error) => {
toast.error(`Error: ${error.message}`)
},
})
// ... component implementation
}All Shadcn UI components are available in src/components/ui/. Import and use them:
import { Button } from '@/components/ui/button'
import { Card, CardHeader, CardTitle, CardContent } from '@/components/ui/card'
import { Input } from '@/components/ui/input'
import { Label } from '@/components/ui/label'
function MyComponent() {
return (
<Card>
<CardHeader>
<CardTitle>My Card</CardTitle>
</CardHeader>
<CardContent>
<div className="space-y-4">
<div>
<Label htmlFor="name">Name</Label>
<Input id="name" placeholder="Enter name" />
</div>
<Button>Submit</Button>
</div>
</CardContent>
</Card>
)
}Use Tailwind utility classes for styling:
<div className="space-y-6">
<h1 className="text-3xl font-bold">Title</h1>
<p className="text-muted-foreground">Description</p>
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4">
{/* Grid items */}
</div>
</div>The Vite dev server proxies /api requests to http://localhost:8080. Configure in vite.config.ts:
server: {
port: 3000,
proxy: {
'/api': {
target: 'http://localhost:8080',
changeOrigin: true,
},
},
}Strict mode enabled with path aliases:
{
"compilerOptions": {
"strict": true,
"paths": {
"@/*": ["./src/*"]
}
}
}- Port already in use: Change port in
vite.config.ts - API not connecting: Ensure backend is running on port 8080
- Type errors: Run
npm installto ensure all types are installed - Styling issues: Ensure Tailwind classes are recognized
Enable React Query DevTools:
import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
// In your App component
<QueryClientProvider client={queryClient}>
<App />
<ReactQueryDevtools initialIsOpen={false} />
</QueryClientProvider># Build for production
npm run build
# Output in dist/ directory
# Serve with any static file serverMIT
For issues or questions, refer to the main project documentation or the IMPLEMENTATION_GUIDE.md for detailed implementation examples.