The Knowledge Graph for TypeScript

Define your ontology with Zod. Query with a fluent builder. Embedded, type-safe, and built for intelligent applications.

Graph User Post Group Role Zod Types

Define. Connect. Query.

Your schema is your database. Your types are your queries.

schema.ts
import { defineNode, defineEdge, defineGraph, createStore } from "@nicia-ai/typegraph";
import { z } from "zod";

// 1. Define your ontology
const Person = defineNode("Person", {
  schema: z.object({ name: z.string(), role: z.string() })
});
const Project = defineNode("Project", {
  schema: z.object({ name: z.string(), status: z.string() })
});
const worksOn = defineEdge("worksOn");

const graph = defineGraph({
  id: "my_app",
  nodes: { Person: { type: Person }, Project: { type: Project } },
  edges: { worksOn: { type: worksOn, from: [Person], to: [Project] } }
});

// 2. Query with full type safety
const results = await store.query()
  .from("Person", "p")
  .whereNode("p", p => p.role.eq("Engineer"))
  .traverse("worksOn", "e")
  .to("Project", "proj")
  .select(ctx => ({ person: ctx.p.name, project: ctx.proj.name }))
  .execute();

Why TypeGraph?

Build smarter applications with a database that understands your domain.

Universal Schema

Define your data model once with Zod. TypeGraph orchestrates your database, API validation, and TypeScript types automatically. No more syncing separate layers.

AI-Native Structure

Give LLMs what they crave: structured, semantic context. Feed your ontology directly to agents for higher-accuracy RAG and reasoning.

Smart Relationships

Go beyond foreign keys. Model real-world logic with implies, inverseOf, and transitive rules that the database understands and enforces.

Zero-Infrastructure Start

Prototyping? Start with an in-memory or SQLite graph. Scaling? Swap the adapter to PostgreSQL without changing a line of your application logic.

Type-Safe Query Builder

Forget strict SQL strings. Build complex, multi-hop graph traversals with a fluent TypeScript API that catches errors before you run code.

Enforced Integrity

Declaratively enforce constraints like disjoint sets ("a User cannot be an Admin and a Guest") and cardinality limits directly at the schema level.

What can you build?

TypeGraph excels where relationships matter most.

Knowledge Graphs for RAG

Feed your LLMs high-fidelity, structured context. Map documents to concepts, authors, and entities to reduce hallucinations and improve retrieval accuracy.

Build this →

Complex Identity & Access

Model fine-grained permissions (ReBAC) with ease. Traverse organizational hierarchies and group memberships in a single, type-safe query.

Build this →

Recommendation Engines

Discover hidden connections. "Users who bought X also bought Y" becomes a trivial graph traversal rather than a complex series of SQL JOINs.

Build this →

Stay in the loop

Occasional updates on new features, guides, and releases. No spam.