- Implement tests for RideLocation and CompanyHeadquarters models to verify functionality and data integrity. - Create a manual trigger test script for trending content calculation endpoint, including authentication and unauthorized access tests. - Develop a manufacturer sync test to ensure ride manufacturers are correctly associated with ride models. - Add tests for ParkLocation model, including coordinate setting and distance calculations between parks. - Implement a RoadTripService test suite covering geocoding, route calculation, park discovery, and error handling. - Create a unified map service test script to validate map functionality, API endpoints, and performance metrics.
7.9 KiB
Frontend Migration Plan: React/Next.js to HTMX + Alpine.js
Executive Summary
Based on my analysis, this project already has a fully functional HTMX + Alpine.js Django backend with comprehensive templates. The task is to migrate the separate Next.js React frontend (frontend/ directory) to integrate seamlessly with the existing Django HTMX + Alpine.js architecture.
Current State Analysis
✅ Django Backend (Already Complete)
- HTMX Integration: Already implemented with proper headers and partial templates
- Alpine.js Components: Extensive use of Alpine.js for interactivity
- Template Structure: Comprehensive template hierarchy with partials
- Authentication: Complete auth system with modals and forms
- Styling: Tailwind CSS with dark mode support
- Components: Reusable components for cards, pagination, forms, etc.
🔄 React Frontend (To Be Migrated)
- Next.js App Router: Modern React application structure
- Component Library: Extensive UI components using shadcn/ui
- Authentication: React-based auth hooks and providers
- Theme Management: React theme provider system
- API Integration: TypeScript API clients for Django backend
Migration Strategy
Phase 1: Template Enhancement (Extend Django Templates)
Instead of replacing the existing Django templates, we'll enhance them to match the React frontend's design and functionality.
1.1 Header Component Migration
Current Django: Basic header with navigation React Frontend: Advanced header with browse menu, search, theme toggle, user dropdown
Action: Enhance backend/templates/base/base.html header section
1.2 Component Library Integration
Current Django: Basic components React Frontend: Rich component library (buttons, cards, modals, etc.)
Action: Create Django template components matching shadcn/ui design system
1.3 Advanced Interactivity
Current Django: Basic Alpine.js usage React Frontend: Complex state management and interactions
Action: Enhance Alpine.js components with advanced patterns
Phase 2: Django View Enhancements
2.1 API Response Optimization
- Enhance existing Django views to support both full page and HTMX partial responses
- Implement proper JSON responses for Alpine.js components
- Add advanced filtering and search capabilities
2.2 Authentication Flow
- Enhance existing Django auth to match React frontend UX
- Implement modal-based login/signup (already partially done)
- Add proper error handling and validation
Phase 3: Frontend Asset Migration
3.1 Static Assets
- Migrate React component styles to Django static files
- Enhance Tailwind configuration
- Add missing JavaScript utilities
3.2 Alpine.js Store Management
- Implement global state management using Alpine.store()
- Create reusable Alpine.js components using Alpine.data()
- Add proper event handling and communication
Implementation Plan
Step 1: Analyze Component Gaps
Compare React components with Django templates to identify missing functionality:
- Browse Menu: React has sophisticated browse dropdown
- Search Functionality: React has advanced search with autocomplete
- Theme Toggle: React has system/light/dark theme support
- User Management: React has comprehensive user profile management
- Modal System: React has advanced modal components
- Form Handling: React has sophisticated form validation
Step 2: Enhance Django Templates
Base Template Enhancements
<!-- Enhanced header with browse menu -->
<div class="browse-menu" x-data="browseMenu()">
<!-- Implement React-style browse menu -->
</div>
<!-- Enhanced search with autocomplete -->
<div class="search-container" x-data="searchComponent()">
<!-- Implement React-style search -->
</div>
Alpine.js Component Library
// Global Alpine.js components
Alpine.data('browseMenu', () => ({
open: false,
toggle() { this.open = !this.open }
}))
Alpine.data('searchComponent', () => ({
query: '',
results: [],
async search() {
// Implement search logic
}
}))
Step 3: Django View Enhancements
Enhanced Views for HTMX
def enhanced_park_list(request):
if request.headers.get('HX-Request'):
# Return partial template for HTMX
return render(request, 'parks/partials/park_list.html', context)
# Return full page
return render(request, 'parks/park_list.html', context)
Step 4: Component Migration Priority
-
Header Component (High Priority)
- Browse menu with categories
- Advanced search with autocomplete
- User dropdown with profile management
- Theme toggle with system preference
-
Navigation Components (High Priority)
- Mobile menu with slide-out
- Breadcrumb navigation
- Tab navigation
-
Form Components (Medium Priority)
- Advanced form validation
- File upload components
- Multi-step forms
-
Data Display Components (Medium Priority)
- Advanced card layouts
- Data tables with sorting/filtering
- Pagination components
-
Modal and Dialog Components (Low Priority)
- Confirmation dialogs
- Image galleries
- Settings panels
Technical Implementation Details
HTMX Patterns to Implement
- Lazy Loading
<div hx-get="/api/parks/" hx-trigger="intersect" hx-swap="innerHTML">
Loading parks...
</div>
- Infinite Scroll
<div hx-get="/api/parks/?page=2" hx-trigger="revealed" hx-swap="beforeend">
Load more...
</div>
- Live Search
<input hx-get="/api/search/" hx-trigger="input changed delay:300ms"
hx-target="#search-results">
Alpine.js Patterns to Implement
- Global State Management
Alpine.store('app', {
user: null,
theme: 'system',
searchQuery: ''
})
- Reusable Components
Alpine.data('modal', () => ({
open: false,
show() { this.open = true },
hide() { this.open = false }
}))
File Structure After Migration
backend/
├── templates/
│ ├── base/
│ │ ├── base.html (enhanced)
│ │ └── components/
│ │ ├── header.html
│ │ ├── footer.html
│ │ ├── navigation.html
│ │ └── search.html
│ ├── components/
│ │ ├── ui/
│ │ │ ├── button.html
│ │ │ ├── card.html
│ │ │ ├── modal.html
│ │ │ └── form.html
│ │ └── layout/
│ │ ├── browse_menu.html
│ │ └── user_menu.html
│ └── partials/
│ ├── htmx/
│ └── alpine/
├── static/
│ ├── js/
│ │ ├── alpine-components.js
│ │ ├── htmx-config.js
│ │ └── app.js
│ └── css/
│ ├── components.css
│ └── tailwind.css
Success Metrics
- Functionality Parity: All React frontend features work in Django templates
- Design Consistency: Visual design matches React frontend exactly
- Performance: Page load times improved due to server-side rendering
- User Experience: Smooth interactions with HTMX and Alpine.js
- Maintainability: Clean, reusable template components
Timeline Estimate
- Phase 1: Template Enhancement (3-4 days)
- Phase 2: Django View Enhancements (2-3 days)
- Phase 3: Frontend Asset Migration (2-3 days)
- Testing & Refinement: 2-3 days
Total Estimated Time: 9-13 days
Next Steps
- Immediate: Start with header component migration
- Priority: Focus on high-impact components first
- Testing: Implement comprehensive testing for each migrated component
- Documentation: Update all documentation to reflect new architecture
This migration will result in a unified, server-rendered application with the rich interactivity of the React frontend but the performance and simplicity of HTMX + Alpine.js.