Bitcart Plugins Development

Creating a New Plugin

Bitcart plugins are modular components that can extend the functionality of your Bitcart instance. A plugin can consist of one or more of the following components:

  • Backend: Server-side logic, database models, and API endpoints

  • Admin: Extensions to the admin panel UI

  • Store: Customizations for the store frontend

  • Docker: Docker compose deploy customizations

To create a new plugin, use the Bitcart CLI:

bitcart-cli plugin init .

This will guide you through creating a new plugin by asking for:

  • Plugin name

  • Author

  • Description

  • Component types to include

To install plugin to develop alongside bitcart, you can use bitcart-cli plugin install .

It is recommended to pass --dev flag to install plugin in development mode. It uses symlinks to link the plugin to the bitcart source code, so when you make changes to the plugin, they are reflected immediately.

It asks for paths where you cloned bitcart, bitcart-admin and other repositories. You can pass --save flag to save paths to config, so that it is never asked again.

After you are done developing and want to remove it from codebase:

Backend Plugin Development

Plugin Structure

A backend plugin must have a plugin.py file which as a Plugin class that implements the BasePlugin class from api.plugins. The basic structure is:

Database Models

To add custom database tables:

  1. Create a models.py file in your plugin directory

  2. Define SQLAlchemy models

  3. Manage migrations using alembic:

Basically same commands as alembic, but you provide your plugin name.

This will create a new migration in the versions/ directory. Migrations are automatically applied when the plugin is loaded.

Hooks and Filters

Bitcart provides two extension mechanisms:

  1. Hooks: Execute actions at specific points

  2. Filters: Modify data as it flows through the system

To find hooks and filters, you can search the codebase for apply_filters and run_hook.

For example, db_modify_wallet would be called right after wallet is saved in db.

So you can use it like this:

And in filters first argument you receive is the value which you can return unmodified or modify. Other arguments are optional data

Example:

Plugin Settings

To add custom settings for your plugin:

Settings are automatically available in the admin panel and can be accessed via:

Dependencies

If you need to add backend dependencies, create a requirements.txt file in your plugin directory, it will be installed automatically.

Frontend Plugin Development

Admin Panel Extensions

Admin plugins can extend the UI using the our plugin system based on vuems. The basic structure is in e.g. admin/your_plugin_name:

Extending the UI

  1. Register custom components in extends.js:

  1. Add custom routes in routes.js:

  1. Add dependencies to package.json

Store Extensions

Store plugins follow a similar structure to admin plugins but are specifically for the store frontend. They can:

  • Add custom pages

  • Extend existing components

  • Add new payment methods

  • Customize the checkout process

Plugin Packaging

To package your plugin:

This creates a .bitcart file that can be installed on any Bitcart instance.

Best Practices

  1. Use descriptive names for hooks and filters

  2. Document your plugin's requirements and dependencies

  3. Handle errors gracefully

  4. Clean up resources in the shutdown method

  5. Follow the existing code style

  6. Test your plugin thoroughly before distribution

Plugin Lifecycle

  1. Plugin discovery and loading

  2. Database migrations

  3. Plugin initialization (startup)

  4. Hook/filter registration

  5. Settings registration

  6. UI component registration (if applicable)

  7. Background worker setup (if needed)

  8. Shutdown cleanup on server stop

Last updated

Was this helpful?