Skip to content

vvduth/car-dealer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

65 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš— Meat Motors - Car Dealer Platform

A modern, full-stack car dealership management system built with Next.js 15, featuring advanced inventory management, customer reservations, and comprehensive admin tools.

🌐 Live Demo

Production: https://car-dealer-lake-eight.vercel.app/

πŸ“Έ Screenshots

Homepage & Inventory

Homepage Modern landing page with featured vehicles and search functionality

Vehicle Details

Inventory Inventory section

Admin Dashboard

Admin Dashboard Comprehensive admin panel for inventory and customer management

AI auto-detech car specs

AI auto-detech AI detech specs of the whip by just upload 1 picture

✨ Features

🎯 Core Functionality

πŸ“‹ Advanced Inventory Management

  • Hierarchical Car Taxonomy: Make β†’ Model β†’ Model Variant structure for precise categorization
  • Real-time Search & Filtering: Filter by make, model, price, year, mileage, fuel type, transmission, body type, and more
  • Dynamic Vehicle Listings: Live status updates (LIVE, DRAFT, SOLD)
  • URL-based State Management: Shareable filter links with nuqs integration
  • View Counter: Track vehicle popularity with automated view counting
  • Slug-based URLs: SEO-friendly URLs auto-generated from vehicle details

πŸ–ΌοΈ Professional Image Management

  • AWS S3 Integration: Scalable cloud storage with presigned URLs
  • Drag & Drop Upload: Intuitive multi-image uploader using @dnd-kit
  • Image Sorting: Reorder images with drag-and-drop interface
  • Thumbhash Placeholders: Ultra-fast loading with blur-up effect
  • Main Image Selection: Designate primary vehicle photo
  • Automatic Optimization: Next.js Image component with lazy loading

πŸ“… Smart Reservation System

  • Multi-Step Form: Welcome β†’ Date Selection β†’ Customer Details
  • Calendar Integration: Interactive date picker with date-fns
  • Lead Tracking: Capture customer interest with status lifecycle
  • Email Notifications: Automated alerts via Resend
  • Terms & Conditions: Built-in acceptance workflow
  • Booking Confirmation: Success page with reservation details

πŸ‘₯ Customer Relationship Management

  • Lead Status Pipeline: SUBSCRIBER β†’ INTERESTED β†’ CONTACTED β†’ PURCHASED β†’ COLD
  • Lifecycle Tracking: Full history of status changes with timestamps
  • Customer Profiles: Detailed contact information and booking preferences
  • Vehicle Association: Link customers to specific vehicle interests
  • Search & Filter: Find customers by name, email, status, or vehicle
  • Bulk Actions: Efficient customer management workflows

πŸ” Authentication & Security

πŸ”’ Advanced Authentication Flow

  • NextAuth v5: Latest authentication library with database sessions
  • Custom 2FA Implementation: OTP-based two-factor authentication
  • Challenge System: Secure OTP generation and validation with @/lib/otp
  • Session Management: 30-day sessions with automatic expiration
  • Credential Provider: Email/password authentication with bcrypt hashing
  • Protected Routes: Middleware-based route protection for admin area
  • Automatic Redirects: Smart routing based on authentication state

πŸ›‘οΈ Security Features

  • Rate Limiting: Upstash Redis-based request throttling (5 login attempts per 10 minutes)
  • CSRF Protection: Built-in NextAuth CSRF tokens
  • Content Security Policy: Strict CSP headers via middleware
  • SQL Injection Prevention: Prisma ORM parameterized queries
  • Input Sanitization: HTML sanitization for user-generated content
  • Environment Variable Validation: Type-safe env vars with @t3-oss/env-nextjs
  • Secure Headers: Custom security headers via Next.js middleware

πŸ€– AI-Powered Features

✨ OpenAI Integration

  • AI Description Generator: Automatically generate compelling vehicle descriptions
  • Streamable Responses: Real-time AI output streaming
  • Content Enhancement: Improve existing descriptions with AI suggestions
  • Custom Prompts: Tailored prompts for automotive content
  • Token Management: Efficient API usage with streaming

πŸ›  Technical Features

