A modern, interactive web application for learning gradient-free optimization algorithms. Built with SvelteKit for optimal performance and user experience.
Before you begin, ensure you have the following installed on your system:
- Node.js (version 18.0 or higher)
- npm (comes with Node.js) or yarn
- Git (for cloning the repository)
-
Clone the repository
git clone <repository-url> cd optimization-tutorial/svelte-optimization-tutorial
-
Install dependencies
npm install
Or if you prefer yarn:
yarn install
-
Start the development server
npm run dev
Or with yarn:
yarn dev
-
Open in browser
Navigate to
http://localhost:5173in your web browser. The application will automatically reload when you make changes to the code.
- Visit nodejs.org
- Download the LTS version (recommended)
- Run the installer and follow the installation wizard
- Verify installation by opening Command Prompt and running:
node --version npm --version
Option 1: Direct Download
- Visit nodejs.org
- Download the LTS version
- Run the installer
Option 2: Using Homebrew
brew install node# Update package index
sudo apt update
# Install Node.js
sudo apt install nodejs npm
# Verify installation
node --version
npm --version# Install Node.js using NodeSource repository
curl -fsSL https://rpm.nodesource.com/setup_lts.x | sudo bash -
sudo yum install nodejs npmAfter installing Node.js and npm, verify they're working correctly:
node --version # Should show v18.x.x or higher
npm --version # Should show 8.x.x or highersvelte-optimization-tutorial/
├── src/
│ ├── lib/
│ │ ├── components/ # Reusable Svelte components
│ │ │ ├── Sidebar.svelte
│ │ │ ├── ParameterControl.svelte
│ │ │ └── VisualizationPanel.svelte
│ │ ├── data/ # Algorithm data and configurations
│ │ └── utils/ # Utility functions
│ ├── routes/
│ │ ├── +layout.svelte # Main layout component
│ │ ├── +page.svelte # Landing page
│ │ ├── overview/ # Algorithm overview page
│ │ └── optimizers/ # Individual optimizer pages
│ │ └── hill-climbing/ # Example optimizer page
│ └── app.html # HTML template
├── static/ # Static assets (images, GIFs, etc.)
├── package.json # Dependencies and scripts
├── svelte.config.js # Svelte configuration
└── vite.config.js # Vite build configuration
npm run dev- Start development server with hot reloadnpm run build- Build the application for productionnpm run preview- Preview the production build locallynpm run check- Run Svelte type checkingnpm run check:watch- Run type checking in watch mode
-
Create a new route directory
mkdir src/routes/optimizers/your-algorithm-name
-
Create the page component
touch src/routes/optimizers/your-algorithm-name/+page.svelte
-
Use the existing template structure
- Copy the structure from
src/routes/optimizers/hill-climbing/+page.svelte - Update the algorithm information, parameters, and descriptions
- Add algorithm-specific visualizations
- Copy the structure from
-
Update the sidebar navigation
- Edit
src/lib/components/Sidebar.svelte - Add your algorithm to the appropriate category in the
optimizersarray
- Edit
-
Add to overview page
- Edit
src/routes/overview/+page.svelte - Add your algorithm to the
optimizersarray with scoring information
- Edit
- Static assets (images, GIFs, etc.) go in the
static/directory - Reference assets in your components using absolute paths:
/assets/algorithm-name/visualization.gif - Organize assets by algorithm in subfolders:
static/assets/hill-climbing/
- Use CSS custom properties for consistent theming
- Follow mobile-first responsive design principles
- Use semantic HTML elements for accessibility
- Maintain consistent spacing using rem units
- Use descriptive class names following BEM methodology when appropriate
The application uses CSS custom properties for theming. Key colors can be modified in the root CSS:
:root {
--primary-color: #3b82f6;
--secondary-color: #64748b;
--success-color: #059669;
--warning-color: #dc2626;
--background-color: #f8fafc;
--text-color: #334155;
}- Create your component in
src/lib/components/ - Export it from the component file
- Import and use in your pages:
<script> import MyComponent from '$lib/components/MyComponent.svelte'; </script>
npm run buildThis creates a build directory with the compiled application.
- Push your code to a Git repository
- Connect your repository to Vercel
- Vercel will automatically deploy on every push
- Build the project:
npm run build - Upload the
builddirectory to Netlify - Configure redirects for SPA routing
The built application is a static site and can be hosted on any static hosting service:
- GitHub Pages
- Amazon S3 + CloudFront
- Google Firebase Hosting
Create a .env file in the root directory for environment-specific configuration:
VITE_API_URL=your-api-url
VITE_ANALYTICS_ID=your-analytics-id
Access in your components with:
import { env } from '$env/dynamic/public';
const apiUrl = env.VITE_API_URL;1. Port already in use
# Kill process using port 5173
sudo lsof -ti:5173 | xargs sudo kill -9
# Or start on a different port
npm run dev -- --port 30002. Module resolution errors
- Clear node_modules and reinstall:
rm -rf node_modules package-lock.json npm install
3. Build failures
- Check for TypeScript errors:
npm run check - Ensure all imports use correct paths with
$libalias
4. Assets not loading
- Verify assets are in the
static/directory - Use absolute paths starting with
/ - Check browser network tab for 404 errors
- Lazy load images with the
loading="lazy"attribute - Optimize GIFs - consider converting to WebP or MP4
- Code splitting - SvelteKit handles this automatically
- Preload critical resources in
app.html
- Use TypeScript for better development experience
- Write tests for components using @testing-library/svelte
- Follow accessibility guidelines (WCAG 2.1)
- Optimize for SEO with proper meta tags and structured data
- Monitor performance with Lighthouse audits
- Fork the repository
- Create a feature branch:
git checkout -b feature/your-feature-name - Make your changes and test thoroughly
- Commit with descriptive messages
- Push to your fork:
git push origin feature/your-feature-name - Create a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
Once you have the application running:
- Explore the landing page to understand the tutorial structure
- Check out the overview page to see algorithm comparisons
- Visit individual algorithm pages to see the interactive parameter controls
- Add your own algorithms using the hill-climbing page as a template
- Integrate existing assets from the original optimization-tutorial repository
The application is designed to be easily extensible - you can add new algorithms, visualizations, and interactive features by following the established patterns in the codebase.