Skip to content
~/docs/getting-started/quick-start
DOCUMENTATION

Quick Start

Build your first graph database in 5 minutes

Let's build a simple social graph database with users and their connections. By the end of this guide, you'll understand the core concepts of KiteDB.

1. Define Your Schema

KiteDB uses a schema to define nodes and edges. Let's create a simple social network with users and follow relationships.

social.ts
import { kite } from '@kitedb/core';

// Define schema inline when opening the database
const db = await kite('./social.kitedb', {
  nodes: [
    {
      name: 'user',
      props: {
        name: { type: 'string' },
        email: { type: 'string' },
      },
    },
  ],
  edges: [
    {
      name: 'follows',
      props: {
        followedAt: { type: 'int' },  // Unix timestamp
      },
    },
  ],
});

2. Add Some Data

typescript
// Create users
const alice = db.insert('user')
  .values('alice', { name: 'Alice Chen', email: 'alice@example.com' })
  .returning();

const bob = db.insert('user')
  .values('bob', { name: 'Bob Smith', email: 'bob@example.com' })
  .returning();

// Create a follow relationship
db.link(alice.id, 'follows', bob.id, { followedAt: Date.now() });

3. Query the Graph

typescript
// Find all users Alice follows
const following = db
  .from(alice.id)
  .out('follows')
  .nodes();

console.log('Alice follows:', following.length, 'users');

// Check if Alice follows Bob
const followsBob = db.hasEdge(alice.id, 'follows', bob.id);
console.log('Alice follows Bob:', followsBob);

4. Close the Database

typescript
// Always close when done
db.close();

Next Steps

Congratulations! You've built your first graph database with KiteDB. Continue learning with these guides: