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:
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:
Create a
models.py
file in your plugin directoryDefine SQLAlchemy models
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:
Hooks: Execute actions at specific points
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
Register custom components in
extends.js
:
Add custom routes in
routes.js
:
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
Use descriptive names for hooks and filters
Document your plugin's requirements and dependencies
Handle errors gracefully
Clean up resources in the shutdown method
Follow the existing code style
Test your plugin thoroughly before distribution
Plugin Lifecycle
Plugin discovery and loading
Database migrations
Plugin initialization (startup)
Hook/filter registration
Settings registration
UI component registration (if applicable)
Background worker setup (if needed)
Shutdown cleanup on server stop
Last updated
Was this helpful?