Plugin System

April 15, 2025

Deprecated Feature

@c15t/backend v1 did not deliver the flexibility we wanted and fell short of our standards. It is now deprecated as we work on a full rewrite, with v2 entering canary soon. This does not affect consent.io deployments, which remain stable.

The c15t Backend plugin system provides a powerful way to extend and customize the functionality of your consent management system. This guide covers everything you need to know about plugins, from basic usage to advanced features.

Overview

Plugins are modular components that can:

  • Extend the context with additional data
  • Modify requests and responses
  • Add new routes and endpoints
  • Provide custom middleware
  • Hook into the request lifecycle

Plugin Types

Core Plugins

Core plugins are essential system components that provide fundamental functionality:

Feature Plugins

Feature plugins add specific functionality to your system:

Middleware Plugins

Middleware plugins process requests and responses:

Plugin Lifecycle

Initialization

Plugins are initialized when the c15t instance is created:

Request Lifecycle

Plugins can hook into various stages of request processing:

Context Extensions

Plugins can extend the context with additional data:

Custom Routes

Plugins can add custom routes to your API:

Error Handling

Plugins can handle errors at different levels:

Plugin Dependencies

Plugins can declare dependencies on other plugins:

Best Practices

  1. Plugin Organization

  2. Error Handling

  3. Performance Optimization

Testing Plugins

Unit Testing

Integration Testing

Common Issues

  1. Plugin Order

    • Plugins are executed in the order they are provided
    • Dependencies should be listed first
    • Core plugins should be initialized before feature plugins
  2. Context Access

    • Always check for context existence
    • Use optional chaining for nested properties
    • Provide default values when needed
  3. Error Propagation

    • Handle errors at the appropriate level
    • Log errors for debugging
    • Return appropriate error responses