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:

  1. Copy the example code
  2. Install dependencies: npm install
  3. Configure environment variables
  4. Run the application: npm start

Contributing Examples

Have a useful example to share? Contributions are welcome!

  1. Create a new markdown file in this directory
  2. Follow the existing format and structure
  3. Include complete, working code
  4. Add setup and configuration instructions
  5. Submit a pull request

Best Practices

When creating applications based on these examples:

  1. Environment Configuration: Always use environment variables for sensitive data
  2. Error Handling: Implement comprehensive error handling
  3. Security: Follow security best practices for authentication
  4. Testing: Include unit and integration tests
  5. Logging: Use structured logging for debugging
  6. Documentation: Document your API endpoints and services

Getting Help

If you have questions about the examples:

  1. Check the API Reference for detailed API documentation
  2. Review the Troubleshooting Guide for common issues
  3. Look at the Core Concepts for architectural guidance
  4. Submit an issue on the project repository

Next Steps

After exploring the examples:

  1. Core Concepts - Understand the architecture
  2. API Reference - Complete API documentation
  3. Migration Guide - Upgrading between versions
  4. Troubleshooting - Common issues and solutions