Use Case

Internal product APIs with embedded ClickHouse analytics

This is the migration path for teams that already have a backend and do not want to split it into a separate analytics service on day one. Keep the existing routes, move the query logic onto a shared path, and expose more only when it earns its place.

Contract impact

Zero endpoint breakage

Execution model

In-process + routed

Migration style

Endpoint-by-endpoint

Keep route contracts stable

Existing consumers do not need to notice the migration while you move analytics logic behind an internal path.

Use one query definition

Let handlers call `api.run(...)` directly and expose the same definition over HTTP only where it is genuinely useful.

Scale rollout safely

Start with one endpoint or one response shape, see what sticks, then widen the internal surface deliberately.

Implementation flow

Step 1

Mount internal routes

Mount the analytics handler beside the routes you already run instead of restructuring the whole backend first.

Step 2

Compose in endpoints

Pull analytics into existing business responses without turning every route into bespoke query code.

Step 3

Reuse query logic

Keep one typed source of truth whether the query is called directly or exposed under an internal path.

Works with your existing routes

The route tree stays yours. Add the analytics surface where it fits instead of adopting a separate service boundary immediately.

routes.ts
import { createFetchHandler } from '@hypequery/serve';

const hypequeryHandler = createFetchHandler(api.handler);
app.route('/api/products', products);
app.all('/internal/hq/*', (c) => hypequeryHandler(c.req.raw));

Compose analytics directly in business endpoints

Use `api.run(...)` when a product response needs analytics context but does not need another network hop inside the same backend.

products.ts
const productId = c.req.param('productId').toUpperCase();
const analytics = await api.run('productOverview', {
  productId,
});

return c.json({ productId, analytics });

Define once, reuse everywhere

The same definition can back an internal route and an in-process call, which is the whole point of this adoption path.

analytics/api.ts
const { query, serve } = initServe({
  context: () => ({ db }),
});

const topProducts = query({
  output: z.array(z.object({
    product_id: z.string(),
    avg_order_value: z.number(),
  })),
  query: ({ ctx }) =>
    ctx.db
      .table('analytics.orders')
      .select(['payment_type as product_id'])
      .count('trip_id', 'orders')
      .avg('order_total', 'avg_order_value')
      .groupBy(['payment_type'])
      .execute(),
});

export const api = serve({
  basePath: '/internal/hq',
  queries: { topProducts },
});

Ready to implement

Use this as your first production migration path

  • Keep existing consumer contracts intact
  • Move the query logic into one typed definition
  • Expose more surface area only when the team actually needs it

Get early access to hypequery cloud.

Cloud hosts the same model you run in your backend, with a managed API and MCP server, versions, and rollback. We're letting teams in a few at a time. Join the waitlist and we'll reach out when your project can go live.

How do you want to build your analytics layer? (Optional)
What features do you most need? (Optional)

Pick as many as you like.

Only your email is required. All other questions are optional.