Modules & Plugins
Litekart's modular architecture allows you to extend functionality through plugins and custom modules. This guide covers how to work with Litekart's plugin system and create custom extensions.
Plugin Architecture
Litekart plugins follow a standardized structure that allows seamless integration with the core platform. Plugins can extend:
- API endpoints - Add new REST API routes
- Services - Extend business logic
- Admin UI - Add new admin panel features
- Storefront - Customize customer experience
- Database models - Add custom data entities
- Event handlers - React to platform events
Official Plugins
Payment Plugins
Stripe Payment Plugin
bash
npm install @litekart/plugin-payment-stripeFeatures:
- Credit card payments
- Apple Pay & Google Pay
- Payment intents
- Webhook handling
- Refund processing
Configuration:
json
{
"plugins": [
{
"resolve": "@litekart/plugin-payment-stripe",
"options": {
"apiKey": "sk_test_...",
"webhookSecret": "whsec_..."
}
}
]
}PayPal Payment Plugin
bash
npm install @litekart/plugin-payment-paypalFeatures:
- PayPal Checkout
- PayPal Payments Pro
- Recurring payments
- Express Checkout
Shipping Plugins
Shippo Shipping Plugin
bash
npm install @litekart/plugin-shipping-shippoFeatures:
- Real-time shipping rates
- Label generation
- Tracking integration
- Multi-carrier support
Shiprocket Shipping Plugin
bash
npm install @litekart/plugin-shipping-shiprocketFeatures:
- Indian shipping integration
- Bulk label printing
- COD orders
- Real-time tracking
Communication Plugins
SendGrid Email Plugin
bash
npm install @litekart/plugin-email-sendgridFeatures:
- Transactional emails
- Template support
- Bounce handling
- Analytics
SMS Gateway Plugins
bash
npm install @litekart/plugin-sms-twilio
npm install @litekart/plugin-sms-aws-snsFeatures:
- OTP verification
- Order notifications
- Marketing SMS
- Delivery receipts
Analytics Plugins
Google Analytics Plugin
bash
npm install @litekart/plugin-analytics-googleFeatures:
- E-commerce tracking
- Conversion funnels
- Custom events
- Real-time reports
Facebook Pixel Plugin
bash
npm install @litekart/plugin-analytics-facebookFeatures:
- Purchase tracking
- Add to cart events
- Custom audiences
- Conversion optimization
Creating Custom Plugins
Plugin Structure
my-custom-plugin/
├── package.json
├── src/
│ ├── index.js
│ ├── services/
│ ├── routes/
│ ├── models/
│ └── migrations/
├── migrations/
└── README.mdBasic Plugin Example
javascript
// src/index.js
export default {
name: 'my-custom-plugin',
version: '1.0.0',
// Register services
services: [
{
name: 'customService',
service: './services/custom-service.js'
}
],
// Register API routes
routes: [
{
method: 'GET',
path: '/api/custom-endpoint',
handler: './routes/custom-route.js'
}
],
// Database migrations
migrations: [
'./migrations/create-custom-table.js'
],
// Plugin configuration
options: {
apiKey: {
type: 'string',
required: true,
description: 'API key for external service'
}
}
}Service Creation
javascript
// src/services/custom-service.js
import { BaseService } from '@litekart/core'
export default class CustomService extends BaseService {
constructor(container) {
super(container)
this.logger = container.logger
this.db = container.db
}
async customMethod(data) {
// Your custom logic here
return await this.db.customTable.create(data)
}
}API Route Creation
javascript
// src/routes/custom-route.js
export default async (req, res) => {
const customService = req.scope.resolve('customService')
try {
const result = await customService.customMethod(req.body)
res.json({ success: true, data: result })
} catch (error) {
res.status(500).json({ success: false, error: error.message })
}
}Database Migration
javascript
// src/migrations/create-custom-table.js
export const up = async (db) => {
await db.schema.createTable('custom_table', (table) => {
table.increments('id').primary()
table.string('name').notNullable()
table.timestamp('created_at').defaultTo(db.fn.now())
})
}
export const down = async (db) => {
await db.schema.dropTable('custom_table')
}Plugin Development Best Practices
Code Organization
- Separate concerns - Keep services, routes, and models in separate files
- Use TypeScript - For better type safety and developer experience
- Follow naming conventions - Use consistent naming patterns
- Document your code - Include JSDoc comments for public APIs
Error Handling
javascript
// Proper error handling in services
async customMethod(data) {
try {
// Validate input
if (!data.name) {
throw new Error('Name is required')
}
// Business logic
const result = await this.processData(data)
// Log success
this.logger.info('Custom operation completed', { id: result.id })
return result
} catch (error) {
// Log error
this.logger.error('Custom operation failed', { error: error.message })
// Re-throw for proper error handling
throw error
}
}Testing
javascript
// __tests__/custom-service.test.js
import CustomService from '../src/services/custom-service.js'
describe('CustomService', () => {
let service
let mockDb
beforeEach(() => {
mockDb = {
customTable: {
create: jest.fn()
}
}
service = new CustomService({
db: mockDb,
logger: console
})
})
it('should create custom record', async () => {
const data = { name: 'Test' }
const expected = { id: 1, name: 'Test' }
mockDb.customTable.create.mockResolvedValue(expected)
const result = await service.customMethod(data)
expect(result).toEqual(expected)
expect(mockDb.customTable.create).toHaveBeenCalledWith(data)
})
})Plugin Publishing
Publishing to npm
json
// package.json
{
"name": "@litekart/plugin-custom-feature",
"version": "1.0.0",
"description": "Custom feature plugin for Litekart",
"main": "dist/index.js",
"keywords": ["litekart", "plugin", "ecommerce"],
"author": "Your Name",
"license": "MIT",
"peerDependencies": {
"@litekart/core": "^1.0.0"
}
}bash
# Build and publish
npm run build
npm publish --access publicPlugin Registry
Submit your plugin to the Litekart Plugin Registry:
- Create a GitHub repository
- Add plugin metadata
- Submit PR to plugin registry
- Plugin gets reviewed and published
Advanced Plugin Features
Event Listeners
javascript
export default {
name: 'event-listener-plugin',
events: {
'order.placed': './listeners/order-placed.js',
'customer.created': './listeners/customer-created.js'
}
}Cron Jobs
javascript
export default {
name: 'cron-plugin',
cronJobs: [
{
name: 'daily-report',
schedule: '0 9 * * *', // Daily at 9 AM
handler: './jobs/daily-report.js'
}
]
}Admin UI Extensions
javascript
export default {
name: 'admin-ui-plugin',
admin: {
routes: [
{
path: '/admin/custom',
component: './admin/pages/custom-page.vue'
}
],
menu: [
{
label: 'Custom',
icon: 'custom-icon',
path: '/admin/custom'
}
]
}
}Troubleshooting Plugins
Common Issues
Plugin not loading
- Check plugin name and version compatibility
- Verify plugin structure matches requirements
- Check server logs for error messages
Database migration failures
- Ensure migration files are properly exported
- Check database permissions
- Verify migration order
API routes not working
- Check route registration
- Verify middleware setup
- Test route isolation
Debug Mode
Enable debug logging for plugins:
bash
# Environment variable
DEBUG=litekart:* npm run devRecovery Procedures
Reset Plugin Configuration
sql
-- Remove plugin from database
DELETE FROM plugins WHERE name = 'problematic-plugin';
-- Clear plugin cache
TRUNCATE TABLE plugin_cache;Community Plugins
Popular Community Plugins
- Multi-vendor marketplace - Enable multiple sellers
- Advanced reporting - Custom analytics dashboards
- Inventory management - Enhanced stock tracking
- Loyalty program - Points and rewards system
- Product reviews - Advanced review and rating system
- SEO optimization - Enhanced search engine optimization
Finding Plugins
- Plugin Registry - Official plugin directory
- GitHub - Community plugins
- Community Forum - Plugin discussions
Support
Need help with plugins?