How amuzcorp/authapi works
Main Components
• Plugin Bootstrap & Registration:
• plugin.php – This is the entry point for the plugin that integrates with XpressEngine3.
• composer.json – Manages dependencies.
• Service Layer:
• The primary service (AuthApiService in src/AuthApiService.php) that is registered and obtained via app('amuz.authapi').
• ApiMigration.php (likely used for any DB migrations related to API keys).
• Command Line Interface (CLI):
• The src/Commands directory houses several artisan commands (ActivateApiKey, DeactivateApiKey, DeleteApiKey, GenerateApiKey, ListApiKeys) which provide direct management of API keys.
• Controllers & Middleware:
• src/Controller.php – Handles incoming requests.
• src/Middleware/AuthorizeApiKey.php – Ensures that API key authorization is enforced.
• Data Models:
• src/Models/ApiKey.php, ApiKeyAccessEvent.php, and ApiKeyAdminEvent.php – Represent the data and events tied to API keys.
• Presentation Layer:
• The views (Blade templates in views/ folder) provide the UI components for creating or listing API keys.
• Assets:
• Contains style.css for frontend styling.
Relationships and Interactions
• The Plugin Bootstrap (plugin.php) initializes the AuthAPI plugin and registers the AuthApiService with the application container.
• The AuthApiService is the core that other parts (controllers, commands) use to create, delete, or toggle API keys. It encapsulates business logic.
• CLI Commands interact with the AuthApiService directly to perform actions (activation, deletion, listing, etc.) based on the artisan command calls.
• The Controller likely acts as a bridge between HTTP requests (coming from users or external API calls) and the underlying service.
• Middleware (AuthorizeApiKey) intercepts requests to ensure authorized API access before reaching controllers.
• Models represent and persist the state of API keys and their access events.
• Views provide a web interface for administrators and end-users to interact with the API key management functions.
Architectural Patterns and Design Principles
• Separation of Concerns: The project separates concerns by isolating API key management, business logic, request handling, and presentation.
• Service-oriented Design: The core functionality is implemented in a unified service that is leveraged by both HTTP controllers and CLI commands.
• MVC-Like structure: Although it is a plugin, it still aligns with the MVC approach – models (under src/Models), controllers (src/Controller.php), and view templates.
• Middleware usage: Cleanly separates authorization logic from request processing.
• Extensibility: The README describes hooks (via XeRegister) to allow third-party plugins to register REST services and verify permissions.
Relevant Technologies, Frameworks, and Libraries
• PHP as the main language.
• Blade templating engine for views.
• Artisan CLI (typical with Laravel or similar platforms) suggests conventions inspired by Laravel.
• Eloquent ORM for model operations (as seen from the usage in README).
• XpressEngine3 integration as the host platform for the plugin.