ECS Architecture
Built on the Entity-Component-System pattern, providing a highly decoupled, scalable, and maintainable architecture for complex backend applications.
Powered by Bun
Leverages Bun's incredible performance and modern TypeScript runtime to deliver blazing fast execution.
GraphQL & REST
Automatically generates GraphQL schemas and REST endpoints from your components and services, saving you hours of boilerplate.
PostgreSQL Native
First-class support for PostgreSQL with automatic table generation, migrations, and optimized queries out of the box.
100% Type-Safe
Written in TypeScript with strict typing. Catch errors at compile time and enjoy excellent IDE autocompletion.
BunSane Studio
Built-in development dashboard to browse entities, inspect components, and debug your PostgreSQL data without leaving your workflow.
Simple, Declarative, Powerful
BunSane uses the Entity-Component-System (ECS) architecture to keep your backend modular and scalable.
- ✅ Define atomic data with
@Component&@CompData - ✅ Structure entities with
@ArcheType - ✅ Expose GraphQL via
@GraphQLOperation - ✅ Automatic PostgreSQL tables & GraphQL schema
import { BaseComponent, CompData, Component } from "bunsane/core/components";
import { ArcheType, ArcheTypeField, BaseArcheType } from "bunsane/core/ArcheType";
import { BaseService } from "bunsane/service";
import { GraphQLOperation } from "bunsane/gql";
import { Entity } from "bunsane/core/Entity";
import { t } from "bunsane/gql/schema";
// 1. Define Components
@Component
export class NameComponent extends BaseComponent {
@CompData({ indexed: true })
value: string = "";
}
@Component
export class EmailComponent extends BaseComponent {
@CompData({ indexed: true })
value: string = "";
@CompData()
verified: boolean = false;
}
// 2. Define an Archetype
@ArcheType("User")
export class UserArcheTypeClass extends BaseArcheType {
@ArcheTypeField(NameComponent)
name!: NameComponent;
@ArcheTypeField(EmailComponent)
email!: EmailComponent;
}
export const UserArcheType = new UserArcheTypeClass();
// 3. Create a Service with GraphQL
class UserService extends BaseService {
constructor() {
super();
UserArcheType.registerFieldResolvers(this);
}
@GraphQLOperation({
type: "Mutation",
input: { name: t.string().required(), email: t.string().email().required() },
output: UserArcheType,
})
async createUser(args: { name: string; email: string }) {
const user = Entity.Create()
.add(NameComponent, { value: args.name })
.add(EmailComponent, { value: args.email });
await user.save();
return user;
}
}