Flight Kit

Flight Kit — reference app

A real agency solution, assembled only from fk-ui composites. Individual parts (trip-type tabs, airport pair field, offer card, filter panel) are internal to the composites and are never mounted directly.

Everything below can be yours: four routes, one proxy file and one stylesheet import. The four stage pages then carry their own guides.

Deploy a booking site in four routes

The whole setup, in the order you would do it — then the four routes themselves, and an honest list of what you do not have to write.

  1. Know what you are assembling

    Four composites, one per stage of the booking flow, and one shared component for the wait. That is the whole public surface — the trip-type tabs, the airport field, the offer card, the filter panel, the traveller form, the timeline and the tables are all internal to the composite that uses them, and are never mounted directly. You are not assembling a component library; you are wiring four stages and choosing four routes.

    The stages hand off through the fk-ui store rather than through props, which is the thing that makes an app this small possible: the form publishes a search, the list is subscribed to it, the list writes a selection, the checkout reads it. No stage needs to know the next one exists.

  2. Import the stylesheet once

    One line, and it is not optional: it pulls in Tailwind, the design tokens, the fk-* utility vocabulary, and the @source directive that stops Tailwind purging the classes used inside the library. Leaving it out is the most common way a Tailwind component library renders unstyled.

    app/globals.css
    /* once, in your global stylesheet */
    @import '@sheriph/fk-ui/tailwind.css';
  3. Keep the key on your server, and copy the proxy

    This is the part people brace for, and it is the smallest part of the build. There is no API client to write, no auth header to remember, no error handling to get right: you set three values, copy one file, and every composite on every route can talk to the API.

    That file is a proxy on your own origin. Composites call /api/flight-kit/… — the client's default base, which is why no component ever needs a key or a URL — and your route handler attaches the agency key and forwards upstream. The extra hop is entirely about that key: a key shipped to the browser is a key anyone can read, and then book on the agency's account with.

    Every path in this guide is relative to your Next.js project root — the folder holding next.config — not to the top of the repository you are reading this in. In this reference app that root is apps/demo/, so the file below is really at apps/demo/src/app/api/flight-kit/[...path]/route.ts when you go looking for it locally.

    Create app/api/flight-kit/[...path]/route.ts in your app, and paste the file below into it unchanged — it is written to be copied, and it is the only file in the whole setup that must not be adapted. Two things are worth knowing before you do. The folder really is named [...path], brackets included: that is Next.js's catch-all segment, and it is what lets one file serve every call the composites make. Renaming it to app/api/flight-kit/route.ts compiles, and then 404s everything below the root.

    And nothing inside the file needs adapting, which is the part that surprises people. Where it sends requests and which key it sends are the two values you set in .env.local below, which the file already reads. It is shaped this way for three reasons. It passes the upstream status through unchanged, because the client reads that status to decide between offering a retry and showing the server's own message. It reads the response as bytes rather than as text, because the same route also carries carrier logos, and decoding a PNG as UTF-8 corrupts it silently. And it never caches, because these responses are booking-critical.

    app/api/flight-kit/[...path]/route.ts (whole file)
    import { NextResponse, type NextRequest } from 'next/server';
    /**
    * THE PROXY — the single most important file in this app.
    *
    * The browser never sees the agency API key. Every call from an fk-ui component
    * goes to `/api/flight-kit/...` on this app's own origin; this handler attaches
    * the key server-side and forwards upstream. That is why `fk-ui`'s client
    * defaults its `apiBase` to `/api/flight-kit`.
    *
    * Copy this file verbatim into your own app. Do not move the key client-side,
    * and never give it a NEXT_PUBLIC_ prefix — anything prefixed that way is
    * embedded in the JavaScript your visitors download, so anyone could copy the
    * key and book flights on your account.
    *
    * Reads are public on the server (airports, airlines) and need no key, but
    * forwarding it uniformly costs nothing and keeps this file simple.
    */
    export const runtime = 'nodejs';
    const API_BASE = (process.env.FLIGHT_KIT_API_URL ?? 'http://localhost:3000/api').replace(/\/$/, '');
    const API_KEY = process.env.FLIGHT_KIT_API_KEY ?? '';
    async function proxy(
    req: NextRequest,
    { params }: { params: Promise<{ path: string[] }> },
    ): Promise<NextResponse> {
    const { path } = await params;
    const target = `${API_BASE}/${path.join('/')}${req.nextUrl.search}`;
    const hasBody = req.method !== 'GET' && req.method !== 'HEAD';
    let upstream: Response;
    try {
    upstream = await fetch(target, {
    method: req.method,
    headers: {
    Accept: 'application/json',
    ...(hasBody ? { 'Content-Type': 'application/json' } : {}),
    // The key is the real authorisation boundary. It lives here and only here.
    ...(API_KEY ? { Authorization: `Bearer ${API_KEY}` } : {}),
    },
    body: hasBody ? await req.text() : undefined,
    // Never cache booking-critical responses.
    cache: 'no-store',
    });
    } catch (err) {
    return NextResponse.json(
    { error: `Upstream unreachable: ${(err as Error).message}` },
    { status: 502 },
    );
    }
    // Pass the status through unchanged — the fk-ui client reads it to decide
    // between "retry" and "show the user the server's own message".
    //
    // `arrayBuffer()` rather than `text()`: this proxy also carries carrier logos
    // (`/api/flight-kit/assets/airlines/64/BA.png`). `text()` decodes the body as
    // UTF-8, which silently corrupts every byte of a PNG — you get a 200 response
    // with an image that cannot be decoded, and no error anywhere to explain it.
    //
    // Cache-Control is forwarded because the images are static; without it the
    // browser would re-fetch all of them through this function on every render.
    const contentType = upstream.headers.get('content-type') ?? 'application/json';
    const cacheControl = upstream.headers.get('cache-control');
    return new NextResponse(await upstream.arrayBuffer(), {
    status: upstream.status,
    headers: {
    'Content-Type': contentType,
    ...(cacheControl ? { 'Cache-Control': cacheControl } : {}),
    },
    });
    }
    export const GET = proxy;
    export const POST = proxy;

    The two secrets come from onboarding, not from anything you invent. Register at the dashboard — dashboard.sheriph.app/login — then confirm the emailed code. The completion screen shows the agencyId and the API key together — the only time the key is displayed, since only its bcrypt hash is stored. If it is lost before you have pasted it anywhere, rotate it under Profile & security; there is no read-back endpoint.

    .env.local
    # .env.local — server-side only.
    #
    # None of these takes a NEXT_PUBLIC_ prefix, and the key must never be given
    # one: anything so prefixed is inlined into the JavaScript your visitors
    # download, where anyone could read it and book on the agency's account.
    FLIGHT_KIT_API_KEY=fk_... # from the completion screen
    FLIGHT_KIT_API_URL=https://api.sheriph.app/api # the platform API
    # Read on the server and passed down as a prop (see the layout below). An
    # identifier, not a secret — but read per request rather than at build time,
    # which is what lets one deployment serve several agencies without a rebuild.
    FLIGHT_KIT_AGENCY_ID=<the agencyId from the same screen>
  4. Wrap the app in the provider, once

    Mount it in the root layout, above every route. The store itself is a module singleton — the provider is what supplies the API client and the query cache, and it is where persisted state is restored, in an effect, never during render.

    Read the agency id on the server and pass it down as a prop, as below. It keeps the id a runtime concern rather than a build-time one, which is what lets one deployment serve more than one agency.

    app/layout.tsx and the two files it needs
    /* ── app/globals.css ───────────────────────────────────────────────────── */
    @import '@sheriph/fk-ui/tailwind.css';
    /* ── app/providers.tsx ─────────────────────────────────────────────────── */
    'use client';
    import type { ReactNode } from 'react';
    import { FlightKitProvider } from '@sheriph/fk-ui/core';
    export function Providers({ children, agencyId }: { children: ReactNode; agencyId: string }) {
    return (
    // A same-origin path: your route handler attaches the API key there, so it
    // never reaches the browser. This is the client's default, and passing it
    // explicitly is how you mount your own.
    <FlightKitProvider agencyId={agencyId} apiBase="/api/flight-kit">
    {children}
    </FlightKitProvider>
    );
    }
    /* ── app/layout.tsx ────────────────────────────────────────────────────── */
    import type { Metadata } from 'next';
    import type { ReactNode } from 'react';
    import { Providers } from './providers';
    import './globals.css';
    /**
    * Read per request, not baked into the build — which is what lets one image
    * serve several agencies. A value read inside a client component is inlined at
    * build time instead, so pointing it at another agency would mean rebuilding.
    */
    export const dynamic = 'force-dynamic';
    export const metadata: Metadata = {
    title: 'Your travel agency',
    };
    const agencyId = process.env.FLIGHT_KIT_AGENCY_ID ?? process.env.NEXT_PUBLIC_AGENCY_ID ?? '';
    export default function RootLayout({ children }: { children: ReactNode }) {
    return (
    <html lang="en">
    <body>
    {/* Mounted once, above every booking stage. */}
    <Providers agencyId={agencyId}>{children}</Providers>
    </body>
    </html>
    );
    }
  5. Four routes, four composites

    This is the entire site. Read it as the answer to “how much code is this?” — the next step is the only part that needs a decision, and step 7 is what you get in return.

    the four routes, whole
    /* ── app/page.tsx — stage 1, the search ────────────────────────────────── */
    'use client';
    import { useRouter } from 'next/navigation';
    import { FlightSearchForm } from '@sheriph/fk-ui/search';
    import { RESULTS_PATH, queryFromCriteria } from '@/lib/search-query';
    export default function SearchPage() {
    const router = useRouter();
    return (
    <FlightSearchForm
    onSearch={(criteria) => router.push(`${RESULTS_PATH}?${queryFromCriteria(criteria)}`)}
    />
    );
    }
    /* ── app/flights/page.tsx — stage 2, the results ───────────────────────── */
    'use client';
    import { useRouter } from 'next/navigation';
    import { FlightResultsList } from '@sheriph/fk-ui/results';
    import { FlightSearchSummary } from '@sheriph/fk-ui/search';
    import { RESULTS_PATH, queryFromCriteria } from '@/lib/search-query';
    export default function ResultsPage() {
    const router = useRouter();
    return (
    <>
    <FlightSearchSummary
    onSearch={(criteria) =>
    // replace, not push: a search is not a document.
    router.replace(`${RESULTS_PATH}?${queryFromCriteria(criteria)}`, { scroll: false })
    }
    />
    <FlightResultsList onBook={() => router.push('/checkout')} />
    </>
    );
    }
    /* ── app/checkout/page.tsx — stage 3, the checkout ─────────────────────── */
    'use client';
    import { BookingFlow } from '@sheriph/fk-ui/checkout';
    import { bookingConfirmationHref } from '@sheriph/fk-ui/confirmation';
    export default function CheckoutPage() {
    return (
    <BookingFlow
    resultsHref="/flights"
    confirmationHref={(ref) => bookingConfirmationHref(ref)}
    />
    );
    }
    /* ── app/booking-confirmation/page.tsx — stage 4, the receipt ──────────── */
    'use client';
    import { Suspense } from 'react';
    import { useSearchParams } from 'next/navigation';
    import { BOOKING_REF_PARAM, BookingConfirmation } from '@sheriph/fk-ui/confirmation';
    function Confirmation() {
    const reference = useSearchParams().get(BOOKING_REF_PARAM) ?? '';
    return <BookingConfirmation bookingRef={reference} searchHref="/" />;
    }
    export default function ConfirmationPage() {
    return (
    <Suspense fallback={null}>
    <Confirmation />
    </Suspense>
    );
    }
  6. The URL is the one thing you decide

    A composite publishes to the store and reports through a callback; it never navigates and never touches a URL, because the library imports no router at all. So the query string is yours — and it buys two things: a search that survives a refresh on a cold load, and a link a traveller can share or bookmark.

    It is also strictly optional. Skip it — don't write the parameters, don't parse them back — and the flow still works end to end through the store; you only lose shareability and refresh-survival on the results page. /flight-search-form shows the mapping if you want it (about forty lines, in src/lib/search-query.ts here), and /search-result shows how to publish it back on mount without burning a second search.

  7. Brand it with tokens, not with overrides

    Set --fk-color-primary once and the components follow. There is no theme provider to configure, no sx prop, and no reason to restyle anything: if a composite does not look like your brand, the colour is almost always the only thing missing.

    It is not only the accent. Every value in the library — the accent, the text, the hairlines, the surfaces, the three verdicts, the radii and the type scale — is a CSS custom property on :root, so a theme is a reassignment rather than an API to learn. The steps derived from a colour — its hover, its tint, the pale wash behind a verdict — are computed from the colour itself, so setting one variable moves all of them and there is no palette to keep consistent by hand. And because it is only inheritance, a scoped re-theme needs no feature at all: the same declarations on a wrapper element re-theme that subtree and nothing else, which is how one app runs an agency's portal in the agency's own colours.

    Two things the tokens cannot do for you. A dark theme declares its own accent base, so an override meant for both has to be written in both places. And the PDF and the email are rendered by the server, which never sees your stylesheet — of everything above, only the brand colour travels, inside the booking payload.

    One breakpoint, fk-mobile (768px), mobile-first — a layout difference is a class change inside the same component, never a second one to mount. And an agency that sets a colour in its own dashboard wins over your theme, on the page and on the printed ticket, because they chose it deliberately.

    globals.css — one colour, derived everywhere
    /* ── globals.css — your brand, as tokens ───────────────────────────────── */
    /* Every value in the library is a custom property on :root, so a theme is a
    * reassignment rather than a configuration API: no provider, no theme object,
    * nothing to keep in sync. Start with the accent and add the rest only if you
    * need them. */
    :root {
    --fk-color-primary: #0b4f9e; /* buttons, links, focus rings, selected state */
    --fk-text: #14181f; /* body copy */
    --fk-border: #d7dbe0; /* hairlines */
    --fk-surface: #ffffff; /* the page the composites sit on */
    /* The three verdicts. Each one's pale wash follows its own colour. */
    --fk-color-error: #b3261e;
    --fk-color-success: #2f7d5b;
    --fk-color-warning: #d47238;
    }
    /* ── What you do not have to set ───────────────────────────────────────── */
    /* The derived steps — `-hover`, `-soft`, `-strong` — are computed from the
    * colour they belong to, so one assignment moves the whole ramp and there is no
    * palette to keep consistent. That is deliberate: three hand-picked blues are how
    * a brand ends up with buttons that hover in somebody else's blue. The same is
    * true of `--fk-color-brand`, the colour a confirmation is *printed* in — the
    * masthead, the section rules, the table headers, the total. It defaults to the
    * primary, so set it only if the document should differ from the app. */
    /* ── One colour per agency, without a deploy ───────────────────────────── */
    /* An agency that sets a colour in its own dashboard beats your theme, on the page
    * and on the printed ticket, because it chose that colour deliberately. There is
    * nothing to reconcile in code:
    *
    * <BookingConfirmation bookingRef={pnr} primaryColor="#0b4f9e" />
    */
  8. What you did not write

    The claim is less code, so here is the itemised invoice. Across the four stages the composites already own: the airport lookup and the form's validation; the search request itself — issuing it, aborting a superseded one so a slow first response cannot overwrite a faster second, and the blocking first-load surface over skeletons; the offer card, fare rules, sorting, filtering with chips and a mobile sheet, pagination, and the six distinct states of a results list (idle, loading, reloading, empty, error, and “your filters excluded everything”); the traveller form with its per-field errors and focus management; the pricing — the agency's markup and markdown applied server-side, so the fare quoted and the fare booked cannot drift; the commit that returns a real locator; the retrieval, the share dialog, the calendar file and the PDF ticket; and the accessibility of all of it — focus traps, live regions, real tables, keyboard paths.

    None of that is configuration you switch on. It is what happens when you mount the four routes above.

Go deeper, one stage at a time

Each of the four stage pages carries its own implementation guide — steps, the code to paste, the props table, and the traps worth knowing before you mount it.

Every page in this app

The composites mounted in the roles they are actually for, in the order a traveller meets them.