forked from BLC/AyposWeb
4.7 KiB
4.7 KiB
Copilot Instructions for AyposWeb
Project Overview
AyposWeb is a React-based monitoring system for virtual machine infrastructure with real-time data visualization. It provides VM migration advice, environmental monitoring, stress testing, and preventive maintenance features through a Material-UI interface.
Tech Stack & Architecture
- Frontend: React 18 + TypeScript + Vite
- UI Framework: Material-UI (MUI) v5 with custom B'GREEN branding
- Charts: Multiple libraries (Plotly.js, Recharts, Chart.js, MUI X-Charts)
- Routing: React Router v6 with declarative routes in
App.tsx - State: React hooks with custom polling patterns (no external state management)
- Build: Vite with standard TypeScript config
- Deployment: Docker + nginx or Vercel with API proxy
Core Architecture Patterns
Service Layer Pattern
Services use singleton pattern with axios HTTP client:
// All services follow this pattern in src/services/
class ServiceName {
private static instance: ServiceName;
public static getInstance(): ServiceName { /* singleton */ }
}
Smart Polling Hook Pattern
Custom hooks in src/components/Migration/hooks.ts implement adaptive polling:
- Starts with fast intervals (5s) when data changes
- Gradually increases to slower intervals (30s) when stable
- Always use
useSmartPollingfor real-time data fetching
Environment Configuration
// src/config/env.ts handles dev/prod API routing
const getApiUrl = (): string => {
if (import.meta.env.PROD) return '/api'; // Vercel proxy
return import.meta.env.VITE_API_URL || 'fallback-url';
};
Component Organization
Layout Structure
MainLayoutprovides responsive sidebar with mobile menu toggleSidebaruses custom styled MUI components with B'GREEN theming- Pages in
src/pages/are route components that compose feature components
Material-UI Customization
// src/theme.ts defines B'GREEN brand colors
primary: { main: '#028a4a' } // B'GREEN green
- Use
styled()for component-specific styling - Custom
StyledListItemButtonpattern for navigation - Responsive breakpoints with
useMediaQuery(theme.breakpoints.down('md'))
Chart Component Patterns
Multiple charting libraries used for different purposes:
- Plotly.js: Complex scientific visualizations in migration analysis
- Recharts: Simple bar/line charts for resource distribution
- MUI X-Charts: Native MUI integration for basic charts
- Chart.js: Time-series data with date-fns adapter
Data Flow Patterns
API Integration
// Services handle all external API calls
const response = await axios.post(`${BASE_URL}/endpoint`, data, {
headers: { 'Content-Type': 'application/json' }
});
Type Safety
- Strict TypeScript with comprehensive interfaces in
src/types/ - Migration-specific types in
src/components/Migration/types.ts - Monitoring types shared across services in
src/types/monitoring.ts
Error Handling
- Services log requests for debugging:
console.log('Starting operation with config:', config) - Use try/catch with proper error propagation to UI components
Development Workflows
Build Commands
npm run dev # Vite dev server on :5173
npm run build # TypeScript compilation + Vite build
npm run preview # Preview production build
Environment Setup
- Development: Uses
VITE_API_URLenvironment variable - Production: API calls routed through
/apiproxy (seevercel.json) - No
.env.example- check README for environment variables
Key Files to Understand
src/App.tsx: Route definitions and global providerssrc/components/Layout/MainLayout.tsx: Responsive layout logicsrc/services/monitoringService.ts: Main API service patternssrc/components/Migration/hooks.ts: Custom polling and data fetchingsrc/theme.ts: B'GREEN brand implementation
Project-Specific Conventions
Import Organization
- React/third-party imports
- MUI component imports
- Local component imports
- Service/utility imports
- Asset imports (images/icons)
Component Naming
- Page components: PascalCase in
src/pages/ - Feature components: PascalCase in feature folders under
src/components/ - Service files: camelCase with "Service" suffix
Styling Approach
- Use MUI's
styled()over CSS-in-JS or external CSS - Custom styled components follow
Styled{ComponentName}naming - Responsive design with MUI breakpoint system
- B'GREEN brand colors defined in theme, not hardcoded
When adding new features, follow the established service layer pattern, use TypeScript interfaces for all data structures, and implement smart polling for real-time data when appropriate.