System Architecture
Clean, scalable, and maintainable design
graph TB
%% External Layer
subgraph "🌐 Client Layer"
direction LR
WEB[🖥️ Web Frontend
React/Vue/Angular]
MOBILE[📱 Mobile App
iOS/Android]
API_CLIENT[🔧 API Client
Third-party Integration]
end
%% Main Service
subgraph "🚀 Prism File Service"
direction TB
%% Entry Point
MAIN[🎯 main.go
Application Bootstrap
• Server startup
• Dependency injection
• Graceful shutdown]
%% API Gateway Layer
subgraph "🛡️ API Gateway Layer"
direction TB
ROUTER[🔀 HTTP Router
Gin/Echo Framework]
AUTH[🔐 JWT Middleware
• Token validation
• Rate limiting
• CORS handling]
LOGGER[📊 Request Logger
Structured logging]
end
%% Handler Layer
subgraph "🎮 Handler Layer"
direction LR
UPLOAD_H[⬆️ Upload Handler
• Multipart parsing
• Size validation
• Type checking]
DOWNLOAD_H[⬇️ Download Handler
• Stream response
• Range support
• Cache headers]
META_H[📋 Metadata Handler
• File listing
• Search & filter
• Pagination]
DELETE_H[🗑️ Delete Handler
• Soft delete
• Batch operations
• Cleanup jobs]
end
%% Service Layer
subgraph "⚙️ Business Logic Layer"
direction TB
FILE_SVC[📁 File Service
• Upload processing
• Virus scanning
• Thumbnail generation
• Metadata extraction]
STORAGE_SVC[💾 Storage Service
• Multi-backend support
• Failover logic
• Compression]
CACHE_SVC[⚡ Cache Service
• Hot file caching
• CDN integration
• Cache invalidation]
end
%% Storage Abstraction
subgraph "🗄️ Storage Abstraction Layer"
direction TB
STORAGE_IF[🔌 Storage Interface
Go interface definition]
subgraph "Storage Implementations"
direction LR
S3_IMPL[☁️ AWS S3
• Multi-region
• Encryption
• Lifecycle policies]
LOCAL_IMPL[💿 Local Storage
• High-speed SSD
• RAID configuration
• Backup jobs]
GCS_IMPL[🌥️ Google Cloud
• Auto-scaling
• Global CDN
• AI integration]
MINIO_IMPL[🐋 MinIO
• Self-hosted
• S3 compatible
• Kubernetes ready]
end
end
%% Repository Layer
subgraph "🗃️ Data Access Layer"
direction TB
FILE_REPO[📊 File Repository
• CRUD operations
• Complex queries
• Transaction support
• Connection pooling]
USER_REPO[👤 User Repository
• User management
• Permission checks
• Activity tracking]
end
end
%% Infrastructure Layer
subgraph "🏗️ Infrastructure & Dependencies"
direction TB
subgraph "💾 Databases"
POSTGRES[🐘 PostgreSQL
• File metadata
• User data
• Audit logs
• Full-text search]
REDIS[🔴 Redis Cluster
• JWT denylist
• Session store
• Hot cache
• Pub/Sub messaging]
end
subgraph "🔐 Security & Config"
VAULT[🏦 HashiCorp Vault
• API keys
• DB credentials
• Encryption keys
• Certificate management]
CONSUL[🗺️ HashiCorp Consul
• Service discovery
• Configuration
• Health checks
• Load balancing]
end
subgraph "📈 Monitoring & Observability"
PROMETHEUS[📊 Prometheus
• Metrics collection
• Alert rules
• Performance monitoring]
JAEGER[🔍 Jaeger
• Distributed tracing
• Request flow
• Latency analysis]
ELK[📋 ELK Stack
• Log aggregation
• Search & analysis
• Dashboards]
end
subgraph "🌐 External Services"
CDN[🚀 CloudFlare CDN
• Global edge cache
• DDoS protection
• SSL termination]
ANTIVIRUS[🛡️ ClamAV
• Virus scanning
• Malware detection
• Quarantine system]
QUEUE[📮 Message Queue
• Async processing
• Job scheduling
• Dead letter queue]
end
end
%% Data Flow Connections
WEB -.->|HTTPS/REST API| ROUTER
MOBILE -.->|HTTPS/REST API| ROUTER
API_CLIENT -.->|HTTPS/REST API| ROUTER
MAIN --> ROUTER
ROUTER --> AUTH
AUTH --> LOGGER
LOGGER --> UPLOAD_H
LOGGER --> DOWNLOAD_H
LOGGER --> META_H
LOGGER --> DELETE_H
UPLOAD_H --> FILE_SVC
DOWNLOAD_H --> FILE_SVC
META_H --> FILE_SVC
DELETE_H --> FILE_SVC
FILE_SVC --> STORAGE_SVC
FILE_SVC --> CACHE_SVC
FILE_SVC --> FILE_REPO
FILE_SVC --> USER_REPO
STORAGE_SVC --> STORAGE_IF
STORAGE_IF --> S3_IMPL
STORAGE_IF --> LOCAL_IMPL
STORAGE_IF --> GCS_IMPL
STORAGE_IF --> MINIO_IMPL
FILE_REPO --> POSTGRES
USER_REPO --> POSTGRES
CACHE_SVC --> REDIS
AUTH --> REDIS
MAIN -.->|Secrets| VAULT
MAIN -.->|Config| CONSUL
%% External integrations
FILE_SVC -.->|Virus Scan| ANTIVIRUS
FILE_SVC -.->|Async Jobs| QUEUE
STORAGE_SVC -.->|Global Cache| CDN
%% Monitoring connections
ROUTER -.->|Metrics| PROMETHEUS
FILE_SVC -.->|Traces| JAEGER
LOGGER -.->|Logs| ELK
%% Styling
classDef clientClass fill:#e1f5fe,stroke:#0277bd,stroke-width:2px,color:#000
classDef serviceClass fill:#f3e5f5,stroke:#7b1fa2,stroke-width:2px,color:#000
classDef handlerClass fill:#e8f5e8,stroke:#2e7d32,stroke-width:2px,color:#000
classDef businessClass fill:#fff3e0,stroke:#ef6c00,stroke-width:2px,color:#000
classDef storageClass fill:#fce4ec,stroke:#c2185b,stroke-width:2px,color:#000
classDef dataClass fill:#e0f2f1,stroke:#00695c,stroke-width:2px,color:#000
classDef infraClass fill:#f1f8e9,stroke:#558b2f,stroke-width:2px,color:#000
classDef monitorClass fill:#fff8e1,stroke:#ff8f00,stroke-width:2px,color:#000
classDef externalClass fill:#fafafa,stroke:#424242,stroke-width:2px,color:#000
class WEB,MOBILE,API_CLIENT clientClass
class MAIN,ROUTER,AUTH,LOGGER serviceClass
class UPLOAD_H,DOWNLOAD_H,META_H,DELETE_H handlerClass
class FILE_SVC,STORAGE_SVC,CACHE_SVC businessClass
class STORAGE_IF,S3_IMPL,LOCAL_IMPL,GCS_IMPL,MINIO_IMPL storageClass
class FILE_REPO,USER_REPO,POSTGRES dataClass
class REDIS,VAULT,CONSUL infraClass
class PROMETHEUS,JAEGER,ELK monitorClass
class CDN,ANTIVIRUS,QUEUE externalClass