Add comprehensive .gitignore
This commit is contained in:
207
docs/maternal-app-dataflow.txt
Normal file
207
docs/maternal-app-dataflow.txt
Normal file
@@ -0,0 +1,207 @@
|
||||
================================================================================
|
||||
MATERNAL APP MVP - DATA FLOW ARCHITECTURE
|
||||
================================================================================
|
||||
|
||||
┌─────────────────────────────────────────────────────────────────────────────┐
|
||||
│ USER INTERFACE LAYER │
|
||||
├─────────────────────────────────────────────────────────────────────────────┤
|
||||
│ │
|
||||
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
|
||||
│ │ Parent 1 │ │ Parent 2 │ │ Caregiver │ │ Voice Input │ │
|
||||
│ │ (Mobile) │ │ (Mobile) │ │ (Mobile) │ │ (Whisper) │ │
|
||||
│ └──────┬───────┘ └──────┬───────┘ └──────┬───────┘ └──────┬───────┘ │
|
||||
│ │ │ │ │ │
|
||||
│ └──────────────────┴──────────────────┴──────────────────┘ │
|
||||
│ │ │
|
||||
│ ▼ │
|
||||
│ ┌───────────────────────┐ │
|
||||
│ │ API Gateway (REST) │ │
|
||||
│ │ Authentication │ │
|
||||
│ │ Rate Limiting │ │
|
||||
│ │ i18n Routing │ │
|
||||
│ └───────────┬───────────┘ │
|
||||
│ │ │
|
||||
└──────────────────────────────────────┼──────────────────────────────────────┘
|
||||
│
|
||||
================================================================================
|
||||
REAL-TIME SYNC LAYER
|
||||
================================================================================
|
||||
│
|
||||
┌────────────▼────────────┐
|
||||
│ WebSocket Server │
|
||||
│ (Socket.io) │
|
||||
│ ┌──────────────────┐ │
|
||||
│ │ Event Publisher │ │
|
||||
│ └──────────────────┘ │
|
||||
│ ┌──────────────────┐ │
|
||||
│ │ Family Rooms │ │
|
||||
│ └──────────────────┘ │
|
||||
└────────────┬────────────┘
|
||||
│
|
||||
┌─────────────────┼─────────────────┐
|
||||
│ │ │
|
||||
▼ ▼ ▼
|
||||
┌──────────┐ ┌──────────┐ ┌──────────┐
|
||||
│ Redis │ │ Redis │ │ Redis │
|
||||
│ Channel 1│ │ Channel 2│ │ Channel 3│
|
||||
│ (Family) │ │ (Family) │ │ (Family) │
|
||||
└──────────┘ └──────────┘ └──────────┘
|
||||
│ │ │
|
||||
└─────────────────┼─────────────────┘
|
||||
│
|
||||
================================================================================
|
||||
APPLICATION SERVICE LAYER
|
||||
================================================================================
|
||||
│
|
||||
┌──────────────────────────────┼──────────────────────────────┐
|
||||
│ │ │
|
||||
▼ ▼ ▼
|
||||
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
|
||||
│ Tracking │ │ AI Assistant │ │ Analytics │
|
||||
│ Service │ │ Service │ │ Service │
|
||||
│ │ │ │ │ │
|
||||
│ • Feeding │ │ • Chat Handler │ │ • Pattern │
|
||||
│ • Sleep │ │ • Context Mgr │ │ Detection │
|
||||
│ • Diaper │◄─────────┤ • LLM Gateway │◄─────────┤ • Predictions │
|
||||
│ • Growth │ │ • Response Gen │ │ • Insights │
|
||||
│ • Voice Process │ │ │ │ • Reports │
|
||||
└────────┬────────┘ └────────┬────────┘ └────────┬────────┘
|
||||
│ │ │
|
||||
│ ▼ │
|
||||
│ ┌───────────────────────┐ │
|
||||
│ │ LLM API Gateway │ │
|
||||
│ │ ┌────────────────┐ │ │
|
||||
│ │ │ OpenAI/Claude │ │ │
|
||||
│ │ └────────────────┘ │ │
|
||||
│ │ ┌────────────────┐ │ │
|
||||
│ │ │ Context Cache │ │ │
|
||||
│ │ └────────────────┘ │ │
|
||||
│ └───────────────────────┘ │
|
||||
│ │
|
||||
└──────────────────────┬──────────────────────────────────┘
|
||||
│
|
||||
================================================================================
|
||||
DATA PERSISTENCE LAYER
|
||||
================================================================================
|
||||
│
|
||||
┌───────────▼───────────┐
|
||||
│ Database Router │
|
||||
└───────────┬───────────┘
|
||||
│
|
||||
┌───────────────────────┼───────────────────────┐
|
||||
│ │ │
|
||||
▼ ▼ ▼
|
||||
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
|
||||
│ PostgreSQL │ │ MongoDB │ │ Redis │
|
||||
│ (Primary) │ │ (Documents) │ │ (Cache) │
|
||||
├──────────────┤ ├──────────────┤ ├──────────────┤
|
||||
│ • Users │ │ • AI Chats │ │ • Sessions │
|
||||
│ • Children │ │ • Reports │ │ • Real-time │
|
||||
│ • Activities │ │ • Analytics │ │ • Predictions│
|
||||
│ • Families │ │ • Logs │ │ • Temp Data │
|
||||
│ • Settings │ │ │ │ │
|
||||
└──────┬───────┘ └──────┬───────┘ └──────┬───────┘
|
||||
│ │ │
|
||||
└──────────────────────┼───────────────────────┘
|
||||
│
|
||||
================================================================================
|
||||
BACKGROUND JOBS LAYER
|
||||
================================================================================
|
||||
│
|
||||
┌─────────▼─────────┐
|
||||
│ Message Queue │
|
||||
│ (Bull) │
|
||||
└─────────┬─────────┘
|
||||
│
|
||||
┌─────────────────────┼─────────────────────┐
|
||||
│ │ │
|
||||
▼ ▼ ▼
|
||||
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
|
||||
│ Notification │ │ ML/AI │ │ Data │
|
||||
│ Worker │ │ Worker │ │ Export │
|
||||
├──────────────┤ ├──────────────┤ ├──────────────┤
|
||||
│ • Push │ │ • Training │ │ • PDF Gen │
|
||||
│ • Email │ │ • Prediction │ │ • CSV Export │
|
||||
│ • SMS │ │ • Analysis │ │ • Backup │
|
||||
└──────────────┘ └──────────────┘ └──────────────┘
|
||||
|
||||
================================================================================
|
||||
DATA FLOW PATTERNS
|
||||
================================================================================
|
||||
|
||||
1. ACTIVITY LOGGING FLOW:
|
||||
User → Mobile App → API Gateway → Tracking Service → PostgreSQL
|
||||
↓
|
||||
WebSocket Server → Redis Pub/Sub → All Family Devices
|
||||
|
||||
2. AI ASSISTANT FLOW:
|
||||
User Query → Voice/Text Input → AI Service → Context Fetch (PostgreSQL)
|
||||
↓
|
||||
LLM API → Response Generation
|
||||
↓
|
||||
MongoDB (Chat History) → User
|
||||
|
||||
3. PATTERN RECOGNITION FLOW:
|
||||
PostgreSQL Data → Analytics Service → ML Worker → Pattern Detection
|
||||
↓
|
||||
Redis Cache → Predictions
|
||||
↓
|
||||
Push Notification
|
||||
|
||||
4. REAL-TIME SYNC FLOW:
|
||||
Device A → WebSocket → Redis Channel → WebSocket → Device B
|
||||
↓
|
||||
PostgreSQL (Persistence)
|
||||
|
||||
5. OFFLINE SYNC FLOW:
|
||||
Mobile SQLite → Queue Actions → Network Available → Sync Service
|
||||
↓
|
||||
PostgreSQL
|
||||
↓
|
||||
Conflict Resolution
|
||||
↓
|
||||
Update All Devices
|
||||
|
||||
================================================================================
|
||||
SECURITY BOUNDARIES
|
||||
================================================================================
|
||||
|
||||
┌─────────────────────────────────────────────────────────────────────────┐
|
||||
│ ENCRYPTED AT REST │
|
||||
│ ┌───────────────────────────────────────────────────────────────────┐ │
|
||||
│ │ END-TO-END ENCRYPTED │ │
|
||||
│ │ ┌─────────────────────────────────────────────────────────────┐ │ │
|
||||
│ │ │ SENSITIVE USER DATA │ │ │
|
||||
│ │ │ • Child Health Records │ │ │
|
||||
│ │ │ • Personal Identifiable Information │ │ │
|
||||
│ │ │ • Location Data │ │ │
|
||||
│ │ └─────────────────────────────────────────────────────────────┘ │ │
|
||||
│ │ │ │
|
||||
│ │ ENCRYPTED IN TRANSIT │ │
|
||||
│ └───────────────────────────────────────────────────────────────────┘ │
|
||||
│ │
|
||||
│ AUDIT LOGGING │
|
||||
└─────────────────────────────────────────────────────────────────────────┘
|
||||
|
||||
================================================================================
|
||||
SCALABILITY NOTES
|
||||
================================================================================
|
||||
|
||||
• Horizontal Scaling Points:
|
||||
- API Gateway (Load Balancer)
|
||||
- WebSocket Servers (Sticky Sessions)
|
||||
- Service Layer (Kubernetes Pods)
|
||||
- Redis (Cluster Mode)
|
||||
- PostgreSQL (Read Replicas)
|
||||
|
||||
• Bottleneck Mitigation:
|
||||
- LLM API: Response caching, rate limiting
|
||||
- Database: Connection pooling, query optimization
|
||||
- Real-time: Redis pub/sub for fan-out
|
||||
- Storage: CDN for static assets
|
||||
|
||||
• Performance Targets:
|
||||
- API Response: <200ms (p95)
|
||||
- Real-time Sync: <100ms
|
||||
- AI Response: <3s
|
||||
- Offline Support: 7 days of data
|
||||
Reference in New Issue
Block a user