Enthält: - rdp_client.py: RDP Client mit GUI und Monitor-Auswahl - rdp.sh: Bash-basierter RDP Client - teamleader_test/: Network Scanner Fullstack-App - teamleader_test2/: Network Mapper CLI Subdirectories mit eigenem Repo wurden ausgeschlossen. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
6.4 KiB
6.4 KiB
Network Scanner Frontend - Development Guide
Architecture
Component Structure
App (Router)
└── Layout (Navigation)
├── Dashboard
│ ├── ScanForm
│ └── Statistics
├── NetworkPage
│ ├── NetworkMap (ReactFlow)
│ │ └── HostNode (Custom)
│ └── HostDetails (Modal)
├── HostsPage
│ ├── HostTable
│ └── HostDetails (Modal)
└── ScansPage
└── ScansList
State Management
- Local State: React hooks (useState, useEffect)
- Custom Hooks: Data fetching and WebSocket management
- No Global State: Each page manages its own data
Data Flow
- REST API → Custom hooks → Components → UI
- WebSocket → Custom hooks → State updates → UI refresh
Custom Hooks
useScans
Manages scan data:
- Fetches list of scans
- Polls for updates
- Provides refetch function
const { scans, loading, error, refetch } = useScans();
useHosts
Manages host data:
- Fetches list of hosts
- Gets individual host details
- Provides refetch function
const { hosts, loading, error, refetch } = useHosts();
const { host, loading, error } = useHost(hostId);
useTopology
Manages network topology:
- Fetches topology graph data
- Provides refetch function
const { topology, loading, error, refetch } = useTopology();
useWebSocket
Manages WebSocket connection:
- Auto-reconnect on disconnect
- Message handling
- Connection status
const { isConnected, reconnect } = useWebSocket({
onScanProgress: (data) => { ... },
onScanComplete: (data) => { ... },
onHostDiscovered: (data) => { ... },
});
API Integration
REST Endpoints
All endpoints are proxied through Vite dev server:
// Development: http://localhost:3000/api/* → http://localhost:8000/api/*
// Production: Configure your web server proxy
scanApi.startScan(request)
scanApi.getScanStatus(id)
scanApi.listScans()
scanApi.cancelScan(id)
hostApi.listHosts(params)
hostApi.getHost(id)
hostApi.getHostByIp(ip)
hostApi.getHostServices(id)
hostApi.getHostStatistics()
hostApi.deleteHost(id)
topologyApi.getTopology()
topologyApi.getNeighbors(id)
WebSocket Messages
type WSMessage = {
type: 'scan_progress' | 'scan_complete' | 'host_discovered' | 'error';
data: any;
};
Styling
TailwindCSS
Custom theme configuration in tailwind.config.js:
colors: {
primary: { ... }, // Blue shades
slate: { ... }, // Dark theme
}
Color Scheme
- Background:
slate-900 - Cards:
slate-800 - Borders:
slate-700 - Text primary:
slate-100 - Text secondary:
slate-400 - Accent:
primary-500(blue)
Responsive Design
Mobile-first approach with breakpoints:
sm: 640pxmd: 768pxlg: 1024pxxl: 1280px
Network Map (React Flow)
Custom Node Component
HostNode.tsx renders each host as a custom node:
<HostNode
data={{
ip: string,
hostname: string | null,
type: 'gateway' | 'server' | 'workstation' | 'device',
status: 'up' | 'down',
service_count: number,
color: string,
onClick: () => void,
}}
/>
Layout Algorithm
Currently using circular layout. Can be replaced with:
- Force-directed (d3-force)
- Hierarchical (dagre)
- Manual positioning
Node Types
- Gateway: Blue, Globe icon
- Server: Green, Server icon
- Workstation: Purple, Monitor icon
- Device: Amber, Smartphone icon
- Unknown: Gray, HelpCircle icon
Adding New Features
New API Endpoint
- Add type to
src/types/api.ts - Add service method to
src/services/api.ts - Create custom hook in
src/hooks/ - Use in component
New Page
- Create component in
src/pages/ - Add route to
App.tsx - Add navigation item to
Layout.tsx
New Component
- Create in
src/components/ - Follow existing patterns
- Use TypeScript for props
- Add proper error handling
Performance Optimization
Current Optimizations
- React.memo for node components
- Debounced search
- Lazy loading (can be added)
- Code splitting (can be added)
Potential Improvements
- Virtual scrolling for large host lists
- Lazy loading for routes
- Service worker for offline support
- Caching with React Query or SWR
Testing
Currently no tests included. Recommended setup:
npm install -D vitest @testing-library/react @testing-library/jest-dom
Example test structure:
tests/
├── components/
├── hooks/
├── pages/
└── utils/
Deployment
Build for Production
npm run build
Static Hosting
Upload dist/ to:
- Netlify
- Vercel
- GitHub Pages
- AWS S3 + CloudFront
Web Server Configuration
Nginx example:
server {
listen 80;
server_name yourdomain.com;
root /path/to/dist;
location / {
try_files $uri $uri/ /index.html;
}
location /api {
proxy_pass http://localhost:8000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
Environment Variables
Create .env.production for production:
VITE_API_URL=https://api.yourdomain.com
VITE_WS_URL=wss://api.yourdomain.com
Troubleshooting
WebSocket Connection Issues
- Check CORS settings on backend
- Verify WebSocket URL
- Check browser console for errors
API Connection Issues
- Verify backend is running
- Check proxy configuration in
vite.config.ts - Check network tab in browser dev tools
Build Errors
- Clear
node_modulesand reinstall - Check Node.js version (18+)
- Update dependencies
Code Quality
ESLint
npm run lint
TypeScript
npx tsc --noEmit
Format (if Prettier is added)
npx prettier --write src/
Browser DevTools
React DevTools
Install extension for component inspection.
Network Tab
Monitor API calls and WebSocket messages.
Console
Check for errors and warnings.
Contributing
- Follow existing code style
- Add TypeScript types for all new code
- Test in multiple browsers
- Update documentation