NinjaStack — Schema-First Agentic Backend Framework
Description: Point at a database, get a full agentic backend. Auto-generate ADK agents, GraphQL, auth, and UI from your schema.

Open Source · Python · Google ADK

# Point at a database.
Get an agentic backend.

NinjaStack auto-generates AI agents, GraphQL APIs, authentication, and UI from your schema. Define once, generate everything.

See How It Works → View Source
terminal

    # Connect to your database, generate everything
    $ ninjastack introspect --db postgres://localhost/myapp
    → Discovered 12 entities, 8 relationships, 3 domains

    $ ninjastack sync
    → Generated: 12 models, 18 agents, 12 GraphQL types
    → Wired: 3 domain agents + coordinator
    → Auth: JWT + RBAC configured

    $ ninjastack serve
    → 🥷 Agentic backend running at http://localhost:8000
    → GraphQL playground at /graphql
    → Agent chat at /chat

## The problem with building agentic backends

Every team building AI agents rewrites the same boilerplate: data access, tool definitions, permission checks, API layers, agent orchestration.

The result? Months of plumbing before any agent does anything useful. Fragile hand-wired tool registrations. Auth bolted on as an afterthought. No clear ownership boundaries between agents.

## Schema-first changes everything

NinjaStack starts from what you already have — your database schema. From that single source of truth, it generates the entire agentic stack.

Agents get scoped tools per entity. Domains define ownership boundaries. RBAC is declarative. GraphQL is automatic. You focus on business logic, not wiring.

## Built for real backends

Not a toy. A production framework for schema-driven agentic systems.

🔍

### Database Introspection

Connect to SQL, MongoDB, Neo4j, or vector stores. NinjaStack discovers entities, fields, relationships, and constraints automatically.

🤖

### ADK Agent Generation

Auto-generates Google ADK agents with scoped CRUD tools per entity. Data agents are deterministic (no LLM). Domain agents use Gemini for reasoning.

🧬

### Agentic Schema Definition

A typed, composable schema language for entities, relationships, domains, and agent configs. Your single source of truth.

🔐

### Auth & RBAC

Pluggable auth (OAuth2, JWT, API keys) with role-based access control at the domain and entity level. Declarative, not bolted on.

📊

### GraphQL Generation

Strawberry GraphQL types, queries, mutations, and inputs generated from your schema. Permission-enforced at the resolver level.

💬

### Conversational Setup

Don't have a database yet? Chat with the Setup Assistant (real Gemini-powered LlmAgent) to design your schema through natural dialogue.

🎯

### Tool Scoping

Each agent sees only its own tools. Data agents own one entity. Domain agents own one domain. The coordinator routes across domains. No leaking.

🚀

### K8s Deployment

Helm charts and deployment manifests generated automatically. Deploy your agentic backend to GKE, EKS, or any Kubernetes cluster.

🔄

### Polyglot Persistence

Unified persistence layer across SQL, NoSQL, graph, and vector databases. Entities declare their storage engine; the framework handles the rest.

## Three paths to an agentic backend

Start from an existing database, from conversation, or both.

🔌

### Bolt-on Mode

Connect to an existing database. NinjaStack introspects your schema and generates the full stack around it.

    ninjastack introspect \
      --db postgres://...
      --db mongo://...
      --db neo4j://...

💬

### Greenfield Mode

No database? Chat with the AI setup assistant to design your domain model through natural conversation.

    ninjastack init --interactive

    # "I need a bookstore with
    #  books, customers, orders,
    #  and reviews..."

🔀

### Hybrid Mode

Bolt-on to an existing system, then expand the schema conversationally. Best of both worlds.

    ninjastack introspect --db ...
    ninjastack assistant
    # "Add a Reviews entity
    #  with semantic search..."

## Agent hierarchy with clear boundaries

Every agent has a scope. No tool leaking. No implicit state. Explicit ownership at every level.

