weweb-backend-core
v0.1.0
Published
WeWeb Backend Core - Framework for building backend workflows in WeWeb
Readme
WeWeb Backend Core
A Node.js-based backend service framework for WeWeb, supporting integration with external services like OpenAI and Supabase.
Features
- Backend service framework for WeWeb applications
- Support for integrations with external services (OpenAI, Supabase)
- Flexible workflow configuration
- Middleware support
- Input validation and mapping
- Testing with Vitest
Project Structure
- Uses Node.js runtime
- Organized as a pnpm workspace
- Two main packages:
backend-coreandopenai - Uses Vite for building and bundling
Packages
backend-core
Core library for building and serving backend workflows:
- API route handling and serving
- Security configuration with access rule handling
- Request validation and input mapping
- Integration with external services via pluggable integrations
- Error handling and response formatting
openai
OpenAI-specific integration that provides:
- Wrapper around OpenAI API client
- Methods for chat completions, embeddings, moderation, and image generation
- Schema definition for input validation
Main Features
Workflow Configuration:
- Define HTTP endpoints with paths and methods
- Configure security settings (public/authenticated access)
- Set up input validation
- Map request data to action inputs
Integration System:
- Plugin-based architecture for integrating external services
- Each integration provides named methods that can be called from workflows
Request Processing:
- Input validation against JSON schema
- Flexible mapping from request data (body, headers, query params) to action inputs
- Support for nested object mapping and direct values
CORS Support:
- Built-in CORS handling for cross-origin requests
Development
Setup
This project uses pnpm for package management. Make sure you have Node.js (v18+) and pnpm installed on your system.
# Install dependencies
pnpm install
# Build all packages
pnpm build
# Start development mode with watch
pnpm devRunning Tests
The project uses Vitest for testing:
# Run all tests
pnpm testExample Test Structure
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
describe('Feature name', () => {
beforeAll(() => {
// Setup code that runs once before all tests
});
afterAll(() => {
// Cleanup code that runs once after all tests
});
it('should behave in a certain way', () => {
// Test code
expect(result).toBe(expectedValue);
});
});Code Style
Format code with:
pnpm formatRun linter:
pnpm lintCheck types:
pnpm typecheckBest Practices
- Use descriptive test descriptions
- Separate setup and teardown with beforeAll/afterAll
- Run the combined command for code quality:
pnpm lint && pnpm typecheckPackage Usage
backend-core
import { serve } from '@yamakasinge/backend-core';
const config = {
// Backend configuration
};
const server = serve(config);openai
import { serve } from '@yamakasinge/backend-core';
import OpenAI from '@yamakasinge/openai';
const config = {
workflows: [/* ... */],
integrations: [OpenAI],
production: false
};
serve(config);Building for Production
# Build all packages for production
pnpm buildThis will generate optimized ES modules in the dist folder of each package.
