✅ DO:
❌ DON'T:
Example - Secure Storage:
// JavaScript - Use environment variables
const API_KEY = process.env.SULALA_API_KEY;
// Flutter - Use secure storage
final prefs = await SharedPreferences.getInstance();
final apiKey = prefs.getString('api_key');
✅ DO:
❌ DON'T:
Example - HTTPS Only:
// JavaScript
const BASE_URL = process.env.NODE_ENV === 'production'
? 'https://sulala.ai'
: 'http://localhost:3000';
✅ DO:
~/.ssh, ~/Documents/Private)❌ DON'T:
Example - Safe Search Scope:
const SAFE_DIRECTORIES = [
'~/Documents',
'~/Downloads',
'~/Desktop'
];
const EXCLUDED_DIRECTORIES = [
'~/.ssh',
'~/.config',
'~/Library/Application Support'
];
✅ DO:
❌ DON'T:
Example - Efficient Polling:
// Poll after heartbeat
async function pollCycle() {
await sendHeartbeat();
await pollForSearches();
await pollForUploadRequests();
}
setInterval(pollCycle, 30000); // 30 seconds
✅ DO:
❌ DON'T:
Example - Optimized Search:
async function searchFiles(query, maxResults = 100) {
const results = [];
const searchPaths = getSearchPaths();
for (const path of searchPaths) {
const files = await searchInDirectory(path, query);
results.push(...files);
if (results.length >= maxResults) break;
}
return results.slice(0, maxResults);
}
✅ DO:
❌ DON'T:
✅ DO:
❌ DON'T:
Example - Robust Error Handling:
async function sendHeartbeatWithRetry(maxRetries = 3) {
for (let i = 0; i < maxRetries; i++) {
try {
return await sendHeartbeat();
} catch (error) {
if (i === maxRetries - 1) throw error;
await sleep(Math.pow(2, i) * 1000); // Exponential backoff
}
}
}
✅ DO:
❌ DON'T:
✅ DO:
❌ DON'T:
Example - Proper Logging:
logger.info('Heartbeat sent', {
deviceId: deviceId,
status: 'online'
});
logger.error('Search failed', {
queryId: queryId,
error: error.message // Don't log full stack trace in production
});
✅ DO:
❌ DON'T:
✅ DO:
Example - Configuration:
const config = {
apiKey: process.env.SULALA_API_KEY || '',
baseUrl: process.env.SULALA_BASE_URL || 'http://localhost:3000',
heartbeatInterval: parseInt(process.env.HEARTBEAT_INTERVAL || '30000'),
pollingInterval: parseInt(process.env.POLLING_INTERVAL || '30000')
};
✅ DO:
❌ DON'T:
✅ DO:
Example - System Service (macOS):
<!-- LaunchAgent plist -->
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
✅ DO:
❌ DON'T:
✅ DO:
✅ DO:
✅ DO:
✅ DO:
✅ DO:
Before deploying to production: