Complete rewrite of Appwrite integration to match the new database structure with two separate databases: whisperrnote for users and chat for all chat features.
-
whisperrnote Database (
67ff05a9000296822396)- users collection (shared with base app)
-
chat Database (
chat)- conversations, messages, contacts
- stories, posts, follows
- wallets, tokenHoldings
- stickers, gifs, polls, etc.
- ✅ Moved from
tablesDBAPI todatabasesAPI - ✅ Updated all database/collection IDs from env variables
- ✅ Separated WHISPERRNOTE and CHAT collections
- ✅ Removed all hardcoded values
- ✅ Created clean service architecture
- ✅
env.sample- Complete rewrite with actual IDs - ✅
src/lib/appwrite/config/constants.ts- New database structure - ✅
src/lib/appwrite/config/client.ts- Updated to use Databases API - ✅
src/lib/appwrite/config/index.ts- Central config export
- ✅
src/lib/appwrite/services/auth.service.ts- Authentication - ✅
src/lib/appwrite/services/user.service.ts- User management (whisperrnote DB) - ✅
src/lib/appwrite/services/messaging.service.ts- Conversations & messages - ✅
src/lib/appwrite/services/contacts.service.ts- Contacts management - ✅
src/lib/appwrite/services/storage.service.ts- File uploads - ✅
src/lib/appwrite/services/index.ts- Services export
- ✅
src/lib/appwrite/index.ts- Central export for all Appwrite features
VITE_APPWRITE_ENDPOINT=https://fra.cloud.appwrite.io/v1
VITE_APPWRITE_PROJECT_ID=your-project-idVITE_DATABASE_WHISPERRNOTE=67ff05a9000296822396
VITE_DATABASE_CHAT=chatAll collection IDs are set in env.sample with their actual values from appwrite.config.json.
import {
authService,
userService,
messagingService,
contactsService,
storageService
} from '@/lib/appwrite';// Login
const session = await authService.login(email, password);
// Get current user
const user = await authService.getCurrentUser();
// Logout
await authService.logout();// Get user from whisperrnote database
const user = await userService.getUser(userId);
// Search users
const users = await userService.searchUsers('john');// Create conversation
const conversation = await messagingService.createConversation({
type: 'direct',
creatorId: userId,
participantIds: [userId, otherUserId],
});
// Send message
const message = await messagingService.sendMessage({
conversationId: conversation.$id,
senderId: userId,
content: 'Hello!',
contentType: 'text',
});
// Get messages
const messages = await messagingService.getConversationMessages(conversationId);// Upload message attachment
const file = await storageService.uploadMessageAttachment(fileObject);
// Upload voice message
const voice = await storageService.uploadVoiceMessage(voiceFile);
// Get file URL
const url = storageService.getFileView(BUCKET_IDS.MESSAGES, fileId);import { isConfigurationValid, getMissingEnvVars } from '@/lib/appwrite';
if (!isConfigurationValid()) {
const missing = getMissingEnvVars();
console.error('Missing env vars:', missing);
}All services include proper TypeScript interfaces:
User- User document from whisperrnote DBConversation- Conversation document from chat DBMessage- Message document from chat DBContact- Contact document from chat DB
import { tablesDB } from '@/lib/appwrite/config/client';
import { DATABASE_IDS, MAIN_COLLECTIONS } from '@/lib/appwrite/config/constants';
// Old API
const profile = await tablesDB.getRow({
databaseId: DATABASE_IDS.MAIN,
tableId: MAIN_COLLECTIONS.PROFILES,
rowId: userId
});import { userService } from '@/lib/appwrite';
// New API
const user = await userService.getUser(userId);- Separate services for each domain
- Clear separation between whisperrnote and chat databases
- Type-safe interfaces
- All IDs from environment variables
- Easy to change configurations
- No magic strings
- Simple, intuitive API
- Full TypeScript support
- Comprehensive error handling
- Proper error logging
- Validation helpers
- Secure configuration
- ✅ Copy
env.sampleto.env - ✅ Add your
VITE_APPWRITE_PROJECT_ID - ✅ Test authentication flow
- ✅ Test messaging features
- ✅ Update frontend components to use new services
Old service files backed up to:
src/lib/appwrite/services/backup/
Test configuration:
import { isConfigured, getConfig } from '@/lib/appwrite';
console.log('Configured:', isConfigured());
console.log('Config:', getConfig());Test services:
// Test auth
const user = await authService.getCurrentUser();
console.log('Current user:', user);
// Test database access
const users = await userService.searchUsers('test');
console.log('Found users:', users);✅ Configuration complete ✅ Services implemented ✅ Type definitions added ✅ Documentation complete ✅ Ready for MVP development