# MotoRisk - Motorcycle Risk Assessment Calculator ## Project Overview This is a full-stack web application that calculates personalized motorcycle riding risk scores using comprehensive data analysis. The application provides instant safety recommendations based on user profiles, motorcycle specifications, and riding habits. ## Tech Stack - **Frontend**: React 18 with TypeScript, Wouter routing, TanStack Query for state management - **Backend**: Node.js with Express.js, TypeScript with ES modules - **Database**: PostgreSQL with Drizzle ORM - **UI**: shadcn/ui components with Radix UI primitives, Tailwind CSS - **Build**: Vite for development and production builds ## Key Features - Real-time risk calculation using NHTSA baseline data (67 fatalities per 100k rider-years) - Comprehensive motorcycle database with 361+ authentic models - Interactive mobile-optimized interface with continuous scroll progress indicator - User survey system with 5-star rating and optional feedback collection - User interaction tracking that saves risk factor changes to database - Google AdSense integration for monetization - SEO-optimized with structured data and comprehensive safety content ## Database Schema - `motorcycles`: Stores motorcycle specifications (make, model, year, engine CC, category, power, weight) - `risk_assessments`: Stores user risk assessment data with comprehensive safety factors - `user_analytics`: Tracks user behavior and engagement metrics - `user_surveys`: Stores user feedback ratings and optional text feedback - `user_interactions`: Tracks all risk factor changes with debounced database saves ## Project Structure ``` ├── client/ # React frontend │ ├── src/ │ │ ├── components/ # UI components │ │ │ ├── risk-calculator.tsx # Main calculator component │ │ │ ├── user-survey.tsx # Survey component with star rating │ │ │ ├── personal-info-form.tsx # User demographics form │ │ │ ├── motorcycle-selection-form.tsx # Motorcycle search/selection │ │ │ ├── riding-habits-form.tsx # Riding behavior inputs │ │ │ ├── safety-gear-form.tsx # Safety equipment selection │ │ │ └── risk-display.tsx # Risk score visualization │ │ ├── hooks/ │ │ │ ├── useUserInteractions.ts # Tracks user input changes │ │ │ └── use-toast.ts # Toast notification system │ │ ├── lib/ │ │ │ ├── risk-calculator.ts # Core risk calculation engine │ │ │ ├── risk-data.ts # Risk multipliers and baseline data │ │ │ └── cookies.ts # Cookie management for user tracking │ │ ├── types/ │ │ │ └── index.ts # TypeScript type definitions │ │ └── pages/ # Route pages ├── server/ # Express backend │ ├── routes.ts # API endpoints │ ├── storage.ts # Database operations (MemStorage implementation) │ ├── db.ts # Database connection setup │ └── index.ts # Server entry point └── shared/ └── schema.ts # Drizzle database schema definitions ``` ## Key Components ### Risk Calculation Engine - Uses log odds methodology with NHTSA baseline (67 fatalities per 100k rider-years) - Applies statistical multipliers for: age, experience, gender, motorcycle type, riding habits, safety gear, location - Real-time calculation updates as users modify inputs - Generates prioritized safety recommendations based on risk profile ### User Experience Features - Mobile-first design with immediate calculator access - Full-screen vertical progress bar that fills based on scroll position - Centered toast-style cookie banner for mobile users - Debounced user interaction tracking to prevent excessive API calls - Star rating system with optional feedback dialog ### Data Sources - Motorcycle database pre-seeded from CSV with popular models - NHTSA, IIHS, and other authoritative safety statistics - State-by-state helmet law compliance data - Real crash data analysis for risk multipliers ## API Endpoints - `GET /api/motorcycles` - Retrieve all motorcycles (internal use only) - `GET /api/motorcycles/search?q=` - Search motorcycles by query - `POST /api/risk-assessments` - Create new risk assessment - `POST /api/user-surveys` - Submit user feedback survey - `POST /api/user-interactions` - Track user input changes - `POST /api/analytics/track` - Track user behavior analytics ## Development Guidelines - Follow mobile-first responsive design principles - Use TypeScript for all new code - Implement proper error handling and loading states - Use debounced API calls for frequent user interactions - Maintain SEO optimization with structured data - Follow authentication patterns for user tracking via cookies ## Important Notes - All user data is tracked via cookie-based user IDs - Risk assessments are linked to user surveys for feedback analysis - Database uses MemStorage for development, can be switched to PostgreSQL - Rate limiting is implemented on all API endpoints - Google AdSense integration requires proper ads.txt configuration ## Recent Changes - Implemented comprehensive user survey system with 5-star rating - Added user interaction tracking with database persistence - Enhanced mobile cookie banner as centered toast popup - Created new database tables for surveys and user interactions - Mobile progress bar optimized to complete at results section bottom ## Cookie Management - User ID and session tracking via CookieManager class - Risk factors saved to cookies with analytics consent - GDPR-compliant cookie consent system - Analytics tracking blocked until user consent ## SEO Features - Structured data markup for search engines - Comprehensive FAQ section with Schema.org microdata - XML sitemap for search engine crawling - Canonical URLs and meta descriptions - OpenGraph tags for social media sharing ## Deployment - Runs on Replit with PostgreSQL database - Uses npm for dependency management - Vite handles both frontend and backend in development - Production build outputs to dist/ directory - Environment variables required: DATABASE_URL for PostgreSQL connection