Skip to content

Latest commit

Β 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

TaylorDB + TanStack Start Template

A full-stack React template for building type-safe TaylorDB applications with TanStack Start, TanStack Router, Tailwind CSS, and shadcn/ui.

This template replaces the older React Router SPA + Express/tRPC split used by the legacy TaylorDB full-stack template with a single TanStack Start app. TaylorDB access runs on the server through TanStack Start server functions or server routes.

What This Template Provides

  • TanStack Start: SSR, routing, server functions, server routes, and Nitro output.
  • Type-safe TaylorDB access: @taylordb/query-builder with generated schema types.
  • Server-only data layer: database calls live in src/server/**, never in client components.
  • Modern UI: Tailwind CSS 4 and shadcn/ui components in src/components/ui.
  • AI-ready conventions: AGENTS.md explains where agents should put routes, server functions, repositories, and TaylorDB helpers.

Quick Start

pnpm install
pnpm dev

Build for production:

pnpm build
node .output/server/index.mjs

Project Structure

taylordb-tanstack-template/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ routes/                 # TanStack Router file routes
β”‚   β”‚   β”œβ”€β”€ __root.tsx          # Root document shell
β”‚   β”‚   β”œβ”€β”€ index.tsx           # Home route
β”‚   β”‚   └── $.tsx               # Catch-all 404 route
β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”œβ”€β”€ ui/                 # shadcn/ui components
β”‚   β”‚   β”œβ”€β”€ Header.tsx
β”‚   β”‚   └── ThemeToggle.tsx
β”‚   β”œβ”€β”€ lib/
β”‚   β”‚   └── utils.ts            # shadcn cn() helper
β”‚   β”œβ”€β”€ server/                 # Recommended server-only TaylorDB code
β”‚   β”‚   β”œβ”€β”€ taylordb.ts         # create per-request query builder
β”‚   β”‚   β”œβ”€β”€ repositories/       # table-level query functions
β”‚   β”‚   β”œβ”€β”€ services/           # business logic across repositories
β”‚   β”‚   └── *.functions.ts      # createServerFn operations
β”‚   β”œβ”€β”€ routeTree.gen.ts        # generated by TanStack Router
β”‚   β”œβ”€β”€ router.tsx
β”‚   └── styles.css              # Tailwind + design tokens
β”œβ”€β”€ docs/                       # shadcn and TaylorDB/TanStack guides
β”œβ”€β”€ components.json             # shadcn config
β”œβ”€β”€ package.json
└── vite.config.ts

src/server/** is the recommended location for TaylorDB code. The template may not include generated TaylorDB schema types until you connect a TaylorDB base and run the schema generator.

Tech Stack

App

  • React 19
  • TanStack Start
  • TanStack Router
  • Nitro output
  • Vite 8
  • TypeScript

Data

  • TaylorDB Query Builder (@taylordb/query-builder)
  • Generated TaylorDatabase schema types
  • TanStack Start server functions for app-facing data operations
  • TanStack Start server routes for raw HTTP endpoints and multipart/form-data

UI

  • Tailwind CSS 4
  • shadcn/ui
  • Radix UI primitives through the shadcn registry
  • Lucide icons

Recommended TaylorDB Pattern

TanStack Start does not need Express or tRPC for normal app data access. Use:

  • Server functions for typed reads and mutations called from loaders/components.
  • Server routes for raw HTTP APIs, webhooks, or file upload endpoints.
  • A server-only TaylorDB helper that reads the app_access_token cookie per request and constructs a fresh query builder.

Example helper:

// src/server/taylordb.ts
import { createQueryBuilder } from "@taylordb/query-builder";
import { getRequestHeader } from "@tanstack/react-start/server";
import type { TaylorDatabase } from "./taylordb/types";

function readCookie(name: string) {
  const header = getRequestHeader("cookie");
  if (!header) return null;

  for (const part of header.split(/;\s*/)) {
    const eq = part.indexOf("=");
    if (eq === -1) continue;
    if (part.slice(0, eq) === name) return decodeURIComponent(part.slice(eq + 1));
  }

  return null;
}