πŸ’Ύ Database Architecture

  • PostgreSQL: Production-ready relational database
  • Prisma ORM: Type-safe database client with migrations
  • Connection Pooling: Neon database with optimized pooling
  • Soft Deletes: Cascade deletes for related entities
  • Indexes: Optimized queries with strategic indexing
  • Migrations: Version-controlled schema changes
  • Seeding: CSV-based hierarchical data seeding from taxonomy.csv

πŸ“¦ File Storage & CDN

  • AWS S3: Scalable object storage for vehicle images
  • Presigned URLs: Secure, temporary upload links
  • Imgix CDN: Optional image transformation and delivery
  • Multi-region Support: Configurable AWS regions
  • MIME Type Validation: Secure file type checking
  • Size Limits: Configurable upload constraints

πŸ“§ Communication

  • Resend Email API: Transactional email service
  • React Email Templates: Beautifully designed email components
  • OTP Delivery: Secure code delivery for 2FA
  • Booking Confirmations: Automated reservation emails
  • Admin Notifications: Alert system for new leads

πŸ” Advanced Search & Analytics

  • Full-text Search: Search across vehicle titles and descriptions
  • Multi-criteria Filtering: Combine multiple filters simultaneously
  • Sorting Options: Sort by price, year, views, date added
  • Pagination: Server-side pagination with configurable page sizes
  • Page View Tracking: Analytics on vehicle popularity
  • URL State Persistence: Shareable search results

πŸš€ Tech Stack

Frontend

  • Framework: Next.js 15 (App Router with Turbopack)
  • Language: TypeScript 5
  • Styling: Tailwind CSS 4.0
  • UI Components: Radix UI primitives
  • Forms: React Hook Form 7 + Zod validation
  • State Management:
    • URL state with nuqs
    • Form state with React Hook Form
    • No global state library (React Context only)
  • Animation: Framer Motion
  • Icons: Lucide React + React Simple Icons
  • Rich Text: TinyMCE Editor
  • Drag & Drop: @dnd-kit
  • Image Gallery: Swiper + fslightbox-react
  • Date Handling: date-fns

Backend

  • Runtime: Node.js (Edge & Node.js runtimes)
  • Database: PostgreSQL (Neon)
  • ORM: Prisma 6 with extensions
    • @prisma/extension-accelerate for query caching
    • Connection pooling optimized for serverless
  • Authentication: NextAuth v5 (Auth.js)
    • Database sessions
    • Custom JWT encoding
    • Credentials provider with bcrypt
  • File Storage: AWS S3
    • @aws-sdk/client-s3 v3
    • Presigned URLs for secure uploads
  • Email: Resend API
    • React Email for templates
    • Transactional emails
  • Rate Limiting: Upstash Redis
    • @upstash/ratelimit with sliding window
    • API protection
  • AI: OpenAI SDK with streaming

Development Tools

  • Package Manager: npm
  • TypeScript: Strict mode enabled
  • Linting: ESLint with Next.js config
  • Code Formatting: Prettier
  • Database Tools:
    • Prisma Studio (GUI)
    • Prisma Migrate (migrations)
    • ts-node for seeding
  • Build Tool: Turbopack (Next.js dev server)
  • Deployment: Vercel

Key Dependencies

{
  "@ai-sdk/openai": "^1.1.13",
  "@auth/prisma-adapter": "^2.7.4",
  "@dnd-kit/core": "^6.3.1",
  "@hookform/resolvers": "^3.10.0",
  "@prisma/client": "^6.3.1",
  "@radix-ui/react-*": "Latest",
  "@upstash/ratelimit": "^2.0.5",
  "next": "^15.4.0-canary.83",
  "next-auth": "^5.0.0-beta.25",
  "nuqs": "^2.3.1",
  "react": "^19.0.0",
  "tailwindcss": "^4.0.0",
  "zod": "^3.25.56"
}

πŸ“‹ Prerequisites

Before running this project, ensure you have:

  • Node.js 18.17 or later
  • npm or yarn package manager
  • PostgreSQL database (we recommend Neon for serverless Postgres)
  • AWS Account with S3 bucket configured
  • Resend Account for transactional emails
  • Upstash Account for Redis rate limiting
  • TinyMCE API Key (free tier available)
  • OpenAI API Key (optional, for AI features)

