Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/Jason-AML/MonzaSport-Nextjs/llms.txt

Use this file to discover all available pages before exploring further.

Monza Motors exposes vehicle data through two service modules — a server-side module (collections.js) and a client-side module (collectionClient.js). Both query the Supabase vehiculos table but use different Supabase clients appropriate for their execution context. The server module uses @/lib/server, which builds a createServerClient from @supabase/ssr with cookie access via next/headers. The client module uses @/lib/client, which builds a createBrowserClient safe for use in the browser.

Server-Side Services

File: src/services/collections.js This module is intended for use in Server Components and API route handlers. It imports the async createClient from @/lib/server, which reads cookies from next/headers and cannot be used in client-side code.

getCollections() — server

Fetches all rows from the vehiculos table using the server Supabase client.
import { getCollections } from '@/services/collections';

// Use inside a Server Component or API route handler
const vehicles = await getCollections();
// Returns: Vehicle[]
This function accepts no parameters. It returns every record in the vehiculos table as an array. It is used inside the /api/chat route handler to build the Groq AI system prompt with the full vehicle catalog.
BehaviorDetail
ParametersNone
ReturnsVehicle[] — all rows from vehiculos
ThrowsError with Supabase’s error.message if the query fails

Client-Side Services

File: src/services/collectionClient.js This module is designed for use inside 'use client' components and custom hooks. It uses createBrowserClient from @supabase/ssr via @/lib/client, which relies only on NEXT_PUBLIC_* environment variables and is safe to run in the browser. Functions in this module are compatible with React Query’s useQuery and React’s cache() API.

getCollections() — client

Fetches all rows from the vehiculos table using the browser Supabase client.
import { getCollections } from '@/services/collectionClient';

const vehicles = await getCollections();
// Returns: Vehicle[]
This is the client-side equivalent of the server getCollections(). It is used with React Query’s useQuery inside the CollectionView component to drive the main vehicle listing page.
BehaviorDetail
ParametersNone
ReturnsVehicle[] — all rows from vehiculos
ThrowsError with Supabase’s error.message if the query fails

getCollectionById(id)

Fetches a single vehicle record by its UUID, including its related manufacturer (fabricas) and storage (stored) data via Supabase’s relational select syntax.
import { getCollectionById } from '@/services/collectionClient';

const vehicle = await getCollectionById('uuid-here');
// Returns: Vehicle & { fabricas: Fabrica, stored: Stored }
id
string
required
The UUID of the vehicle in the vehiculos table. Must correspond to an existing row; if no match is found Supabase returns an error and the function throws.
This function is wrapped in React’s cache(), which deduplicates calls with the same id within a single server render tree. The underlying Supabase query uses .select('*, fabricas(*), stored(*)') and .single() to return one fully-joined record.
BehaviorDetail
ReturnsVehicle & { fabricas: Fabrica, stored: Stored } — single joined record
DeduplicationWrapped in React cache() — repeated calls with the same id within one render are resolved once
ThrowsError with Supabase’s error.message if the query fails or no row is found

getCollectionByYear(year)

Filters the vehiculos table by the anio (model year) column and returns all matching vehicles.
import { getCollectionByYear } from '@/services/collectionClient';

const vehicles = await getCollectionByYear(2024);
// Returns: Vehicle[]
year
number
required
The model year to filter by. Maps directly to the anio column in the vehiculos table. Pass a four-digit integer (e.g. 2024).
This function uses a Supabase .eq('anio', year) filter. If no vehicles match the specified year, an empty array is returned rather than an error.
BehaviorDetail
ReturnsVehicle[] — all vehicles whose anio column matches year
Empty resultReturns [] when no vehicles match — does not throw
ThrowsError with Supabase’s error.message if the query itself fails

getFabricas()

Fetches only the fabricante (manufacturer name) column from the fabricas table. Useful for populating filter dropdowns or brand navigation without loading full vehicle records.
import { getFabricas } from '@/services/collectionClient';

const manufacturers = await getFabricas();
// Returns: Array<{ fabricante: string }>
BehaviorDetail
ParametersNone
ReturnsArray<{ fabricante: string }> — one object per row in fabricas
ThrowsError with Supabase’s error.message if the query fails

Which Module to Use?

Server Components and Route Handlers (page.js, layout.js, route.js): import from @/services/collections.Client Components and custom hooks (files with 'use client' at the top): import from @/services/collectionClient.Never import @/services/collections inside a 'use client' component. That module relies on the server Supabase client, which calls cookies() from next/headers — a Next.js API that is only available during server-side rendering and is not accessible in the browser.
ContextImport
page.js (Server Component)@/services/collections
layout.js (Server Component)@/services/collections
route.js (API Route Handler)@/services/collections
'use client' component@/services/collectionClient
Custom hook (e.g. with useQuery)@/services/collectionClient

Build docs developers (and LLMs) love