export function getTaylorDB() {
  const appAccessToken = readCookie("app_access_token");
  if (!appAccessToken) throw new Error("Unauthorized");

  return createQueryBuilder<TaylorDatabase>({
    baseUrl: process.env.TAYLORDB_BASE_URL!,
    baseId: process.env.TAYLORDB_SERVER_ID!,
    apiKey: appAccessToken,
  });
}

Example server function:

// src/server/users.functions.ts
import { createServerFn } from "@tanstack/react-start";
import { z } from "zod";
import { getTaylorDB } from "./taylordb";

export const getUsers = createServerFn({ method: "GET" }).handler(async () => {
  const qb = getTaylorDB();

  return qb
    .selectFrom("users")
    .select(["id", "name", "email"])
    .execute();
});

export const createUser = createServerFn({ method: "POST" })
  .inputValidator(z.object({ name: z.string().min(1), email: z.string().email() }))
  .handler(async ({ data }) => {
    const qb = getTaylorDB();

    return qb
      .insertInto("users")
      .values(data)
      .returning(["id", "name", "email"])
      .executeTakeFirst();
  });

Example route loader:

// src/routes/users.tsx
import { createFileRoute } from "@tanstack/react-router";
import { getUsers } from "@/server/users.functions";

export const Route = createFileRoute("/users")({
  loader: () => getUsers(),
  component: UsersPage,
});

function UsersPage() {
  const users = Route.useLoaderData();
  return <pre>{JSON.stringify(users, null, 2)}</pre>;
}

Server Routes

Use server routes when you need the raw Request object, a plain JSON endpoint, webhooks, or multipart form parsing:

// src/routes/api/users.ts
import { createFileRoute } from "@tanstack/react-router";
import { getTaylorDB } from "@/server/taylordb";

export const Route = createFileRoute("/api/users")({
  server: {
    handlers: {
      GET: async () => {
        const qb = getTaylorDB();
        const users = await qb.selectFrom("users").select(["id", "name"]).execute();
        return Response.json(users);
      },
      POST: async ({ request }) => {
        const formData = await request.formData();
        const qb = getTaylorDB();
        const file = formData.get("avatar");

        const attachments =
          file instanceof File
            ? await qb.uploadAttachments([{ file, name: file.name }])
            : [];

        return Response.json({ uploaded: attachments.length });
      },
    },
  },
});

Environment Variables

TaylorDB server-side code expects:

  • TAYLORDB_BASE_URL
  • TAYLORDB_SERVER_ID

The TaylorDB login flow must set an HttpOnly app_access_token cookie. Server functions and server routes read this cookie on each request.

Adding shadcn/ui Components

pnpm dlx shadcn@latest add button card input label textarea alert tabs select dropdown-menu

Do not add "use client" directives to app files. TanStack Start is not Next.js. If the shadcn registry inserts "use client", remove it from files under src/.

Documentation

License

MIT

TaylorDB Full-Stack Template

A production-ready template for building modern, type-safe web applications with TaylorDB. Designed for AI-assisted development with comprehensive documentation and best practices built-in.

🎯 What This Template Provides

  • Full-Stack Setup: React frontend + Node.js backend in a monorepo
  • Type Safety: End-to-end TypeScript from database to UI
  • Modern UI: shadcn/ui components with Tailwind CSS
  • Type-Safe API: tRPC for seamless client-server communication
  • TaylorDB Integration: Query builder with generated types
  • AI-Ready: Comprehensive documentation for AI-assisted development

πŸš€ Quick Start

1. Install Dependencies

pnpm install

πŸ“ Project Structure

