Internal APIs
This section documents the internal APIs and helper functions available in the codebase.
Overview
| API | Location | Purpose |
|---|---|---|
| Database | src/lib/database.ts | High-level Prisma helpers |
| Redis/Cache | src/lib/redis.ts | Caching and distributed operations |
| Validation | src/lib/validation/zod.ts | Zod schemas and validation |
| i18n | src/lib/i18n.ts | Internationalization helpers |
| REST Routes | src/routes/ | HTTP API endpoints |
Accessing Services
All services are available through the Sapphire container:
typescript
import { container } from '@sapphire/framework';
// Database (Prisma)
const guild = await container.prisma.guild.findUnique({ ... });
// Redis
const value = await container.redis.get('key');
// Logger
container.logger.info('Message');Import Patterns
Use path aliases for cleaner imports:
typescript
// Database helpers
import { saveGuild, getGuild } from '#lib/database.js';
// Redis helpers
import { setCache, getCache, CacheKeys } from '#lib/redis.js';
// Validation
import { snowflakeSchema, safeParse } from '#lib/validation/zod.js';
// i18n
import { getGuildLanguage, resolveKeyForInteraction } from '#lib/i18n.js';Best Practices
- Use helpers over raw Prisma - The database helpers handle common patterns
- Cache frequently accessed data - Use Redis for configuration, settings
- Validate user input - Always validate with Zod schemas
- Handle i18n - Use translation keys for user-facing strings