Overview
EpiNeko uses a service layer pattern to abstract external API calls and data operations. This provides a clean separation between UI components and data fetching logic.Service Architecture
jikan.ts
Fetches anime data from MyAnimeList via Jikan API
library.ts
Manages user library with Supabase database
Jikan Service
The Jikan service provides access to the Jikan API v4, an unofficial MyAnimeList API.Base Configuration
The service uses Next.js’s
next.revalidate for automatic cache management. Default cache time is 3600 seconds (1 hour).Type Definitions
JikanAnime Interface
JikanAnime Interface
JikanImage Interface
JikanImage Interface
JikanEpisode Interface
JikanEpisode Interface
JikanResponse Interface
JikanResponse Interface
API Functions
getTopAnime
Fetch the top-rated anime from MyAnimeList.searchAnime
Search for anime by query string.getAnimeById
Fetch detailed information for a specific anime.Individual anime details are cached for 24 hours since they change infrequently.
getAnimeCharacters
Fetch character list for an anime.getAnimeEpisodes
Fetch episode list for an anime with pagination.Error Handling
The Jikan service includes built-in error handling:1
Rate Limit Detection
Catches 429 status and returns a user-friendly message
2
HTTP Error Handling
Throws descriptive errors for failed requests
3
Automatic Retries
Next.js cache system handles stale data revalidation
Library Service
The Library service manages user anime collections using Supabase.Type Definitions
Database Operations
addToLibrary
Add a new anime to the user’s library.removeFromLibrary
Remove an anime from the user’s library.updateLibraryItem
Update an existing library entry.getLibrary
Retrieve all library items for the current user.Results are automatically sorted by most recently updated first.
getLibraryItem
Check if a specific anime is in the user’s library.Supabase Utilities
Client-Side Client
For browser-based operations:src/utils/supabase/client.ts
Server-Side Client
For server components and API routes:src/utils/supabase/server.ts
Middleware Client
For session management in middleware:src/utils/supabase/middleware.ts
Best Practices
Error Handling
Always wrap service calls in try-catch blocks
Loading States
Show feedback while waiting for API responses
Cache Strategy
Use appropriate revalidation times per endpoint
Authentication
Check user state before library operations
Common Patterns
Fetching with Loading State
Fetching with Loading State
Optimistic Updates
Optimistic Updates
Parallel Requests
Parallel Requests
Related Documentation
Components
See how components use services
Environment Variables
Configure API credentials
Project Structure
Understand service organization