⚑ Quick Start

1. Clone the Repository

git clone https://github.com/your-username/car-dealer.git
cd car-dealer

2. Install Dependencies

npm install

3. Environment Setup

Create a .env.local file in the root directory:

# Database (Neon PostgreSQL with connection pooling)
DATABASE_URL="postgresql://username:password@host.region.aws.neon.tech/dbname?sslmode=require"

# NextAuth Configuration
NEXTAUTH_SECRET="your-super-secret-key-here"  # Generate with: openssl rand -base64 32
NEXTAUTH_URL="http://localhost:3000"  # Change to your production URL in Vercel

# AWS S3 Configuration
AWS_S3_BUCKET_ACCESS_KEY="your-aws-access-key"
AWS_S3_BUCKET_SECRET_KEY="your-aws-secret-key"
NEXT_PUBLIC_S3_BUCKET_REGION="us-east-1"
NEXT_PUBLIC_S3_BUCKET_NAME="your-bucket-name"
NEXT_PUBLIC_S3_BUCKET_URL="https://your-bucket-name.s3.region.amazonaws.com"

# Email Service (Resend)
RESEND_API_KEY="re_your-resend-api-key"
SENDER_EMAIL="onboarding@resend.dev"  # Or your verified domain

# TinyMCE Rich Text Editor
NEXT_PUBLIC_TINYMCE_API_KEY="your-tinymce-api-key"

# Redis Rate Limiting (Upstash)
UPSTASH_REDIS_REST_URL="https://your-redis-instance.upstash.io"
UPSTASH_REDIS_REST_TOKEN="your-upstash-token"

# AI Integration (Optional - for description generation)
OPENAI_API_KEY="sk-proj-your-openai-api-key"

# App Configuration
NEXT_PUBLIC_APP_URL="http://localhost:3000"  # Your app URL
X_AUTH_TOKEN="secret"  # Custom auth token for API protection

# Optional: Imgix CDN (if using Imgix for image optimization)
NEXT_PUBLIC_IMGIX_URL="https://your-source.imgix.net"

