# Cursor Rules for SAP-PLEX-SYNC Project ## Project Overview This is a Rust backend (Axum) and React frontend (Material UI) application for synchronizing SAP Business One with Plesk web servers. ## Code Style Guidelines ### Rust Backend - Use `cargo fmt` for formatting (4-space indentation) - Use `cargo clippy` for linting - Follow the AGENTS.md guidelines for imports, naming, and error handling - Use `anyhow::Result` for error propagation - Return `Result` for API handlers - Use `?` operator for error propagation - Add `///` doc comments for public items ### React Frontend - Use Prettier for formatting (2-space indentation) - Follow the AGENTS.md guidelines for imports, naming, and TypeScript - Use functional components with hooks - Use `useCallback` for event handlers - Use `useMemo` for expensive calculations - Use `useEffect` for side effects - Avoid inline function definitions in JSX ## Development Workflow ### Backend Development ```bash cd backend cargo build # Build the project cargo test # Run tests cargo fmt # Format code cargo clippy # Lint code ``` ### Frontend Development ```bash cd frontend npm install # Install dependencies npm run dev # Start dev server npm run build # Build for production npm test # Run tests npm run lint # Lint code ``` ### Docker Development ```bash docker-compose up -d # Start all services docker-compose logs -f # View logs docker-compose down # Stop all services ``` ## Common Patterns ### Error Handling (Rust) ```rust pub async fn my_handler(State(state): State>) -> impl IntoResponse { let mut conn = match state.pool.get() { Ok(c) => c, Err(_) => return json_error(500, "Database connection error"), }; let result = postgres::GenericClient::query_one(&mut conn, "...", &[]); match result { Ok(row) => Response::json(&json!({"status": "ok"})), Err(e) => { log::error!("Query failed: {}", e); json_error(500, "Database query failed") } } } ``` ### Error Handling (React) ```typescript const handleSave = async () => { try { await apiFetch('/api/config', { method: 'PUT', body: JSON.stringify(data) }); toast.success('Configuration saved'); } catch (error) { logger.error('Failed to save configuration', error); toast.error('Failed to save configuration'); } }; ``` ### Input Validation (React) ```typescript const validateForm = (data: FormData) => { const errors: Record = {}; if (!validators.required(data.username).valid) { errors.username = validators.required(data.username).error; } if (!validators.password(data.password).valid) { errors.password = validators.password(data.password).error; } return errors; }; ``` ## Testing ### Backend Tests - Place tests in `#[cfg(test)] mod tests` blocks - Use `cargo test` to run all tests - Test private functions with `#[cfg(test)]` - Mock external dependencies when needed ### Frontend Tests - Use React Testing Library - Test user interactions, not implementation details - Use `screen.getByRole`, `screen.getByText` - Test both happy paths and error states ## Git Workflow - Use conventional commits: `type(scope): description` - Types: `feat`, `fix`, `docs`, `style`, `refactor`, `test`, `chore` - Branch naming: `feature/`, `bugfix/`, `hotfix/`, `refactor/` ## Important Notes - Always check for unsafe `unwrap()` calls and replace with proper error handling - Use proper logging instead of `console.log` in frontend - Follow TypeScript strict mode settings - Keep functions small and focused - Use meaningful variable and function names - Add comments for complex logic