# alivinshiva/autovista architecture

> Architecture diagram of the GitHub repository alivinshiva/autovista, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/alivinshiva/autovista
- Repository: https://github.com/alivinshiva/autovista

## Overview

##### 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)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client: Browser / React App"
        direction TB
        Home["Home Page"]:::frontend
        Gallery["Gallery Page"]:::frontend
        CustIndex["Customize Page"]:::frontend
        CustCar["Customize [car] Page"]:::frontend
        ViewConf["View [carId] Page"]:::frontend
        SignIn["Sign-in Page"]:::frontend
        SignUp["Sign-up Page"]:::frontend
        subgraph "Shared UI Components"
            direction TB
            CarCustComp["Car Customizer Canvas"]:::ui
            CarViewComp["3D Viewer Component"]:::ui
            ColorPicker["Color Picker Control"]:::ui
            AccessorySel["Accessory Selector"]:::ui
            GalleryCard["Gallery Card"]:::ui
            GalleryList["Gallery List"]:::ui
            ModelUploader["Model Uploader"]:::ui
            GarageBG["Garage Background Wrapper"]:::ui
            ThemeProv["Theme Provider"]:::ui
            ThemeToggle["Theme Toggle"]:::ui
        end
        LocalStorage[(Local Storage)]:::storage
    end

    %% Server Layer
    subgraph "Server: Next.js"
        direction TB
        subgraph "App Router"
            direction TB
            Layout["Layout & Global Styles"]:::server
            subgraph "API Endpoints (App)"
                direction TB
                GetGLB["GET /api/getGlbFiles"]:::api
                CarSave["POST /api/car/save"]:::api
                SaveConfig["POST /api/save-config"]:::api
                Hello["GET /api/hello"]:::api
            end
        end
        subgraph "Pages Router API"
            direction TB
            GetGallery["GET /api/getGallery"]:::api
            SaveCarLegacy["POST /api/saveCar"]:::api
        end
        Middleware["Middleware (Auth/Routing)"]:::middleware
    end

    %% Data Layer
    subgraph "Database Layer"
        direction TB
        MongoDB[(MongoDB)]:::database
        LibMongo["lib/mongodb.ts"]:::code
        Utils["lib/utils.ts"]:::code
        DefaultGallery["lib/getDefaultGalleryData.ts"]:::code
        CarConfigModel["models/CarConfig.ts"]:::code
        DefaultCarModel["models/DefaultCar.ts"]:::code
        UserModel["models/User.ts"]:::code
    end

    %% Static Assets
    subgraph "Static Asset Store"
        direction TB
        GLBStore["public/assets/3d/*.glb"]:::asset
        ImageStore["public/assets/image/"]:::asset
    end

    %% Scripts
    subgraph "Offline Scripts"
        direction TB
        SeedScript["scripts/saveDefaultCars.ts"]:::script
    end

    %% Client to API
    Home -->|uses UI| CarCustComp
    CustIndex -->|renders| CarCustComp
    CustCar -->|renders| CarCustComp
    CustCar -->|calls POST /api/car/save| CarSave
    ViewConf -->|calls GET /api/save-config| SaveConfig
    Gallery -->|calls GET /api/getGlbFiles| GetGLB
    Gallery -->|calls GET /api/getGallery| GetGallery
    SignIn -->|calls auth endpoints| Middleware
    SignUp -->|calls auth endpoints| Middleware

    %% API flow
    CarSave -->|passes through| Middleware
    SaveConfig -->|passes through| Middleware
    GetGLB -->|passes through| Middleware
    GetGallery -->|passes through| Middleware
    SaveCarLegacy -->|passes through| Middleware

    Middleware -->|DB operations| LibMongo
    LibMongo -->|connects to| MongoDB
    Utils -->|helper| CarSave
    DefaultGallery -->|helper| GetGallery

    %% Static assets
    CarCustComp -->|fetches| GLBStore
    CarViewComp -->|loads| GLBStore
    CarCustComp -->|loads textures| ImageStore

    %% Local storage
    CarCustComp -.->|fallback save| LocalStorage

    %% Scripts to DB
    SeedScript -->|seeds| MongoDB

    %% Click events
    click Layout "https://github.com/alivinshiva/autovista/blob/main/app/layout.tsx"
    click Home "https://github.com/alivinshiva/autovista/blob/main/app/page.tsx"
    click Gallery "https://github.com/alivinshiva/autovista/blob/main/app/gallery/page.tsx"
    click CustIndex "https://github.com/alivinshiva/autovista/blob/main/app/customize/page.tsx"
    click CustCar "https://github.com/alivinshiva/autovista/blob/main/app/customize/[car]/page.tsx"
    click ViewConf "https://github.com/alivinshiva/autovista/blob/main/app/view/[carId]/page.tsx"
    click SignIn "https://github.com/alivinshiva/autovista/blob/main/app/sign-in/[[...sign-in]]/page.tsx"
    click SignUp "https://github.com/alivinshiva/autovista/blob/main/app/sign-up/[[...sign-up]]/page.tsx"
    click GetGLB "https://github.com/alivinshiva/autovista/blob/main/app/api/getGlbFiles/route.ts"
    click CarSave "https://github.com/alivinshiva/autovista/blob/main/app/api/car/save/route.ts"
    click SaveConfig "https://github.com/alivinshiva/autovista/blob/main/app/api/save-config/route.ts"
    click Hello "https://github.com/alivinshiva/autovista/blob/main/app/api/hello/route.ts"
    click GetGallery "https://github.com/alivinshiva/autovista/blob/main/pages/api/getGallery.ts"
    click SaveCarLegacy "https://github.com/alivinshiva/autovista/blob/main/pages/api/saveCar.ts"
    click CarCustComp "https://github.com/alivinshiva/autovista/blob/main/components/car-customizer.tsx"
    click CarViewComp "https://github.com/alivinshiva/autovista/blob/main/components/carViewer.tsx"
    click ColorPicker "https://github.com/alivinshiva/autovista/blob/main/components/color-picker.tsx"
    click AccessorySel "https://github.com/alivinshiva/autovista/blob/main/components/accessory-selector.tsx"
    click GalleryCard "https://github.com/alivinshiva/autovista/blob/main/components/GallerCard.tsx"
    click GalleryList "https://github.com/alivinshiva/autovista/blob/main/components/gallery.tsx"
    click ModelUploader "https://github.com/alivinshiva/autovista/blob/main/components/model-uploader.tsx"
    click GarageBG "https://github.com/alivinshiva/autovista/blob/main/components/garage-background.tsx"
    click ThemeProv "https://github.com/alivinshiva/autovista/blob/main/components/theme-provider.tsx"
    click ThemeToggle "https://github.com/alivinshiva/autovista/blob/main/components/theme-toggle.tsx"
    click LibMongo "https://github.com/alivinshiva/autovista/blob/main/lib/mongodb.ts"
    click Utils "https://github.com/alivinshiva/autovista/blob/main/lib/utils.ts"
    click DefaultGallery "https://github.com/alivinshiva/autovista/blob/main/lib/getDefaultGalleryData.ts"
    click CarConfigModel "https://github.com/alivinshiva/autovista/blob/main/models/CarConfig.ts"
    click DefaultCarModel "https://github.com/alivinshiva/autovista/blob/main/models/DefaultCar.ts"
    click UserModel "https://github.com/alivinshiva/autovista/blob/main/models/User.ts"
    click GLBStore "https://github.com/alivinshiva/autovista/tree/main/public/assets/3d/"
    click ImageStore "https://github.com/alivinshiva/autovista/tree/main/public/assets/image/"
    click SeedScript "https://github.com/alivinshiva/autovista/blob/main/scripts/saveDefaultCars.ts"
    click Middleware "https://github.com/alivinshiva/autovista/blob/main/middleware.ts"

    %% Styles
    classDef frontend fill:#E3F2FD,stroke:#1976D2,stroke-width:1px
    classDef ui fill:#FFF8E1,stroke:#F9A825,stroke-width:1px
    classDef server fill:#E8EAF6,stroke:#3F51B5,stroke-width:1px
    classDef api fill:#F3E5F5,stroke:#8E24AA,stroke-width:1px
    classDef middleware fill:#FFECB3,stroke:#FFA000,stroke-width:1px,stroke-dasharray: 5 5
    classDef database fill:#E0F7FA,stroke:#00796B,stroke-width:1px
    classDef code fill:#ECEFF1,stroke:#607D8B,stroke-width:1px
    classDef asset fill:#F1F8E9,stroke:#558B2F,stroke-width:1px
    classDef script fill:#FFF3E0,stroke:#EF6C00,stroke-width:1px
    classDef storage stroke-dasharray: 3 3,stroke:#9E9E9E,fill:none
```
