Monza Motors exposes vehicle data through two service modules — a server-side module (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.
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.
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.| Behavior | Detail |
|---|---|
| Parameters | None |
| Returns | Vehicle[] — all rows from vehiculos |
| Throws | Error 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.
getCollections(). It is used with React Query’s useQuery inside the CollectionView component to drive the main vehicle listing page.
| Behavior | Detail |
|---|---|
| Parameters | None |
| Returns | Vehicle[] — all rows from vehiculos |
| Throws | Error 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.
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.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.
| Behavior | Detail |
|---|---|
| Returns | Vehicle & { fabricas: Fabrica, stored: Stored } — single joined record |
| Deduplication | Wrapped in React cache() — repeated calls with the same id within one render are resolved once |
| Throws | Error 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.
The model year to filter by. Maps directly to the
anio column in the vehiculos table. Pass a four-digit integer (e.g. 2024)..eq('anio', year) filter. If no vehicles match the specified year, an empty array is returned rather than an error.
| Behavior | Detail |
|---|---|
| Returns | Vehicle[] — all vehicles whose anio column matches year |
| Empty result | Returns [] when no vehicles match — does not throw |
| Throws | Error 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.
| Behavior | Detail |
|---|---|
| Parameters | None |
| Returns | Array<{ fabricante: string }> — one object per row in fabricas |
| Throws | Error 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.| Context | Import |
|---|---|
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 |