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 Email Editor — Intuitive HTML editor with live preview
- 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": "<HTML email template content>"
}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— HTML email template content with Liquid variablesisActive— 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 visual 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.
Log Cleanup
BAASIX includes automatic cleanup for audit logs and email logs to prevent unbounded database growth. By default, log cleanup is disabled and must be explicitly enabled via environment variables.
Environment Configuration
# =============================================================================
# AUDIT LOG CLEANUP
# =============================================================================
# Enable automatic audit log cleanup (default: false)
AUDIT_LOG_CLEANUP_ENABLED=true
# Audit log retention period in days (default: 90)
# Records older than this will be automatically deleted
AUDIT_LOG_RETENTION_DAYS=90
# =============================================================================
# EMAIL LOG CLEANUP
# =============================================================================
# Enable automatic email log cleanup (default: false)
EMAIL_LOG_CLEANUP_ENABLED=true
# Email log retention period in days (default: 30)
# Records older than this will be automatically deleted
EMAIL_LOG_RETENTION_DAYS=30How It Works
When enabled, the log cleanup service:
- Starts automatically when the server starts
- Runs daily to delete old log entries
- Runs an initial cleanup 10 seconds after server startup
- Logs the number of deleted records to the console
Log Tables
| Table | Description | Default Retention |
|---|---|---|
baasix_AuditLog | Tracks all CRUD operations and authentication events | 90 days |
baasix_EmailLog | Tracks all sent emails with status and metadata | 30 days |
Manual Cleanup (Programmatic)
You can also trigger log cleanup programmatically from extensions or custom endpoints:
import { triggerLogCleanup } from '@baasix/baasix';
// Use environment configuration
const result = await triggerLogCleanup();
console.log(`Deleted ${result.auditLogs} audit logs, ${result.emailLogs} email logs`);
// Override configuration
const result = await triggerLogCleanup({
auditLogs: true,
emailLogs: true,
auditLogRetentionDays: 30, // Custom retention
emailLogRetentionDays: 7, // Custom retention
});Best Practices
- Enable cleanup in production to prevent unbounded database growth
- Set appropriate retention periods based on compliance requirements
- Monitor disk space if cleanup is disabled
- Back up logs before enabling cleanup if you need historical data
- Consider compliance (GDPR, HIPAA) when setting retention periods
Disabling Cleanup
To disable automatic cleanup (default behavior):
AUDIT_LOG_CLEANUP_ENABLED=false
EMAIL_LOG_CLEANUP_ENABLED=falseWhen disabled, logs will accumulate indefinitely. You can still perform manual cleanup via the programmatic API or by directly deleting records from the database.
These additional features enhance the functionality and customization options of the BAASIX system. Proper utilization of email templates, logo customization, storage services, caching, task management, and log cleanup 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
- Services Reference - ItemsService and other services