How alivinshiva/autovista works
Project Type and Purpose
– This is a full-stack web application built on Next.js (App Router + Pages Router).
File Structure & Architectural Clues
• app/ (Next.js App Router)
– page.tsx files for UI routes (/, /gallery, /customize/[car], /view/[carId], /sign-in, /sign-up)
– app/api/** folders define serverless API endpoints (getGlbFiles, car/save, save-config, hello)
– layout.tsx and globals.css define global UI shell and styling
• pages/api/ (legacy Next.js Pages Router)
– additional API endpoints (getGallery, saveCar)
• components/ & components/ui/
– pure React UI components (customizer controls, gallery cards, theme toggle) and a shared UI library (buttons, dialogs, form controls)
• lib/ & models/
– lib/mongodb.ts handles DB connection
– lib/utils.ts and lib/getDefaultGalleryData.ts provide helper functions
– models/*.ts define TypeScript schemas for CarConfig, DefaultCar, User
• public/assets/3d & public/assets/image
– 3D GLB models and textures served as static assets
• scripts/
– saveDefaultCars.ts seeds the database
• middleware.ts
– route protection or shared middleware logic (e.g., authentication checks)
Key Architectural Patterns & Tech Stack
– File-based routing for UI and API handlers (Next.js App Router)
– SSR/ISR and serverless functions for API logic
– React + Three.js (via @react-three/fiber and @react-three/drei) for real-time 3D rendering
– Tailwind CSS for styling and responsive design
– MongoDB as persistent storage, Node.js driver in lib/mongodb.ts
– Local storage fallback for saving temporary configurations
– TypeScript for type safety across components, models, and API
Main Components & Their Interactions
1. Client (Browser)
• UI pages rendered by Next.js (React components, Three.js canvas)
• Local storage read/write for quick saves
2. Next.js Server
• Serves React pages and static assets (/public)
• Hosts API endpoints under /api/* (serverless functions)
• Runs middleware for auth or routing logic
3. Database Layer
• MongoDB cluster accessed via lib/mongodb.ts
• Collections for users, car configurations, default cars
• Scripts for seeding default data (scripts/saveDefaultCars.ts)
4. Static Asset Store
• GLB files and textures under public/assets/3d & /image
• Served directly by Next.js as static files
5. External Services (optional)
• If using NextAuth or other OAuth providers for sign-in/up
• CDN for static asset caching (not shown but recommended in deployment)