This document describes the architecture of the HostingCo system, including its components, data flow, and design principles.
The HostingCo system is a modern, microservices-oriented web application built with scalability, security, and maintainability in mind.
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Frontend │ │ Backend API │ │ Database │
│ (React) │◄──►│ (Node.js) │◄──►│ (PostgreSQL) │
│ Port: 3000 │ │ Port: 3003 │ │ Port: 5432 │
└─────────────────┘ └─────────────────┘ └─────────────────┘
│
▼
┌─────────────────┐
│ Cache Layer │
│ (Redis) │
│ Port: 6379 │
└─────────────────┘
┌─────────────────────────────────────────────────────────┐
│ Frontend Layer │
├─────────────────────────────────────────────────────────┤
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Pages │ │ Components │ │ Hooks │ │
│ │ │ │ │ │ │ │
│ │ Dashboard │ │ Layout │ │ useAuth │ │
│ │ Login │ │ Header │ │ │ │
│ │ Hosting │ │ Sidebar │ │ │ │
│ │ Billing │ │ Protected │ │ │ │
│ │ Support │ │ AuthDebug │ │ │ │
│ │ Settings │ │ │ │ │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
├─────────────────────────────────────────────────────────┤
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Routing │ │ Utils │ │ Assets │ │
│ │ │ │ │ │ │ │
│ │ React Router│ │ Date-fns │ │ TailwindCSS │ │
│ │ Navigation │ │ Lucide Icons│ │ Recharts │ │
│ │ Protected │ │ Axios │ │ │ │
│ │ Routes │ │ React Query │ │ │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
└─────────────────────────────────────────────────────────┘
Key Features:
┌─────────────────────────────────────────────────────────┐
│ Backend Layer │
├─────────────────────────────────────────────────────────┤
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Routes │ │ Middleware │ │ Services │ │
│ │ │ │ │ │ │ │
│ │ Auth │ │ Auth │ │ WebSocket │ │
│ │ Users │ │ Rate Limit │ │ Database │ │
│ │ Dashboard │ │ Error Handle│ │ Logger │ │
│ │ Hosting │ │ CORS │ │ Validation │ │
│ │ Billing │ │ Helmet │ │ │ │
│ │ Support │ │ │ │ │ │
│ │ Settings │ │ │ │ │ │
│ │ Health │ │ │ │ │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
├─────────────────────────────────────────────────────────┤
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Database │ │ Utils │ │ Security │ │
│ │ │ │ │ │ │ │
│ │ PostgreSQL │ │ Error Utils │ │ JWT Auth │ │
│ │ Redis │ │ Logger │ │ Bcrypt │ │
│ │ Models │ │ Validation │ │ Helmet │ │
│ │ Migrations │ │ Helpers │ │ Rate Limit │ │
│ │ Seeds │ │ │ │ │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
└─────────────────────────────────────────────────────────┘
Key Features:
WebSocket support (planned)
│ └─────────────┘ └─────────────┘ └─────────────┘ │
├─────────────────────────────────────────────────────────┤
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Services │ │ Models │ │ Utils │ │
│ │ │ │ │ │ │ │
│ │ AuthSvc │ │ User │ │ Logger │ │
│ │ EmailSvc │ │ Server │ │ Validator │ │
│ │ WebSocket │ │ Invoice │ │ Encryption │ │
│ │ BackupSvc │ │ Ticket │ │ Helpers │ │
│ │ Analytics │ │ ActivityLog │ │ Errors │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
└─────────────────────────────────────────────────────────┘
Key Features:
┌─────────────────────────────────────────────────────────┐
│ Database Layer │
├─────────────────────────────────────────────────────────┤
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Core │ │ Business │ │ System │ │
│ │ Tables │ │ Tables │ │ Tables │ │
│ │ │ │ │ │ │ │
│ │ users │ │ servers │ │ activity_ │ │
│ │ sessions │ │ invoices │ │ logs │ │
│ │ permissions │ │ tickets │ │ system_ │ │
│ │ roles │ │ messages │ │ settings │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
├─────────────────────────────────────────────────────────┤
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Indexes │ │ Constraints │ │ Triggers │ │
│ │ │ │ │ │ │ │
│ │ Primary │ │ Foreign │ │ Audit Trail │ │
│ │ Unique │ │ Check │ │ Auto Update │ │
│ │ Composite │ │ Not Null │ │ Cascading │ │
│ │ Partial │ │ Default │ │ Validation │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
└─────────────────────────────────────────────────────────┘
Key Features:
┌─────────────────────────────────────────────────────────┐
│ Cache Layer │
├─────────────────────────────────────────────────────────┤
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Sessions │ │ Data │ │ System │ │
│ │ │ │ Cache │ │ Cache │ │
│ │ │ │ │ │ │ │
│ │ User Tokens │ │ API Results │ │ Config │ │
│ │ Login State │ │ Dashboard │ │ Settings │ │
│ │ Permissions │ │ Statistics │ │ Templates │ │
│ │ CSRF Tokens │ │ User Lists │ │ Metadata │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
├─────────────────────────────────────────────────────────┤
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Pub/Sub │ │ Locks │ │ Metrics │ │
│ │ │ │ │ │ │ │
│ │ Real-time │ │ Distributed │ │ Performance │ │
│ │ Events │ │ Locks │ │ Counters │ │
│ │ Notifications│ │ Rate Limits │ │ Analytics │ │
│ │ Updates │ │ Mutex │ │ Monitoring │ │
│ │ Messaging │ │ Semaphores │ │ Health │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
└─────────────────────────────────────────────────────────┘
Key Features:
┌─────────┐ Login ┌─────────┐ Validate ┌─────────┐ Token ┌─────────┐
│ Frontend│──────►│ Backend │──────►│ Database│──────►│ Backend │──────►│ Frontend│
└─────────┘ └─────────┘ └─────────┘ └─────────┘ └─────────┘
│ │ │ │ │
│ │ │ │ │
▼ ▼ ▼ ▼ ▼
┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐
│ Session │ │ JWT Gen │ │ User │ │ Cache │ │ Storage │
│ Store │ │ Service │ │ Lookup │ │ Token │ │ Token │
└─────────┘ └─────────┘ └─────────┘ └─────────┘ └─────────┘
┌─────────┐ Request ┌─────────┐ Auth ┌─────────┐ Query ┌─────────┐ Response
│ Frontend│──────►│ Nginx │──────►│ Backend │──────►│ Database│──────►│ Backend │──────►│ Frontend│
└─────────┘ └─────────┘ └─────────┘ └─────────┘ └─────────┘ └─────────┘
│ │ │ │ │
│ │ │ │ │
▼ ▼ ▼ ▼ ▼
┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐
│ Browser │ │ SSL/TLS │ │ Rate │ │ Query │ │ Cache │
│ Cache │ │ Terminate│ │ Limit │ │ Builder│ │ Layer │
└─────────┘ └─────────┘ └─────────┘ └─────────┘ └─────────┘
┌─────────┐ Event ┌─────────┐ Publish ┌─────────┐ Push ┌─────────┐
│ Backend │──────►│ Redis │──────►│ Pub/Sub │──────►│ Frontend│
│ Service │ │ Channel │ │ System │ │ Client │
└─────────┘ └─────────┘ └─────────┘ └─────────┘
│ │ │ │
│ │ │ │
▼ ▼ ▼ ▼
┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐
│ Event │ │ Message │ │ WebSocket│ │ React │
│ Handler │ │ Queue │ │ Server │ │ Update │
└─────────┘ └─────────┘ └─────────┘ └─────────┘
┌─────────────────────────────────────────────────────────┐
│ Development Stack │
├─────────────────────────────────────────────────────────┤
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Frontend │ │ Backend │ │ Database │ │
│ │ (Vite Dev) │ │ (Nodemon) │ │ (PostgreSQL)│ │
│ │ Port: 3000 │ │ Port: 3003 │ │ Port: 5432 │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Hot Reload │ │ Auto Restart│ │ Local DB │ │
│ │ Fast Refresh│ │ TypeScript │ │ Development │ │
│ │ DevTools │ │ Debug Mode │ │ Seed Data │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
└─────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────┐
│ Production Stack │
├─────────────────────────────────────────────────────────┤
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Nginx │ │ Backend │ │ Database │ │
│ │ (Reverse │ │ (PM2) │ │ (PostgreSQL)│ │
│ │ Proxy) │ │ Cluster │ │ Pool) │ │
│ │ Port: 80/443│ │ Port: 3003 │ │ Port: 5432 │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ SSL/TLS │ │ Load │ │ Redis │ │
│ │ Certificates│ │ Balancer │ │ Cluster │ │
│ │ Security │ │ Health │ │ Session │ │
│ │ Headers │ │ Checks │ │ Store │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
└─────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────┐
│ Docker Compose Stack │
├─────────────────────────────────────────────────────────┤
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Frontend │ │ Backend │ │ Database │ │
│ │ Container │ │ Container │ │ Container │ │
│ │ Nginx + │ │ Node.js │ │ PostgreSQL │ │
│ │ React │ │ Express │ │ Data Volume │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Redis │ │ Networks │ │ Volumes │ │
│ │ Container │ │ Bridge │ │ Persistent │ │
│ │ Cache │ │ Overlay │ │ Storage │ │
│ │ Session │ │ Isolation │ │ Backups │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
└─────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────┐
│ Authentication Stack │
├─────────────────────────────────────────────────────────┤
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ JWT Tokens │ │ Password │ │ Session │ │
│ │ Signed │ │ Hashing │ │ Management │ │
│ │ Encrypted │ │ bcrypt │ │ Redis Store │ │
│ │ TTL 24h │ │ 12 rounds │ │ Blacklist │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ RBAC │ │ 2FA │ │ Rate │ │
│ │ Roles │ │ Optional │ │ Limiting │ │
│ │ Permissions │ │ TOTP/Email │ │ Per IP/User │ │
│ │ Middleware │ │ Backup Codes│ │ Redis Store │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
└─────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────┐
│ Data Protection Stack │
├─────────────────────────────────────────────────────────┤
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Encryption │ │ Input │ │ Output │ │
│ │ At Rest │ │ Validation │ │ Sanitization│ │
│ │ AES-256 │ │ Joi Schemas │ │ XSS Protection│ │
│ │ Database │ │ Type Safety │ │ HTML Purify │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Network │ │ Audit │ │ Monitoring │ │
│ │ Security │ │ Logging │ │ Alerting │ │
│ │ SSL/TLS │ │ Activity │ │ Anomaly │ │
│ │ Headers │ │ Tracking │ │ Detection │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
└─────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────┐
│ Caching Architecture │
├─────────────────────────────────────────────────────────┤
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Browser │ │ CDN │ │ Application │ │
│ │ Cache │ │ Edge Cache │ │ Cache │ │
│ │ HTTP Cache │ │ Static │ │ Redis │ │
│ │ Local │ │ Assets │ │ API Results │ │
│ │ Storage │ │ Distribution│ │ Sessions │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Database │ │ Query │ │ Cache │ │
│ │ Query │ │ Optimization│ │ Invalidation│ │
│ │ Cache │ │ Indexing │ │ TTL │ │
│ │ Result │ │ Connection │ │ Events │ │
│ │ Sets │ │ Pooling │ │ Tags │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
└─────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────┐
│ Scalability Architecture │
├─────────────────────────────────────────────────────────┤
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Horizontal │ │ Database │ │ Micro │ │
│ │ Scaling │ │ Scaling │ │ Services │ │
│ │ Load │ │ Read │ │ Service │ │
│ │ Balancer │ │ Replicas │ │ Discovery │ │
│ │ Health │ │ Sharding │ │ API Gateway │ │
│ │ Checks │ │ Partitioning│ │ Circuit │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Event │ │ Message │ │ Async │ │
│ │ Driven │ │ Queues │ │ Processing │ │
│ │ Architecture│ │ Redis/RabbitMQ│ │ Background │ │
│ │ Pub/Sub │ │ Worker │ │ Jobs │ │
│ │ Loose │ │ Processes │ │ Scheduled │ │
│ │ Coupling │ │ Tasks │ │ Tasks │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
└─────────────────────────────────────────────────────────┘
hostingco-system/
├── frontend/ # React frontend
│ ├── src/
│ │ ├── components/ # Reusable UI components
│ │ ├── pages/ # Page components
│ │ ├── hooks/ # Custom React hooks
│ │ ├── services/ # API services
│ │ ├── utils/ # Utility functions
│ │ └── types/ # TypeScript types
│ ├── public/ # Static assets
│ └── package.json
├── backend/ # Node.js backend
│ ├── src/
│ │ ├── routes/ # API routes
│ │ ├── controllers/ # Request handlers
│ │ ├── services/ # Business logic
│ │ ├── models/ # Data models
│ │ ├── middleware/ # Express middleware
│ │ ├── utils/ # Utility functions
│ │ └── types/ # TypeScript types
│ ├── migrations/ # Database migrations
│ ├── seeds/ # Database seeds
│ └── package.json
├── shared/ # Shared code
│ ├── src/
│ │ ├── types/ # Shared TypeScript types
│ │ ├── constants/ # Shared constants
│ │ └── utils/ # Shared utilities
│ └── package.json
├── docs/ # Documentation
├── scripts/ # Build and deployment scripts
└── docker-compose.yml # Container configuration
┌─────────────────────────────────────────────────────────┐
│ Git Workflow │
├─────────────────────────────────────────────────────────┤
│ main (production) │
│ ├── develop (integration) │
│ │ ├── feature/user-authentication │
│ │ ├── feature/server-management │
│ │ ├── feature/billing-system │
│ │ └── hotfix/security-patch │
│ └── release/v1.0.0 (tags) │
├─────────────────────────────────────────────────────────┤
│ Branch Protection: │
│ - Main: Protected, PR required │
│ - Develop: PR required, CI passes │
│ - Feature: No direct push, code review required │
└─────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────┐
│ Logging Architecture │
├─────────────────────────────────────────────────────────┤
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Application │ │ System │ │ Security │ │
│ │ Logs │ │ Logs │ │ Logs │ │
│ │ Winston │ │ Syslog │ │ Audit Trail │ │
│ │ Structured │ │ Journal │ │ Events │ │
│ │ JSON │ │ Systemd │ │ Alerts │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Log │ │ Log │ │ Log │ │
│ │ Aggregation │ │ Analysis │ │ Alerting │ │
│ │ ELK Stack │ │ Splunk │ │ PagerDuty │ │
│ │ Fluentd │ │ Graylog │ │ Slack │ │
│ │ Filebeat │ │ Custom │ │ Email │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
└─────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────┐
│ Metrics Architecture │
├─────────────────────────────────────────────────────────┤
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Application │ │ Infrastructure│ │ Business │ │
│ │ Metrics │ │ Metrics │ │ Metrics │ │
│ │ Response │ │ CPU/Memory │ │ User │ │
│ │ Time │ │ Disk/Network│ │ Activity │ │
│ │ Error Rate │ │ Uptime │ │ Revenue │ │
│ │ Throughput │ │ Health │ │ Conversions │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Metrics │ │ Dashboard │ │ Alerting │ │
│ │ Collection │ │ Visualization│ │ Rules │ │
│ │ Prometheus │ │ Grafana │ │ Alertmanager│ │
│ │ StatsD │ │ Kibana │ │ Custom │ │
│ │ Custom │ │ Custom │ │ Integration │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
└─────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────┐
│ Microservices Architecture │
├─────────────────────────────────────────────────────────┤
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Auth │ │ User │ │ Server │ │
│ │ Service │ │ Service │ │ Service │ │
│ │ JWT/2FA │ │ Profile │ │ Management │ │
│ │ Sessions │ │ Management │ │ Monitoring │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Billing │ │ Support │ │ Notification│ │
│ │ Service │ │ Service │ │ Service │ │
│ │ Invoices │ │ Tickets │ │ Email/SMS │ │
│ │ Payments │ │ Chat │ │ Push │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
└─────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────┐
│ Cloud-Native Architecture │
├─────────────────────────────────────────────────────────┤
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Kubernetes │ │ Service │ │ Serverless │ │
│ │ Orchestration│ │ Mesh │ │ Functions │ │
│ │ Pods │ │ Istio/Linkerd│ │ AWS Lambda │ │
│ │ Services │ │ Traffic │ │ Azure │ │
│ │ Ingress │ │ Management │ │ Functions │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Auto │ │ GitOps │ │ Observability│ │
│ │ Scaling │ │ Deployment │ │ Platform │ │
│ │ HPA/VPA │ │ ArgoCD │ │ OpenTelemetry│ │
│ │ Cluster │ │ Flux │ │ Jaeger │ │
│ │ Autoscaler │ │ Helm │ │ Prometheus │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
└─────────────────────────────────────────────────────────┘
Last updated: $(date)