# Main Plugin Backend Logic

Directory: `includes/`

This directory serves as the core of the AI Services plugin's backend functionality. It contains the primary PHP classes that orchestrate the plugin's operations, including class autoloading, main plugin initialization, service container setup, and the public-facing API function. Additionally, it houses several crucial subdirectories, each dedicated to a specific aspect of the plugin's architecture, such as integrations with different AI providers (Anthropic, Google, OpenAI), chatbot functionality, installation procedures, and the extensive AI services infrastructure.

## Purpose

The primary purpose of the code within this directory is to:

- Initialize and manage the overall plugin lifecycle.
- Provide a centralized location for core plugin files and sub-modules.
- Define the main entry points for plugin functionality, including WordPress hooks and API access.
- Structure the backend codebase into logical, manageable subdirectories, each with a specific responsibility.

## Key Files at the Root Level

The PHP files located directly within the `includes/` directory are fundamental to the plugin's operation:

-   **`Plugin_Autoloader.php`**: Implements a custom class autoloader for the plugin. It uses a class map (generated by Composer) to efficiently load plugin classes as needed, ensuring that only necessary files are included.
-   **`Plugin_Main.php`**: This is the main orchestrator class for the plugin. It initializes the core AI services infrastructure (via `Services_Loader` from `includes/Services/`), sets up a dependency injection container for general plugin services (using `Plugin_Service_Container_Builder.php`), registers default AI services (Anthropic, Google, OpenAI), and hooks into WordPress for various actions like installation, deactivation cleanup, and option registration.
-   **`Plugin_Service_Container_Builder.php`**: Responsible for building and configuring the primary dependency injection container for the plugin (distinct from the one in `includes/Services/`). It defines how general services like `Plugin_Env`, `Current_User`, `Plugin_Installer` (from `includes/Installation/`), and `Chatbot_Loader` (from `includes/Chatbot/`) are instantiated and managed.
-   **`api.php`**: Defines the global `ai_services()` function. This convenience function provides easy, global access to the main `Services_API` instance (from `includes/Services/Services_API.php`), which is the primary way developers interact with the AI services provided by this plugin.

## Subdirectories

The `includes/` directory organizes its extensive functionality into the following subdirectories:

-   **`Anthropic/`**: Contains the integration logic for Anthropic AI services, including the API client, service definition, and text generation model. For more details, see `includes/Anthropic/README.md`.
-   **`Chatbot/`**: Houses the code for the AI-powered chatbot feature, including its loader, AI configuration, and WordPress integration. For more details, see `includes/Chatbot/README.md`.
-   **`Google/`**: Provides the integration for Google's Generative AI services (Gemini, Imagen), including the API client and models for text and image generation. For more details, see `includes/Google/README.md`.
-   **`Installation/`**: Manages the plugin's installation, upgrade, and uninstallation processes. For more details, see `includes/Installation/README.md`.
-   **`OpenAI/`**: Contains the integration logic for OpenAI services (GPT, DALL-E), including the service definition and models for text and image generation. For more details, see `includes/OpenAI/README.md`.
-   **`Services/`**: This is the largest and most critical subdirectory, containing the core infrastructure for registering, managing, and accessing all AI services. It includes the main `Services_API`, base classes, contracts, admin interfaces, REST API endpoints, and much more. For a comprehensive overview, see `includes/Services/README.md`.

These components collectively provide a robust and extensible backend for the AI Services plugin.
