This document provides a comprehensive overview of the Media Vault system architecture, including its components, data flow, user roles, and design decisions.
- Permissions:
- Upload and manage personal media
- View and edit own media metadata
- Share media with other users
- Generate AI descriptions for media
- View personal analytics
- Permissions:
- All End User permissions
- Access to partner-specific media
- Manage media shared with partner organization
- View partner-level analytics
- Permissions:
- All Partner User permissions
- Manage system users and roles
- Configure system settings
- Access system-wide analytics
- Perform system maintenance
sequenceDiagram
participant U as User
participant F as Frontend
participant A as API
participant S as Storage
participant D as Database
participant K as Keycloak
U->>F: Select files to upload
F->>K: Request auth token
K-->>F: Return JWT
F->>A: Upload files (with JWT)
A->>K: Validate token
A->>S: Store files
A->>D: Save metadata
A-->>F: Return success/error
F-->>U: Show upload status
sequenceDiagram
participant U as Owner
participant F as Frontend
participant A as API
participant D as Database
participant R as Recipient
U->>F: Select media to share
F->>A: Request share (with permissions)
A->>D: Create share record
A-->>F: Share link/notification
F-->>U: Confirm share
A->>R: Send notification (email/in-app)
R->>F: Access shared media
F->>A: Validate access
A-->>F: Return media
F-->>R: Display shared media
- Responsive web interface
- Media upload and management
- Real-time updates
- Authentication flows
- API Gateway: Request routing and authentication
- Media Service: File processing and storage
- Metadata Service: Media metadata management
- AI Service: Media analysis and description
- Sharing Service: Access control and sharing
- PostgreSQL: Relational data
- Object Storage: Media files
- Redis: Caching and sessions
- Docker & Docker Compose: Containerization
- Caddy: Reverse proxy
- Keycloak: Authentication/Authorization
- Monitoring Stack: Prometheus, Grafana, Loki
- Local Docker Compose setup
- Hot-reload for development
- Local database instances
- Container orchestration (Kubernetes)
- High availability
- Automated backups
- Monitoring and alerting
- Authentication: User authenticates via Keycloak
- Request Processing: Caddy routes requests to appropriate service
- Business Logic: Backend services process requests
- Data Persistence: Data is stored in appropriate storage
- Response: Results are returned to the frontend
- All communications use HTTPS
- JWT-based authentication
- Role-based access control (RBAC)
- Input validation and sanitization
- Regular security audits
- Horizontal scaling for stateless services
- Database read replicas
- CDN for media delivery
- Caching layer for frequent queries
- Code commit triggers build
- Run tests
- Build Docker images
- Deploy to staging
- Run integration tests
- Deploy to production
- GDPR compliance for user data
- Data retention policies
- Audit logging
- Regular backups
- Centralized error logging
- Graceful degradation
- User-friendly error messages
- Automatic retries for transient failures
See API Documentation for detailed API specifications and examples.
graph TD
User[👤 User] --> Browser[🌐 Browser]
Browser --> Caddy[🔶 Caddy Proxy]
%% Authentication Flow
Browser -.->|1. Login| Keycloak[🔐 Keycloak Auth]
Keycloak -.->|2. JWT Token| Browser
%% Application Flow
Caddy -->|3. Serve UI| Flutter[🎨 Flutter Web]
Caddy -->|4. API Requests| VaultAPI[🔒 Media Vault API]
%% Backend Services
VaultAPI -->|5. Validate| Keycloak
VaultAPI -->|6. Store/Retrieve| Database[(📊 PostgreSQL)]
VaultAPI -->|7. Process| Analyzer[🔍 Media Analyzer]
VaultAPI -->|8. Scan| NSFW[🤖 NSFW Detector]
%% Storage
VaultAPI -->|9. Store Files| Storage[💾 Object Storage]
%% Monitoring
subgraph "📊 Monitoring"
Prometheus[Prometheus]
Grafana[Grafana]
Loki[Loki]
Promtail[Promtail]
end
VaultAPI -->|10. Metrics| Prometheus
Prometheus -->|11. Visualize| Grafana
VaultAPI -->|12. Logs| Loki
%% Styling
classDef frontend fill:#e3f2fd,stroke:#1976d2
classDef backend fill:#4a148c,stroke:#7b1fa2,color:white
classDef auth fill:#fff3e0,stroke:#f57c00
classDef storage fill:#fff8e1,stroke:#f57c00
classDef monitoring fill:#e8f5e9,stroke:#388e3c
class Flutter frontend
class VaultAPI,Analyzer,NSFW backend
class Keycloak auth
class Database,Storage storage
class Prometheus,Grafana,Loki,Promtail monitoring
- Responsive UI: Works on all devices
- Progressive Web App (PWA): Installable on desktop/mobile
- State Management: Provider/Riverpod
- Theming: Light/Dark mode support
- RESTful API: JSON-based endpoints
- Authentication: JWT validation with Keycloak
- Rate Limiting: Protect against abuse
- Request Validation: Input sanitization
- Documentation: OpenAPI/Swagger
- Single Sign-On (SSO): Support for OAuth2/OIDC
- Multi-Factor Auth: TOTP, WebAuthn
- User Federation: LDAP, Active Directory
- Role-Based Access Control (RBAC): Fine-grained permissions
- File Analysis: Extract metadata
- Thumbnail Generation: For images and videos
- Content Moderation: NSFW detection
- Format Conversion: Transcoding to web-friendly formats
- Object Storage: S3-compatible (MinIO)
- Encryption: At-rest and in-transit
- Versioning: File history and rollback
- Replication: Cross-region replication for DR
- Metrics: Prometheus
- Visualization: Grafana dashboards
- Logging: Loki + Promtail
- Alerting: Alertmanager
- User authenticates and gets JWT
- Client requests signed upload URL from API
- Client uploads file directly to storage
- API processes the file asynchronously
- Metadata is stored in database
- User receives upload confirmation
sequenceDiagram
participant U as User
participant F as Frontend
participant K as Keycloak
participant A as API
U->>F: Access app
F->>K: Redirect to login
U->>K: Enter credentials
K->>F: Return JWT
F->>A: Request with JWT
A->>K: Validate token
K->>A: Token info
A->>F: Protected data
F->>U: Render UI
Below is the detailed infrastructure stack that powers Media Vault:
🏗️ INFRASTRUCTURE OVERVIEW
┌─────────────────────────────────────────────────────────────────────┐
│ MONITORING LAYER │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Prometheus │ │ Grafana │ │AlertManager │ │ Jaeger │ │
│ │ :9090 │ │ :3333 │ │ :9093 │ │ :16686 │ │
│ │ Metrics │ │ Dashboards │ │ Alerts │ │ Tracing │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ └─────────────┘ │
└─────────────────────────────────────────────────────────────────────┘
## 📊 Complete Infrastructure Stack
```ascii
🏗️ INFRASTRUCTURE OVERVIEW
┌─────────────────────────────────────────────────────────────────────┐
│ MONITORING LAYER │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Prometheus │ │ Grafana │ │AlertManager │ │ Jaeger │ │
│ │ :9090 │ │ :3333 │ │ :9093 │ │ :16686 │ │
│ │ Metrics │ │ Dashboards │ │ Alerts │ │ Tracing │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ └─────────────┘ │
└─────────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────────┐
│ LOGGING LAYER │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Loki │ │ Promtail │ │ ELK │ │ FileBeat │ │
│ │ :3100 │ │ Log Ship │ │ :5601 │ │ Log Ship │ │
│ │ Log Aggreg │ │ │ │ Advanced │ │ │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ └─────────────┘ │
└─────────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────────┐
│ MANAGEMENT LAYER │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Portainer │ │ pgAdmin │ │Redis Cmd │ │ Watchtower │ │
│ │ :9000 │ │ :5050 │ │ :8081 │ │ Auto Update │ │
│ │ Docker Mgmt │ │ DB Admin │ │ Redis Mgmt │ │ │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ └─────────────┘ │
└─────────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────────┐
│ SECURITY & BACKUP │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Traefik │ │ Nginx Proxy │ │ Backup │ │ Security │ │
│ │ :8080 │ │ :8181 │ │ Service │ │ Scanner │ │
│ │ Load Bal │ │ Proxy Mgmt │ │ Automated │ │ Trivy │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ └─────────────┘ │
└─────────────────────────────────────────────────────────────────────┘
# Full infrastructure stack
make infrastructure
# Basic monitoring only
make monitoring
# Everything (Vault + Infrastructure)
make full-stack
# Specialized stacks
make infra-elk # Elasticsearch + Kibana
make infra-traefik # Traefik load balancer
make infra-nginx # Nginx Proxy Manager# Status and health
make infra-status # Infrastructure status
make health-check # Health check all services
make dev-logs # Development logs
# Performance and security
make load-test # K6 performance testing
make security-scan # Trivy vulnerability scan
make performance-report # Generate report
# Backup and maintenance
make backup-now # Immediate backup
make cleanup-all # Clean unused resources- ✅ System metrics (CPU, Memory, Disk, Network)
- ✅ Container metrics (Docker stats via cAdvisor)
- ✅ Application metrics (API response times, errors)
- ✅ Keycloak metrics (authentication events)
- ✅ Custom alerts (service down, high resource usage)
- 📊 Infrastructure Overview - System health
- 📈 Application Performance - API metrics
- 🔐 Security Dashboard - Auth events
- 💾 Storage Analytics - Vault usage
- 🐳 Container Monitoring - Docker stats
Critical Alerts:
- Service Down (> 1 min)
- Disk Space < 10%
- Memory Usage > 90%
- Failed Login Spike
Warning Alerts:
- High CPU (> 80%, 5 min)
- Response Time > 2s
- Memory Usage > 85%| Service | Port | Purpose | Dashboard |
|---|---|---|---|
| Prometheus | 9090 | Metrics collection | http://localhost:9090 |
| Grafana | 3333 | Visualization | http://localhost:3333 |
| AlertManager | 9093 | Alert management | http://localhost:9093 |
| Node Exporter | 9100 | Host metrics | http://localhost:9100 |
| cAdvisor | 8888 | Container metrics | http://localhost:8888 |
| Service | Port | Purpose | Dashboard |
|---|---|---|---|
| Loki | 3100 | Log aggregation | via Grafana |
| Promtail | - | Log shipping | - |
| Elasticsearch | 9200 | Search & analytics | http://localhost:9200 |
| Kibana | 5601 | Log visualization | http://localhost:5601 |
| Jaeger | 16686 | Distributed tracing | http://localhost:16686 |
| Service | Port | Purpose | Dashboard |
|---|---|---|---|
| Portainer | 9000 | Docker management | http://localhost:9000 |
| pgAdmin | 5050 | PostgreSQL admin | http://localhost:5050 |
| Redis Commander | 8081 | Redis management | http://localhost:8081 |
| Traefik | 8080 | Load balancer | http://localhost:8080 |
- 🛡️ Container scanning with Trivy
- 🔐 Secret management via Docker secrets
- 🌐 Network policies and segmentation
- 📝 Audit logging for all admin actions
- 🚨 Intrusion detection alerts
- 📅 Automated daily backups at 2 AM
- ☁️ S3 upload for off-site storage
- 🔄 30-day retention policy
- 🗜️ Compressed archives with encryption
- ✅ Backup verification checks
Security Headers:
- Strict-Transport-Security
- X-Content-Type-Options: nosniff
- X-Frame-Options: DENY
- Referrer-Policy: strict-origin
Rate Limiting:
- 100 requests/minute per IP
- Admin panel IP restriction
- API throttling enabled- 📊 Real-time dashboards
- ⚡ Performance alerts
- 🎯 SLA monitoring (99.9% uptime)
- 📉 Trend analysis
- 🔄 HPA for API services
- 📈 Load balancing with Traefik
- 🎛️ Resource limits per container
- ⚖️ Dynamic scaling based on metrics
# K6 load testing
make load-test
# Response time monitoring
curl -w "@curl-format.txt" http://localhost:8080/health
# Resource usage
docker stats --format "table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}"- 📧 Email notifications to admin
- 💬 Slack integration for team alerts
- 📱 PagerDuty for critical issues
- 📊 Dashboard notifications
-
Service Down:
make health-check # Identify failed service docker-compose restart <service> make dev-logs # Check logs
-
High Resource Usage:
make performance-report # Generate report docker stats # Check current usage make cleanup-all # Clean resources
-
Security Incident:
make security-scan # Vulnerability check docker-compose logs # Review access logs # Block suspicious IPs in Caddy/Traefik
- ✅ Check health dashboard
- 📊 Review performance metrics
- 🔍 Scan security alerts
- 💾 Verify backup completion
- 📈 Performance report review
- 🛡️ Security scan execution
- 🧹 Resource cleanup
- 📋 Capacity planning review
- 🔄 Update container images
- 📊 SLA report generation
- 🗄️ Backup retention cleanup
- 🔐 Security audit review
- Use profiles for different environments
- Enable automatic updates with Watchtower
- Set up custom metrics for business logic
- Implement circuit breakers for resilience
- Always check logs first:
make dev-logs - Use health endpoints for service status
- Monitor resource usage trends
- Keep runbooks updated for common issues
This infrastructure setup provides enterprise-grade monitoring, security, and management capabilities for Media Vault! 🚀