How tonioseiler/craft-text-to-speech works
Main Components
• Craft CMS Core: Acts as the host environment where the plugin integrates.
• Plugin Entry/Registration: Although not explicitly listed as a separate file, the existence of the plugin files indicates that there is an entry point (via composer.json and the plugin manifests) that registers the plugin with Craft CMS.
• Controllers (src/controllers/TextToSpeechController.php): Handle incoming HTTP requests from the CMS control panel (for example, actions triggered on the entry edit page or in utilities).
• Behaviors (src/behaviors/TextToSpeechBehavior.php): Extend or modify the behavior of certain Craft elements to integrate text-to-speech functionality.
• Services (src/services/TextToSpeechService.php): Encapsulate core business logic for converting text to speech, interfacing with Google’s API, and managing audio generation.
• Jobs (src/jobs/GenerateTTSJob.php): Represent background processes that manage the asynchronous conversion of text to audio.
• Elements/Actions (src/elements/actions/GenerateAudio.php and DeleteAudio.php): Represent discrete actions available in the CMS (e.g., generating or deleting audio files).
• Models/Records (src/models/Settings.php and src/records/ProcessLogRecord.php): Store plugin settings (including API keys and voice configuration) and records of processing events.
• Migrations (src/migrations/Install.php and related migration scripts): Setup database structures like log tables that are used by the plugin.
• Templates (src/templates/*): Twig templates that provide the UI elements (like settings panels and utilities) for configuring plugin behavior within the Craft CMS control panel.
• Utilities (src/utilities/TextToSpeechUtility.php): Provide helper functions and utility operations across the plugin.
Out Relationships and Interactions
• That the Plugin Registration/Bootstrap connects Craft CMS to all the plugin’s components.
• The Service should then be depicted as interacting with Google Text-to-Speech API (implied by the README’s mention of using Google’s credentials and API) and returning the generated audio.
• A branch where Jobs (GenerateTTSJob) are dispatched for asynchronous processing of TTS requests.
• The Actions within the Elements (such as GenerateAudio and DeleteAudio) are invoked within the CMS and use the Service layer, reinforcing the separation of UI interactions from business logic.
• Link the Models/Settings and Records/ProcessLogRecord to the Database (set up via Migrations), showing how the plugin configuration and logs are persisted.
• Templates and Utilities as support layers that render the admin UI in Craft CMS, with the Templates presenting forms/settings and the Utility layer offering additional helper functions for the plugin.
Architectural Patterns
• Separation of Concerns: Different responsibilities are isolated in controllers, services, jobs, and templates.
• MVC Influences: While Craft CMS has its own architecture, notice how the Controllers, Models, and Templates work together to present and process data.
• Asynchronous Processing: Use of Jobs (GenerateTTSJob) supports offloading time-intensive TTS generation to background queues.
• Extensibility: Use of Elements, Behaviors, and Utility classes makes the system modular and enables easier extension or maintenance in future versions.
Technologies, Frameworks, and Libraries
• PHP 8.2 and Craft CMS 4.40.0+ are mandated by the project.
• Google Text-to-Speech API: The plugin relies on this external service for generating audio.
• Twig: Used for templating (as indicated by the Twig files in the templates directory).
• Composer: Manages dependencies and installation of the plugin.
• Additional tools (e.g., PHPStan, ECS) are referenced by configuration files (phpstan.neon, ecs.php), which may be used to maintain code quality and standards.