# AGENTS.md This file provides guidance to AI coding agents when working with code in this repository. ## Essential Documentation **Primary Reference**: [My Jetpack README.md](./README.md) - Complete architecture, development commands, and project structure **Additional Resources**: - [Data Layer Documentation](./_inc/data/README.md) - API hooks and data management - [Automated Testing Overview](../../../docs/automated-testing.md) - Testing patterns and strategies - [Coding Standards & Guidelines](../../../docs/coding-guidelines.md) - Development best practices - [Jetpack HTTP API Documentation](../../../docs/rest-api.md) - REST API patterns - [Jetpack CLI Documentation](../../../tools/cli/README.md) - CLI commands and workflows ## Project Overview My Jetpack is a centralized WordPress admin page providing a unified interface for managing Jetpack products and services. Key architectural components: - **PHP Backend**: Product management system, REST API endpoints (`jetpack/v4/my-jetpack` namespace) - **React Frontend**: TypeScript application with React Router and TanStack React Query for data management - **Product System**: Standardized `Product` class interface with status constants for lifecycle management ## Code Patterns & Examples ### PHP Patterns #### Product Class Structure ```php is_plugin_installed() ) { return self::STATUS_PLUGIN_ABSENT; } if ( ! $this->is_active() ) { return self::STATUS_INACTIVE; } return self::STATUS_ACTIVE; } // Optional: provide management URL public static function get_manage_url() { return admin_url( 'admin.php?page=my-product' ); } // Override as needed: pricing, features, etc. } ``` #### REST API Endpoint Pattern For comprehensive REST API documentation and patterns, see [Jetpack HTTP API Documentation](../../../docs/rest-api.md). My Jetpack endpoints follow the standard pattern: - **Namespace**: `jetpack/v4/my-jetpack` - **Base**: Extend `WP_REST_Controller` - **Registration**: Via `Initializer::register_rest_endpoints()` #### Product Status Constants ```php // Status constants are defined in class-products.php // Use Products::STATUS_* constants instead of magic strings // Common patterns: active, inactive, needs_plan, plugin_absent, etc. // Check class-products.php for current complete list ``` ### React Patterns #### Component Structure ```jsx import { useState, useEffect } from 'react'; import { __ } from '@wordpress/i18n'; import { useConnection } from '@automattic/jetpack-connection'; import styles from './style.module.scss'; const MyComponent = ({ productSlug, onAction }) => { const [isLoading, setIsLoading] = useState(false); const { isRegistered, isUserConnected } = useConnection(); const handleAction = async () => { setIsLoading(true); try { await onAction(); } finally { setIsLoading(false); } }; return (
{product.description}