Component Philosophy
Our components follow these principles:- Single Responsibility - Each component has one clear purpose
- Type Safety - Full TypeScript integration with props validation
- Composability - Small components combine to create complex UIs
- Accessibility - Semantic HTML and ARIA attributes
- Performance - Minimal re-renders using Svelte’s reactivity
Component Organization
Components are organized by feature domain insrc/ui/:
Svelte 5 Patterns
Runes-Based Reactivity
Components use Svelte 5’s runes for state management:$state - Reactive State
$derived - Computed Values
$effect - Side Effects
$props - Component Props
Snippets
Reusable template fragments:Global State Management
Color Scheme Store
src/ui/store.svelte.ts manages theme preferences:
Schedule Navigation Store
src/ui/schedule/store.svelte.ts manages date selection and navigation state.
Spoiler Prevention Store
src/ui/spoiler-prevention/store.svelte.ts controls score hiding functionality.
Component Categories
Game Components
Display live and historical game data. Key Components:game/status.svelte- Game state (Preview, Live, Final)game/team-scores.svelte- Current score displaygame/linescore.svelte- Inning-by-inning scoringgame/plays.svelte- Play-by-play feedgame/win-probability.svelte- Win probability visualizationgame/top-performers.svelte- Best players of the game
Team Components
Team branding and information. Key Components:team/logo.svelte- Team logo with fallbackteam/roster.svelte- Active roster displayteam/styled-team.svelte- Team-colored themingteam/team-calendar.svelte- Team-specific schedule
Player Components
Player profiles and statistics. Key Components:player/headshot.svelte- Player photo with fallbackplayer/player-info.svelte- Bio and detailsplayer/search.svelte- Player search interfaceplayer/hot-cold-zones-list.svelte- Batting zone data
Stats Components
Statistical visualizations and data displays. Key Components:stats/year-by-year.svelte- Career stats tablestats/hot-cold-zones.svelte- Zone heat mapsstats/strikezone.svelte- Strike zone visualizationstats/season-picker.svelte- Season selection
Schedule Components
Calendar and date navigation. Key Components:schedule/calendar.svelte- Full calendar viewschedule/date-picker.svelte- Single date selectorschedule/week-picker.svelte- Week navigationschedule/month-picker-with-year.svelte- Month/year combo
Icon System
SVG icon components inui/icons/.
Icon Categories:
- Baseball: ball, bat, diamond, helmet, jersey
- Navigation: chevron-left, chevron-right, arrows
- UI Controls: expand, collapse, eye, star, search
- Theme: sun, moon, sidebar
- Data: calendar, rank, info, flag
Sidebar Components
Navigation and application settings. Key Components:sidebar/drawer.svelte- Collapsible sidebar containersidebar/nav.svelte- Main navigation menusidebar/toggle-color-scheme.svelte- Dark/light mode togglesidebar/favorites-list.svelte- Favorite teams managementsidebar/compare-list.svelte- Team comparison tool
Playground Components
API exploration and testing tools. Key Components:playground/select-endpoint.svelte- Endpoint dropdownplayground/parameters-table.svelte- Parameter configurationplayground/response.svelte- JSON response viewer
Styling Patterns
Tailwind Utilities
Components use Tailwind CSS classes:Conditional Classes
Usingclsx and tailwind-merge:
Theme-Aware Styling
Dark mode support through Tailwind’sdark: prefix:
Data Fetching in Components
Live Data Integration
Components can subscribe to live data:Load Function Data
Components receive data from SvelteKit’sload functions:
Accessibility
Semantic HTML
Components use proper HTML elements:ARIA Attributes
Accessibility attributes for screen readers:Keyboard Navigation
Interactive elements support keyboard control:Performance Optimization
Lazy Loading
Components are code-split automatically by SvelteKit:Memoization
Expensive computations use$derived:
Event Delegation
List components use delegation for better performance:Testing Patterns
Components are designed for testability:- Pure logic extracted to utility functions
- Props-driven rendering for easy testing
- Minimal side effects in component code
- Type safety catches errors at compile time
Best Practices
- Keep components small - Under 200 lines when possible
- Extract utilities - Move complex logic to
$lib/ - Type everything - Use TypeScript interfaces for all props
- Use runes - Leverage Svelte 5’s reactivity system
- Compose components - Build complex UIs from simple parts
- Follow conventions - Match existing patterns in the codebase
- Consider accessibility - Add ARIA labels and keyboard support
- Optimize images - Use proper loading strategies
- Handle loading states - Show feedback during data fetches
- Test edge cases - Handle missing/null data gracefully