Architectural Principles
The project follows these core architectural principles:Service Layer Architecture
Service Layer Architecture
All external API interactions are abstracted into dedicated service modules located in
src/server/services/. Each service handles authentication, data fetching, and error handling independently.Component-Based UI
Component-Based UI
Reusable Astro components are organized in
src/components/ with clear responsibilities. Each component encapsulates its own styles and behavior.Type Safety
Type Safety
TypeScript types are defined in
src/types/ with dedicated subdirectories for each external service (Spotify, SoundCloud, YouTube).Internationalization
Internationalization
Multi-language support is built-in using Astro’s i18n routing with dictionaries for each locale.
Core Layers
Presentation Layer
The presentation layer consists of:- Pages (
src/pages/[...locale]/): Route handlers using Astro’s file-based routing - Layouts (
src/layouts/): Shared page templatesBaseLayout.astro: Core HTML structure, SEO, analyticsPageLayout.astro: Content page wrapper
- Components (
src/components/): Reusable UI elements
Service Layer
The service layer (src/server/services/) provides a clean API for external integrations:
auth.ts: Authentication and token management- Specific resource handlers (e.g.,
tracks.ts,users.ts) index.ts: Public API exports
Spotify
Authentication and top tracks fetching
src/server/services/spotify/SoundCloud
User info and track retrieval
src/server/services/soundcloud/YouTube
Playlist and video data
src/server/services/youtube/Data Layer
Base Fetcher
All HTTP requests use a centralized fetcher with error handling:- Generic type support
- Automatic JSON parsing
- Structured error handling (
ApiError,NetworkError) - Centralized request configuration
Caching Strategy
Server-side in-memory cache reduces API calls:Tokens are cached with a 60-second buffer before their actual expiration time to prevent race conditions.
Design Patterns
Service Facade Pattern
Each external API is wrapped in a facade that provides a clean, unified interface:Error Handling
Custom error types provide specific error context:Utility Functions
Helper functions are organized by concern:- i18n utilities (
src/utils/i18n.ts): Dictionary loading and locale handling - Animations (
src/utils/animations.ts): Reusable animation helpers - Data transformers (
src/utils/getSoundCloudTracksLinks.ts,getYoutubeVideosInfo.ts): API response processing
Static Assets
Assets are organized by feature insrc/assets/:
Configuration Files
- Astro Config
- i18n Config
- TypeScript Config
Best Practices
Next Steps
Project Structure
Explore the complete directory structure
Routing System
Learn about Astro’s routing and i18n