Quick guide to where everything is and what it does.
Brathroom_app/
β
βββ π Configuration Files
β βββ package.json # Dependencies and scripts
β βββ next.config.js # Next.js config
β βββ tailwind.config.js # Tailwind CSS config
β βββ postcss.config.js # PostCSS (needed for Tailwind)
β βββ .env.local.example # Template for environment variables
β βββ .gitignore # Files to ignore in git
β
βββ π Documentation
β βββ README.md # Main documentation (you are here)
β βββ SETUP.md # Step-by-step setup guide
β βββ CODE-REFERENCE.md # This file
β βββ supabase-schema.sql # Database schema (run in Supabase)
β
βββ π¨ Frontend (app/)
β βββ layout.js # Root layout for all pages
β βββ globals.css # Global CSS (Tailwind imports)
β βββ page.js # Home page (/)
β βββ add/page.js # Add bathroom page (/add)
β βββ bathroom/[id]/
β βββ page.js # Bathroom detail (/bathroom/123)
β βββ review/page.js # Add review (/bathroom/123/review)
β
βββ π§© Components (components/)
β βββ Map.js # Google Maps component
β
βββ π οΈ Utilities (lib/)
βββ supabase.js # Supabase client
βββ utils.js # Helper functions
What it does:
- Shows map with bathroom pins
- Lists all bathrooms
- Search and filter functionality
- Sorts by distance if location enabled
Key parts:
fetchBathrooms() // Gets all bathrooms from Supabase
filteredBathrooms // Filters by search + accessibility
calculateDistance() // Sorts by distance from userWhat it does:
- Shows bathroom info and features
- Displays average ratings
- Lists all reviews
Key parts:
fetchBathroom() // Gets single bathroom by ID
fetchReviews() // Gets all reviews for bathroom
averages // Calculates avg ratings client-sideWhat it does:
- Form with 3 sliders (cleanliness, accessibility, privacy)
- Optional comment
- Submits anonymous review
Key parts:
getDeviceId() // Gets/creates device ID from localStorage
hashDeviceId() // Hashes device ID for privacy
supabase.insert() // Saves review to databaseWhat it does:
- Form to add new bathroom
- Click map to place pin
- Accessibility checkboxes
Key parts:
AddBathroomMap // Map component with click handler
handleLocationSelect() // Captures lat/lng from map click
supabase.insert() // Saves bathroom to databaseWhat it does:
- Shows Google Map
- Places markers for bathrooms
- Shows user location (blue dot)
- Markers are clickable
Key parts:
Wrapper // Loads Google Maps API
new google.maps.Map() // Creates map
new google.maps.Marker() // Creates markers
marker.addListener() // Makes markers clickableWhat it does:
- Creates Supabase client
- Used throughout app for database queries
Usage:
import { supabase } from '@/lib/supabase'
// SELECT query
const { data } = await supabase
.from('bathrooms')
.select('*')
// INSERT query
const { error } = await supabase
.from('reviews')
.insert({ ...data })What it does:
- Device ID management (anonymous identity)
- Distance calculation (Haversine formula)
Functions:
getDeviceId()- Get/create device UUIDhashDeviceId()- SHA-256 hash for privacycalculateDistance()- Calculate km between two points
User clicks map
β
lat/lng captured
β
User fills form
β
Submit β supabase.insert('bathrooms')
β
Redirect to home
β
New bathroom appears on map
User slides ratings
β
User types comment (optional)
β
getDeviceId() from localStorage
β
hashDeviceId() for privacy
β
Submit β supabase.insert('reviews')
β
Redirect to bathroom detail
β
Review appears in list
Page loads
β
fetchBathrooms() β supabase.select()
β
Get user location (if allowed)
β
Filter by search + accessibility
β
Sort by distance
β
Display on map + list
All styling uses Tailwind CSS utility classes:
// Example classes used:
className="bg-blue-600" // Blue background
className="text-white" // White text
className="p-4" // Padding
className="rounded-lg" // Rounded corners
className="shadow" // Drop shadow
className="hover:bg-blue-700" // Hover effect
className="flex gap-2" // Flexbox with gapMain colors:
- Blue (
bg-blue-600) - Primary actions, header - Green (
bg-green-600) - Add bathroom - Gray (
bg-gray-50) - Background
How it works:
- First visit β generate UUID β save to localStorage
- On review submit β hash UUID with SHA-256
- Store only hash in database (never raw UUID)
- Same device = same hash = can't spam
Why this works:
- β Anonymous (no accounts)
- β Privacy-friendly (hash only)
- β Anti-spam (one device = one hash)
- β Client-side (no server code needed)
How it works:
@googlemaps/react-wrapperloads Google Maps API- Create map with
new google.maps.Map() - Add markers with
new google.maps.Marker() - Listen for clicks with
map.addListener('click')
In this app:
- Home page: Shows all bathroom pins (read-only)
- Add page: Click to place new pin (interactive)
All queries use Supabase client (PostgreSQL):
// Get all bathrooms
await supabase.from('bathrooms').select('*')
// Get single bathroom
await supabase.from('bathrooms').select('*').eq('id', id).single()
// Get reviews for bathroom
await supabase.from('reviews').select('*').eq('bathroom_id', id)
// Insert bathroom
await supabase.from('bathrooms').insert({ name, lat, lng, ... })
// Insert review
await supabase.from('reviews').insert({ bathroom_id, cleanliness, ... })What's fast:
- β Static map rendering
- β Client-side filtering
- β Distance calculation (simple math)
What could be optimized later:
- β° Compute averages in DB instead of client
- β° Use Supabase PostGIS for geo queries
- β° Add pagination for large datasets
- β° Cache bathroom data
For MVP: Current approach is simple and works great!
Open browser console (F12) while on any page:
// Test Supabase connection
const { data } = await supabase.from('bathrooms').select('*')
console.log(data)localStorage.getItem('deviceId') // Should show UUIDnavigator.geolocation.getCurrentPosition(
pos => console.log(pos.coords)
)Edit components/Map.js:
center: { lat: 36.9914, lng: -122.0609 }, // UCSC coordsEdit Tailwind classes throughout files:
bg-blue-600 β bg-purple-600- Add column to
bathroomstable in Supabase - Add checkbox in
app/add/page.js - Add badge display in
app/page.jsandapp/bathroom/[id]/page.js
- Set up Supabase Storage bucket
- Add file input in forms
- Upload with
supabase.storage.upload() - Store URL in database
-
Browser Console (F12 β Console tab)
- JavaScript errors
- Network requests
- Supabase errors
-
Network Tab (F12 β Network tab)
- Failed API calls
- Supabase requests
-
Supabase Dashboard
- Table Editor (verify data)
- Logs (see queries)
-
Terminal
- Next.js build errors
- Missing dependencies
Need more help? Check SETUP.md or README.md!