Examples
This directory contains working examples of using the Asterisms JS SDK Backend in different scenarios.
Available Examples
Basic Integration
Service Usage
Advanced Patterns
Quick Start Examples
Basic SvelteKit Setup
// src/lib/sdkInstance.ts
import { createSvelteKitBackendSDK } from '@asterisms/sdk-backend';
import { createFetchAdapter } from '@asterisms/sdk-backend';
import { building } from '$app/environment';
const provider = createSvelteKitBackendSDK({
env: process.env,
building,
httpFactory: createFetchAdapter(fetch),
registrationData: {
bundleId: 'com.example.app',
capabilities: ['FRONTEND_WEBSITE'],
description: 'My Application',
name: 'My App',
subdomain: 'app',
title: 'My App'
}
});
export { provider };
Basic Express.js Setup
// server.js
import express from 'express';
import { getAsterismsBackendSDK } from '@asterisms/sdk-backend';
import { createFetchAdapter } from '@asterisms/sdk-backend';
const app = express();
const sdk = getAsterismsBackendSDK({
bundleId: 'com.example.api',
domain: process.env.ASTERISMS_DOMAIN,
subdomain: 'api',
httpServiceAdapterFactory: createFetchAdapter(fetch),
registrationData: {
bundleId: 'com.example.api',
capabilities: ['BACKEND_SERVICE'],
description: 'API Service',
name: 'API',
subdomain: 'api',
title: 'API Service'
}
});
await sdk.boot();
app.use('/api', (req, res) => {
// Use SDK services
const auth = sdk.authorization();
const storage = sdk.storage();
});
Example Categories
🚀 Getting Started
For developers new to the SDK Backend, start with these examples:
🔐 Authentication & Security
Examples showing authentication and security patterns:
💾 Data & Storage
Examples for data management and storage:
🔔 Notifications
Examples for sending notifications:
🏗️ Architecture & Patterns
Advanced architectural patterns:
Running Examples
Each example includes:
- Complete, working code
- Setup instructions
- Configuration examples
- Testing guidance
To run an example:
- Copy the example code
- Install dependencies:
npm install
- Configure environment variables
- Run the application:
npm start
Contributing Examples
Have a useful example to share? Contributions are welcome!
- Create a new markdown file in this directory
- Follow the existing format and structure
- Include complete, working code
- Add setup and configuration instructions
- Submit a pull request
Best Practices
When creating applications based on these examples:
- Environment Configuration: Always use environment variables for sensitive data
- Error Handling: Implement comprehensive error handling
- Security: Follow security best practices for authentication
- Testing: Include unit and integration tests
- Logging: Use structured logging for debugging
- Documentation: Document your API endpoints and services
Getting Help
If you have questions about the examples:
- Check the API Reference for detailed API documentation
- Review the Troubleshooting Guide for common issues
- Look at the Core Concepts for architectural guidance
- Submit an issue on the project repository
Next Steps
After exploring the examples:
- Core Concepts - Understand the architecture
- API Reference - Complete API documentation
- Migration Guide - Upgrading between versions
- Troubleshooting - Common issues and solutions