=> {
const cacheType = config.get<'memory' | 'redis'>('cache.type', 'memory');
if (cacheType === 'memory') {
return {
ttl: config.get('cache.ttl', 300) * 1000,
max: config.get('cache.max', 1000),
};
}
// Redis
return {
store: await redisStore({
url: config.get('redis.url'),
ttl: config.get('cache.ttl', 300),
}),
};
};
```
### 3.13.4 Deployment Profiles
OpenWA provides several deployment profiles for different needs:
```mermaid
flowchart LR
subgraph Minimal["🪶 Minimal Profile"]
M1[SQLite]
M2[Local Storage]
M3[In-Memory Cache]
M4[Single Session]
end
subgraph Standard["⚡ Standard Profile"]
S1[PostgreSQL]
S2[Local Storage]
S3[Redis]
S4[Multi Session]
end
subgraph Enterprise["🏢 Enterprise Profile"]
E1[PostgreSQL Cluster]
E2[S3/MinIO]
E3[Redis Cluster]
E4[Horizontal Scaling]
end
```
| Profile | Database | Storage | Cache | Sessions | RAM | Use Case |
|---------|----------|---------|-------|----------|-----|----------|
| **Minimal** | SQLite | Local | In-Memory | 1-3 | 512MB | Personal bot, testing |
| **Standard** | PostgreSQL | Local | Redis | 5-10 | 2GB | Small business |
| **Enterprise** | PostgreSQL | S3/MinIO | Redis | 10+ | 4GB+ | Agency, high volume |
### Configuration Examples
#### Minimal Profile (.env)
```bash
# Database
DATABASE_TYPE=sqlite
DATABASE_SQLITE_PATH=./data/openwa.db
# Storage
STORAGE_TYPE=local
STORAGE_LOCAL_PATH=./media
# Cache (in-memory, no config needed)
CACHE_TYPE=memory
# Session
MAX_SESSIONS=3
# No Redis needed
# REDIS_URL=
```
#### Standard Profile (.env)
```bash
# Database
DATABASE_TYPE=postgres
DATABASE_URL=postgresql://openwa:password@localhost:5432/openwa
# Storage
STORAGE_TYPE=local
STORAGE_LOCAL_PATH=./media
# Cache
CACHE_TYPE=redis
REDIS_URL=redis://localhost:6379
# Session
MAX_SESSIONS=10
```
#### Enterprise Profile (.env)
```bash
# Database
DATABASE_TYPE=postgres
DATABASE_URL=postgresql://openwa:password@db-cluster:5432/openwa
DATABASE_POOL_MAX=50
# Storage
STORAGE_TYPE=s3
STORAGE_S3_BUCKET=openwa-media
STORAGE_S3_REGION=ap-southeast-1
STORAGE_S3_ACCESS_KEY_ID=xxx
STORAGE_S3_SECRET_ACCESS_KEY=xxx
# For MinIO:
# STORAGE_S3_ENDPOINT=http://minio:9000
# STORAGE_S3_FORCE_PATH_STYLE=true
# Cache
CACHE_TYPE=redis
REDIS_URL=redis://redis-cluster:6379
# Session
MAX_SESSIONS=50
# Scaling
ENABLE_CLUSTER_MODE=true
```
### Auto-Detection & Recommendations
```typescript
// config/profile-detector.ts
import { Logger } from '@nestjs/common';
interface SystemResources {
totalMemoryMB: number;
availableMemoryMB: number;
cpuCores: number;
}
export function detectRecommendedProfile(resources: SystemResources): string {
const logger = new Logger('ProfileDetector');
if (resources.totalMemoryMB < 1024) {
logger.warn('Low memory detected. Using minimal profile.');
logger.warn('Recommendation: SQLite + Local Storage + In-Memory Cache');
return 'minimal';
}
if (resources.totalMemoryMB < 4096) {
logger.log('Standard resources detected.');
logger.log('Recommendation: PostgreSQL + Local Storage + Redis');
return 'standard';
}
logger.log('High resources detected.');
logger.log('Recommendation: PostgreSQL + S3 + Redis with clustering');
return 'enterprise';
}
```
---
[← 02 - Requirements Specification](./02-requirements-specification.md) · [Documentation Index](./README.md) · [Next: 04 - Security Design →](./04-security-design.md)