taylordb-fullstack-template/
β”œβ”€β”€ apps/
β”‚   β”œβ”€β”€ client/                 # React frontend (Vite)
β”‚   β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”‚   β”œβ”€β”€ components/ui/  # shadcn/ui components
β”‚   β”‚   β”‚   β”œβ”€β”€ pages/          # Route pages
β”‚   β”‚   β”‚   β”œβ”€β”€ lib/            # Utilities & tRPC client
β”‚   β”‚   β”‚   └── index.css       # Design tokens
β”‚   β”‚   └── package.json
β”‚   β”‚
β”‚   └── server/                 # Node.js backend
β”‚       β”œβ”€β”€ taylordb/
β”‚       β”‚   β”œβ”€β”€ types.ts        # Generated schema types
β”‚       β”‚   └── query-builder.ts # Database operations
β”‚       β”œβ”€β”€ router.ts           # tRPC API routes
β”‚       └── package.json
β”‚
β”œβ”€β”€ docs/                       # Comprehensive guides
β”‚   β”œβ”€β”€ TAYLORDB_QUERY_REFERENCE.md
β”‚   └── SHADCN_COMPONENTS_GUIDE.md
β”‚
β”œβ”€β”€ AGENTS.md                   # AI agent instructions
└── taylordb.yml                # Deployment config

πŸ“š Documentation

This template includes comprehensive documentation for both human and AI developers:

For AI Agents

  • AGENTS.md: Complete AI agent instructions
    • Development workflow (Planning β†’ Execution β†’ Verification)
    • Design guidelines for modern UIs
    • Code organization best practices
    • Type safety patterns
    • Example implementations

For Developers


🎨 Tech Stack

Frontend

  • React 19 with TypeScript
  • Vite 7 for fast builds
  • TailwindCSS 4 for styling
  • shadcn/ui for UI components
  • React Router v6 for routing
  • tRPC React Query for API calls

Backend

  • Node.js with TypeScript
  • Express 5 web server
  • tRPC 11 for type-safe APIs
  • Zod for validation
  • TaylorDB Query Builder for database

🎯 Key Features

βœ… Full Type Safety

// Backend defines the API
export const appRouter = router({
  users: {
    getById: publicProcedure
      .input(z.object({ id: z.number() }))
      .query(async ({ input }) => { ... }),
  },
});

// Frontend gets full autocomplete
const { data: user } = trpc.users.getById.useQuery({ id: 1 });
//    ^? User | undefined (fully typed!)

βœ… Modern UI Components

All components from shadcn/ui with:

  • Full dark mode support
  • Responsive design
  • Accessible by default
  • Customizable with Tailwind

βœ… Database Integration

Type-safe queries with TaylorDB:

// Auto-generated types from your schema
export async function getAllUsers() {
  return await queryBuilder
    .selectFrom("users")
    .select(["id", "name", "email"])
    .execute();
}

πŸ€– AI-Assisted Development

This template is optimized for AI-assisted development:

  1. Read AGENTS.md: Comprehensive instructions for AI agents
  2. Follow the workflow: Planning β†’ Execution β†’ Verification
  3. Use type safety: All examples use strict TypeScript
  4. Reference docs: Query patterns, component examples, best practices

The AI agent will:

  • Understand your TaylorDB schema
  • Design appropriate color schemes
  • Build type-safe CRUD operations
  • Create modern, responsive UIs
  • Follow best practices automatically

🚒 Deployment

This template is designed to deploy to TaylorDB's platform using the included taylordb.yml configuration.

Environment Variables Required:

  • TAYLORDB_BASE_URL
  • TAYLORDB_SERVER_ID

πŸ“– Usage Examples

1. Add a New Feature

  1. Create database functions in apps/server/taylordb/query-builder.ts
  2. Expose via tRPC in apps/server/router.ts
  3. Build UI in apps/client/src/pages/
  4. Add route in apps/client/src/main.tsx

2. Add shadcn/ui Component

pnpm dlx shadcn@latest add <component-name>

Example:

pnpm dlx shadcn@latest add table dialog toast

3. Customize Design

Edit apps/client/src/index.css to change colors, fonts, and spacing.


πŸ”— Resources


πŸ“„ License

MIT - Use freely for any project!


Built for modern, type-safe full-stack development with AI assistance ✨

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages