Additional Features Documentation
Table of Contents
Email Templates
BAASIX includes a powerful visual email template designer for creating and managing system email templates.
Template Designer Features
The email template designer provides:
- Visual Drag-and-Drop Editor — Built with GrapesJS for intuitive email design
- Responsive Preview — Desktop, tablet, and mobile device previews
- Variable Blocks — Pre-built blocks for template variables (user info, tenant details, auth links)
- Code Editor — Direct HTML/CSS editing with CodeMirror syntax highlighting and Prettier formatting
- Real-time Preview — See changes instantly as you design
Template Types
BAASIX supports various email template types:
magic_link— Magic link authentication emailsinvite— User invitation emailspassword_reset— Password reset emailswelcome— Welcome emails for new usersverification— Email verification emails- Custom templates for your application needs
Available Template Variables
Template variables are automatically replaced when sending emails:
User Variables:
| Variable | Description |
|---|---|
{{user.firstName}} | User's first name |
{{user.lastName}} | User's last name |
{{user.fullName}} | User's full name |
{{user.email}} | User's email address |
{{user.phone}} | User's phone number |
Tenant Variables:
| Variable | Description |
|---|---|
{{tenant.name}} | Company/organization name |
{{tenant.logo}} | Company logo URL |
{{tenant.website}} | Company website |
{{tenant.address}} | Company address |
{{tenant.phone}} | Company phone |
{{tenant.email}} | Company email |
Authentication Variables:
| Variable | Description |
|---|---|
{{magicLink}} | Magic link URL |
{{magicCode}} | Magic code for authentication |
{{resetPasswordLink}} | Password reset link |
{{verificationLink}} | Email verification link |
{{inviteLink}} | User invitation link |
{{loginLink}} | Login page link |
Date/Time Variables:
| Variable | Description |
|---|---|
{{currentDate}} | Current date |
{{currentTime}} | Current time |
{{currentYear}} | Current year |
Managing Templates via API
List Templates
GET /items/baasix_TemplateGet Template
GET /items/baasix_Template/:idUpdate Template
PATCH /items/baasix_Template/:id
Content-Type: application/json
{
"subject": "Welcome to {{tenant.name}}",
"body": "<JSON project data from GrapesJS>"
}Template Storage Format
Templates are stored in the baasix_Template collection with:
type— Template type identifier (e.g.,magic_link,invite)subject— Email subject line (supports variables)description— Template descriptionbody— GrapesJS project data (JSON) containing HTML structure and stylesisActive— Whether the template is active
Using Templates Programmatically
import { MailService } from '@baasix/baasix';
// Send email using a template
await mailService.sendMail({
to: 'user@example.com',
templateType: 'welcome',
context: {
user: {
firstName: 'John',
lastName: 'Doe',
email: 'john@example.com',
},
tenant: {
name: 'Acme Corp',
website: 'https://acme.com',
},
},
});Admin Dashboard
The admin dashboard provides a full-featured template management interface:
- Template List — View all templates with type, subject, and status
- Quick Edit — Edit template subject and description via side panel
- Visual Designer — Full-page GrapesJS editor for template design
- Code Editor — Side-by-side HTML and CSS editing with formatting
Best Practices
- Use Inline CSS — Email clients have limited CSS support; use inline styles
- Test Across Clients — Preview templates in multiple email clients
- Keep It Simple — Complex layouts may not render correctly in all clients
- Use Tables for Layout — Many email clients still require table-based layouts
- Provide Fallbacks — Include alt text for images and plain text versions
Logo Customization
You can customize the logo used in email templates and potentially other parts of the application.
Default Logo Location
The default logo is located at:
baasix/templates/logo/logo.pngCustom Logo
To use a custom logo, place your logo file at:
extensions/baasix-templates/logo/logo.pngThe system will automatically use the custom logo if it exists, falling back to the default logo otherwise.
Storage Services
BAASIX supports multiple storage services for file handling.
Configuring Storage Services
Storage services are configured through environment variables:
STORAGE_SERVICES_ENABLED=local,s3
STORAGE_DEFAULT_SERVICE=localLocal Storage Configuration
LOCAL_STORAGE_PATH=/path/to/local/storageS3 Storage Configuration
S3_STORAGE_ACCESS_KEY_ID=your_access_key
S3_STORAGE_SECRET_ACCESS_KEY=your_secret_key
S3_STORAGE_REGION=your_region
S3_STORAGE_BUCKET=your_bucket_name
S3_STORAGE_ENDPOINT=your_s3_endpointCache Management
BAASIX includes a caching system to improve performance.
Cache Initialization
The cache is initialized in the server.js file:
await initializeCache({ ttl: process.env.CACHE_TTL * 1000 || 30000 });Cache Configuration
Cache settings can be configured through environment variables:
CACHE_TTL=30000Using the Cache
The cache can be used in various parts of the application to store and retrieve frequently accessed data:
const cache = getCache();
await cache.set('key', value, expiresIn);
const cachedValue = await cache.get('key');TasksService
BAASIX includes a built-in TasksService for managing background tasks efficiently.
Overview
The TasksService manages background tasks from the baasix_Tasks table by:
- Caching "Not started" tasks scheduled within 4 hours to reduce database calls and memory usage
- Coordinating task execution to prevent concurrent processing
- Automatically refreshing cache when tasks change (max refresh interval: 3 hours)
- Providing graceful shutdown with task completion waiting
Quick Start
import tasksService from '../../baasix/services/TasksService';
// Check if a task is running
if (await tasksService.isTaskRunning()) {
return; // Skip if already running
}
// Mark task as running
await tasksService.setTaskRunning(true);
try {
// Get available tasks
const tasks = await tasksService.getNotStartedTasks();
// Process tasks...
} finally {
await tasksService.setTaskRunning(false);
}Environment Configuration
# Cache refresh interval in seconds (default: 600, maximum: 10800 = 3 hours)
TASK_LIST_REFRESH_INTERVAL=600
# Shutdown wait time in seconds (default: 30)
TASK_SHUTDOWN_WAIT_TIME=30Note: Only tasks with scheduled_time within 4 hours are cached to optimize memory usage.
For Complete Documentation
See the dedicated TasksService Documentation for comprehensive usage examples, API reference, and best practices.
These additional features enhance the functionality and customization options of the BAASIX system. Proper utilization of email templates, logo customization, storage services, caching, and task management can significantly improve the user experience and performance of your application.
Related Documentation
- TasksService Documentation - Complete TasksService guide
- File Routes - Working with files and assets
- Baasix Extensions - Create custom extensions
- Socket.IO Integration - Real-time features