🎯 Coordinator Agent
Routes requests across domains · LLM-powered intent classification
↓
📚 Catalog Domain Agent
Gemini 2.5 Flash · Medium reasoning
📖 Book
6 CRUD tools
⭐ Review
6 CRUD tools + semantic
🛒 Commerce Domain Agent
Gemini 2.5 Pro · High reasoning
👤 Customer
6 CRUD tools
📦 Order
6 CRUD tools
↓
🗄️ Unified Persistence Layer
PostgreSQL MongoDB Neo4j ChromaDB
Data Agents

Deterministic. No LLM. One entity, scoped tools. Fast, predictable CRUD.

Domain Agents

LLM-powered. Owns a business domain. Delegates to data agents. Configurable reasoning level.

Coordinator

Top-level router. Classifies intent. Delegates to the right domain. Synthesizes cross-domain results.

## See it in action

Real code from the bookstore example. No pseudo-code.

01

### Define your schema

    from ninja_core.schema.entity import EntitySchema, FieldSchema, FieldType, StorageEngine
    from ninja_core.schema.domain import DomainSchema

    book = EntitySchema(
        name="Book",
        storage_engine=StorageEngine.SQL,
        fields=[
            FieldSchema(name="id", field_type=FieldType.UUID, primary_key=True),
            FieldSchema(name="title", field_type=FieldType.STRING, indexed=True),
            FieldSchema(name="author", field_type=FieldType.STRING),
            FieldSchema(name="price", field_type=FieldType.FLOAT),
        ],
    )

    catalog = DomainSchema(
        name="Catalog",
        entities=["Book", "Review"],
        agent_config=AgentConfig(reasoning_level=ReasoningLevel.MEDIUM),
    )

02

### Agents wire automatically

    from ninja_agents.base import DataAgent, DomainAgent, CoordinatorAgent

    # Data agents: deterministic CRUD, no LLM
    book_agent = DataAgent(entity=book)
    book_agent.execute("book_get", id="abc-123")  # Instant, no API call

    # Domain agents: LLM-powered orchestration
    catalog = DomainAgent(domain=catalog_domain, data_agents=[book_agent, review_agent])

    # Coordinator: routes across all domains
    coordinator = CoordinatorAgent(domain_agents=[catalog, commerce])
    coordinator.route("Find sci-fi books", target_domains=["Catalog"])

03

### Declarative auth & permissions

    from ninja_auth.rbac import RBACConfig, RBACPolicy, RoleDefinition

    policy = RBACPolicy(config=RBACConfig(roles={
        "customer": RoleDefinition(permissions=[
            "read:Catalog",             # Browse books and reviews
            "write:Catalog.Review",     # Write reviews only
            "read:Commerce.Order",      # View own orders
        ]),
    }))

    # Built-in: admin (*:*), editor (read:* + write:*), viewer (read:*)
    policy.check(user_perms, "write", "Catalog", "Book")  # → PermissionError!

## The stack

Built on proven foundations. No custom runtime. No vendor lock-in.

🐍
Python 3.12+
Pydantic v2
🤖
Google ADK
Agent framework
⚡
FastAPI
API server
🍓
Strawberry
GraphQL
🔮
LiteLLM
Model-agnostic
🔑
JWT + OAuth2
Auth strategies
☸️
Kubernetes
Helm deploy
📦
uv
Package management

## Modular monorepo

15 focused packages. Use what you need.

libs/
ninja-core ASD schemas
ninja-introspect DB discovery
ninja-codegen Code generation
ninja-agents ADK agents
ninja-auth Auth + RBAC
ninja-gql GraphQL layer
ninja-persistence Polyglot DB
ninja-boundary Data coercion
ninja-graph Graph-RAG
ninja-models Model gen
ninja-deploy K8s/Helm
ninja-ui UI generation
ninja-cli CLI tooling
apps/
ninja-api FastAPI server
ninja-setup-assistant Gemini wizard

## Stop wiring. Start building.

NinjaStack is open source and ready to use. Define your schema, generate your stack, ship your agents.

`pip install agentic-backend`
⭐ Star on GitHub Browse Examples