Important for Production (Vercel):

  • Set NEXTAUTH_URL to your production domain (e.g., https://your-app.vercel.app)
  • Set NEXT_PUBLIC_APP_URL to your production domain
  • Use a strong NEXTAUTH_SECRET (generate with openssl rand -base64 32)
  • Ensure Upstash Redis database is active (free tier databases delete after 14 days of inactivity)

4. Database Setup

# Generate Prisma client
npx prisma generate

# Run database migrations (creates all tables)
npx prisma migrate dev

# Seed the database with sample data
# This will create:
# - Admin user (admin@example.com / admin123)
# - Car makes, models, and variants from taxonomy.csv
# - Sample vehicle listings
# - Sample customers
npx prisma db seed

Database Schema Overview:

  • users & sessions - Authentication tables
  • classifieds - Vehicle listings
  • makes, models, model_variants - Hierarchical car taxonomy
  • images - Vehicle images with thumbhash data
  • customers & customer_lifecycle - Lead management
  • page_views - Analytics tracking

5. Start Development Server

npm run dev

Open http://localhost:3000 to view the application.

πŸ—„οΈ Database Schema

The application uses a comprehensive database schema with the following main entities:

πŸ“ Project Structure

car-dealer/
β”œβ”€β”€ prisma/                    # Database schema and migrations
β”‚   β”œβ”€β”€ schema.prisma         # Main Prisma schema with all models
β”‚   β”œβ”€β”€ migrations/           # Version-controlled schema changes
β”‚   └── seed/                 # Database seeding scripts
β”‚       β”œβ”€β”€ seed.ts           # Main seed orchestrator
β”‚       β”œβ”€β”€ tax.seed.ts       # Make/Model/Variant seeding from CSV
β”‚       β”œβ”€β”€ admin.seed.ts     # Admin user creation
β”‚       β”œβ”€β”€ class.seed.ts     # Sample vehicle listings
β”‚       β”œβ”€β”€ customer.seed.ts  # Sample customer data
β”‚       └── imageSeed.ts      # Sample images with thumbhash
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ app/                  # Next.js App Router
β”‚   β”‚   β”œβ”€β”€ (presentation)/   # Public-facing pages (route group)
β”‚   β”‚   β”‚   β”œβ”€β”€ page.tsx      # Homepage
β”‚   β”‚   β”‚   β”œβ”€β”€ auth/         # Sign-in, challenge pages
β”‚   β”‚   β”‚   β”œβ”€β”€ inventory/    # Vehicle browsing & details
β”‚   β”‚   β”‚   └── favourites/   # User favourites
β”‚   β”‚   β”œβ”€β”€ admin/            # Admin dashboard (protected)
β”‚   β”‚   β”‚   β”œβ”€β”€ dashboard/    # Analytics & overview
β”‚   β”‚   β”‚   β”œβ”€β”€ cars/         # Inventory management
β”‚   β”‚   β”‚   β”œβ”€β”€ customers/    # Lead management
β”‚   β”‚   β”‚   └── settings/     # Admin settings
β”‚   β”‚   β”œβ”€β”€ api/              # API routes
β”‚   β”‚   β”‚   β”œβ”€β”€ auth/         # NextAuth endpoints
β”‚   β”‚   β”‚   β”œβ”€β”€ images/       # S3 upload handlers
β”‚   β”‚   β”‚   β”œβ”€β”€ taxonomy/     # Make/model data endpoints
β”‚   β”‚   β”‚   └── favourites/   # Favourites management
β”‚   β”‚   β”œβ”€β”€ _actions/         # Server Actions (mutations)
β”‚   β”‚   β”‚   β”œβ”€β”€ car.ts        # Vehicle CRUD operations
β”‚   β”‚   β”‚   β”œβ”€β”€ customer.ts   # Customer management
β”‚   β”‚   β”‚   β”œβ”€β”€ challenge.ts  # OTP verification
β”‚   β”‚   β”‚   β”œβ”€β”€ sign-in.ts    # Authentication
β”‚   β”‚   β”‚   β”œβ”€β”€ subscribe.ts  # Newsletter subscription
β”‚   β”‚   β”‚   └── ai.tsx        # AI description generation
β”‚   β”‚   └── schemas/          # Zod validation schemas
β”‚   β”‚       β”œβ”€β”€ car.schema.ts     # Vehicle validation
β”‚   β”‚       β”œβ”€β”€ customer.schema.ts # Customer validation
β”‚   β”‚       β”œβ”€β”€ auth.schema.ts    # Auth validation
β”‚   β”‚       └── ...               # Other schemas
β”‚   β”œβ”€β”€ components/           # React components
β”‚   β”‚   β”œβ”€β”€ ui/               # Base Radix UI components
β”‚   β”‚   β”œβ”€β”€ admin/            # Admin-specific components
β”‚   β”‚   β”œβ”€β”€ car/              # Vehicle-related components
β”‚   β”‚   β”‚   β”œβ”€β”€ car-form.tsx          # Vehicle edit form
β”‚   β”‚   β”‚   β”œβ”€β”€ car-form-fields.tsx   # Form field components
β”‚   β”‚   β”‚   β”œβ”€β”€ car-carousel.tsx      # Image carousel
β”‚   β”‚   β”‚   β”œβ”€β”€ drag-and-drop.tsx     # Image uploader
β”‚   β”‚   β”‚   β”œβ”€β”€ rich-text-editor.tsx  # TinyMCE wrapper
β”‚   β”‚   β”‚   └── TaxonomySelect.tsx    # Make/model dropdowns
β”‚   β”‚   β”œβ”€β”€ auth/             # Authentication components
β”‚   β”‚   β”œβ”€β”€ shared/           # Reusable components
β”‚   β”‚   β”œβ”€β”€ homepage/         # Landing page sections
β”‚   β”‚   β”œβ”€β”€ inventory/        # Inventory browsing UI
β”‚   β”‚   └── reserve/          # Reservation flow
β”‚   β”œβ”€β”€ lib/                  # Utility functions and clients
β”‚   β”‚   β”œβ”€β”€ prisma.ts         # Prisma client singleton
β”‚   β”‚   β”œβ”€β”€ s3.ts             # AWS S3 client & upload functions
β”‚   β”‚   β”œβ”€β”€ resend.ts         # Email client configuration
β”‚   β”‚   β”œβ”€β”€ otp.ts            # OTP generation & validation
β”‚   β”‚   β”œβ”€β”€ rate-limiter.ts   # Upstash Redis rate limiting
β”‚   β”‚   β”œβ”€β”€ thumbhash-server.ts # Server-side thumbhash generation
β”‚   β”‚   β”œβ”€β”€ thumbhash-client.tsx # Client-side thumbhash rendering
β”‚   β”‚   β”œβ”€β”€ uploader.ts       # File upload utilities
β”‚   β”‚   β”œβ”€β”€ utils.ts          # General utilities (cn, formatters)
β”‚   β”‚   └── ai-utils.ts       # OpenAI integration helpers
β”‚   β”œβ”€β”€ config/               # Configuration files
β”‚   β”‚   β”œβ”€β”€ routes.ts         # Centralized route definitions
β”‚   β”‚   β”œβ”€β”€ types.ts          # Shared TypeScript types
β”‚   β”‚   β”œβ”€β”€ constants.ts      # App-wide constants
β”‚   β”‚   └── endpoints.ts      # API endpoint definitions
β”‚   └── middleware.ts         # Route protection & security headers
β”œβ”€β”€ emails/                   # React Email templates
β”‚   └── challenge.tsx         # OTP email template
β”œβ”€β”€ public/                   # Static assets
β”œβ”€β”€ auth.config.ts            # NextAuth configuration
β”œβ”€β”€ auth.ts                   # Auth.js wrapper
β”œβ”€β”€ next.config.ts            # Next.js configuration
β”œβ”€β”€ tailwind.config.ts        # Tailwind CSS configuration
β”œβ”€β”€ tsconfig.json             # TypeScript configuration
β”œβ”€β”€ taxonomy.csv              # Car make/model seed data
└── .env.local                # Environment variables (gitignored)

πŸ”§ Available Scripts

# Development
npm run dev          # Start development server with Turbopack (fast HMR)
npm run build        # Build for production (optimized)
npm run start        # Start production server
npm run lint         # Run ESLint for code quality

# Database Operations
npx prisma studio    # Open Prisma Studio (visual database browser)
npx prisma generate  # Regenerate Prisma Client after schema changes
npx prisma migrate dev       # Create and apply new migration
npx prisma migrate deploy    # Apply migrations in production
npx prisma db push   # Push schema changes without creating migration (dev only)
npx prisma db seed   # Seed database with initial data
npx prisma migrate reset     # Reset database and re-run all migrations + seed

# Useful Development Commands
npx prisma format    # Format schema.prisma file
npx prisma validate  # Validate Prisma schema
npx prisma db pull   # Pull schema from existing database (introspection)

# Deployment
npm run build && npm run start   # Build and start production server locally
vercel                           # Deploy to Vercel (install: npm i -g vercel)

Common Development Workflows

Adding a new feature:

npm run dev              # Start dev server
# Make changes...
npx prisma migrate dev   # If schema changed
npm run build            # Test production build
git add . && git commit  # Commit changes
git push                 # Auto-deploy to Vercel

Database schema changes:

# Edit prisma/schema.prisma
npx prisma migrate dev --name add_new_field
npx prisma generate
# Update TypeScript types in config/types.ts if needed

🌐 API Routes

The application provides comprehensive API endpoints:

Authentication

  • POST /api/auth/signin - Sign in with credentials
  • POST /api/auth/signout - Sign out and destroy session
  • POST /api/auth/session - Get current session
  • GET /api/auth/csrf - Get CSRF token

Vehicle Management

  • GET /api/cars - List vehicles with filtering
  • GET /api/cars/[id] - Get single vehicle details
  • POST /api/cars - Create new vehicle (admin)
  • PUT /api/cars/[id] - Update vehicle (admin)
  • DELETE /api/cars/[id] - Delete vehicle (admin)

Image Upload

  • POST /api/images/upload - Upload image to S3
  • POST /api/images/presigned-url - Get presigned S3 URL
  • DELETE /api/images/[key] - Delete image from S3

Taxonomy Data

  • GET /api/taxonomy/makes - Get all car makes
  • GET /api/taxonomy/models?makeId=[id] - Get models for make
  • GET /api/taxonomy/variants?modelId=[id] - Get variants for model

Favourites

  • GET /api/favourites - Get user's favourites (cookie-based)
  • POST /api/favourites - Add to favourites
  • DELETE /api/favourites/[id] - Remove from favourites

Server Actions (Form Mutations)

Located in src/app/_actions/:

  • createCarAction - Create new vehicle listing
  • updateCarAction - Update existing vehicle
  • deleteCarAction - Delete vehicle
  • signInAction - Authenticate user with rate limiting
  • challengeAction - Verify OTP code
  • createCustomerAction - Create new customer lead
  • updateCustomerStatusAction - Update lead status
  • generateDescriptionAction - AI-powered description generation

🀝 Contributing

Contributions are welcome! Please follow these guidelines:

Development Process

  1. Fork the Repository

    git clone https://github.com/vvduth/car-dealer.git
    cd car-dealer
  2. Create a Feature Branch

    git checkout -b feature/your-feature-name
  3. Make Your Changes

    • Follow existing code patterns
    • Use TypeScript for type safety
    • Update Prisma schema if needed
    • Add Zod schemas for new forms
    • Follow component structure conventions
  4. Test Your Changes

    npm run dev          # Test locally
    npm run build        # Ensure production build works
    npm run lint         # Check for linting errors
  5. Commit Your Changes

    git add .
    git commit -m "feat: add new feature"

    Commit Message Conventions:

    • feat: New feature
    • fix: Bug fix
    • docs: Documentation changes
    • style: Code style changes (formatting)
    • refactor: Code refactoring
    • test: Test additions/changes
    • chore: Build process or tooling changes
  6. Push to Your Fork

    git push origin feature/your-feature-name
  7. Submit a Pull Request

    • Describe your changes clearly
    • Reference any related issues
    • Include screenshots for UI changes

Code Style Guidelines

  • TypeScript: Use strict type checking
  • Components: Functional components with TypeScript
  • Server Actions: Always use "use server" directive
  • Client Components: Mark with "use client" when needed
  • Styling: Use Tailwind CSS utility classes
  • Imports: Use @/ alias for cleaner imports
  • Error Handling: Return { success: boolean, message: string }
  • Validation: Zod schemas for all user inputs

Areas for Contribution

  • πŸ› Bug fixes and improvements
  • ✨ New features (vehicle comparisons, saved searches, etc.)
  • πŸ“ Documentation improvements
  • 🎨 UI/UX enhancements
  • β™Ώ Accessibility improvements
  • 🌍 Internationalization (i18n)
  • πŸ§ͺ Test coverage
  • ⚑ Performance optimizations

πŸ“ License

This project is licensed under the MIT License. See the LICENSE file for details.

οΏ½ License

This project is licensed under the MIT License. See the LICENSE file for details.

οΏ½πŸ™ Acknowledgments

This project was built with amazing open-source technologies:

  • Next.js - The React framework for production by Vercel
  • Vercel - Deployment and hosting platform with edge network
  • Prisma - Next-generation ORM for type-safe database access
  • NextAuth.js - Complete authentication solution for Next.js
  • Radix UI - Unstyled, accessible component primitives
  • Tailwind CSS - Utility-first CSS framework
  • shadcn/ui - Re-usable components built with Radix and Tailwind
  • Upstash - Serverless Redis for rate limiting and caching
  • Neon - Serverless PostgreSQL with branching
  • AWS S3 - Scalable object storage
  • Resend - Modern email API for developers
  • OpenAI - AI models for content generation
  • TinyMCE - Rich text editor

Special thanks to the open-source community for making these tools freely available.

Built with ❀️ by vvduth using Next.js 15 and modern web technologies

Live Demo: https://car-dealer-lake-eight.vercel.app/

GitHub: https://github.com/vvduth/car-dealer

Releases

No releases published

Packages

No packages published