How bryanmg20/hosting_project works
Project Type and Purpose
• This is a full-stack, container-driven web platform that lets authenticated users spin up isolated Docker containers for their projects.
• It comprises a React-based frontend UI, a Flask-based backend API, an Nginx reverse proxy, an external authentication/DB service (“Roble”), and Docker Engine for running user containers.
Key Architectural Components
a. Client (Browser)
• User interacts via a browser on three domains:
• ui.localhost → React UI
• api.localhost → Backend API
• <project>.user.localhost → User’s project container
b. Nginx Reverse Proxy
• Single entry point on port 80.
• Routes requests by hostname to UI, API, or the target project container.
• Implements rate limiting, header injection, WebSocket/SSE support, timeouts.
c. Frontend Service (UI)
• React + Vite app container on port 3000.
• Features: AuthContext (JWT), SSEContext (Server-Sent Events), pages/components for login, dashboard, project management.
d. Backend Service (API)
• Flask app container on port 5000.
• Modules:
• Auth (register/login, JWT generation, integration with Roble Auth)
• Projects (CRUD on projects, orchestrates container creation/deletion)
• Containers (start/stop/restart via Docker API)
• SSE (monitors Docker Engine, streams real-time events)
• Persists metadata in Roble DB via its REST API.
e. External Services
• Roble Auth: external identity provider
• Roble DB: external serverless database (users, projects tables)
f. Docker Engine & User Containers
• Docker Engine runs on the same host.
• For each new project, an image is built (downloaded from GitHub), a container is created and assigned a subdomain.
• Backend communicates with Docker Engine via its API to manage containers.
Data Flows and Interactions
• User → Browser
• Navigates to ui.localhost → Nginx → React UI
• UI calls API endpoints at api.localhost → Nginx → Flask API
• UI opens SSE connection to /sse/events → Nginx → Flask SSE module
• Flask API ↔ Roble Auth/DB
• Auth endpoints call external Roble Auth for signup/login
• Project endpoints call Roble DB REST API for CRUD on projects
• Flask API ↔ Docker Engine
• Container endpoints call Docker API to start/stop/restart containers
• Nginx → User Containers
• HTTP requests to <project>.user.localhost are forwarded to that container’s port.
• SSE Events
• Flask SSE monitors Docker Engine events & metrics and pushes them to the open SSE connection.
• React UI listens and updates charts/status in real time.
Architectural Patterns & Principles
• Layered (Reverse Proxy → UI/API → External Services → Docker Engine)
• Modular monolith in Flask (separate modules for auth, projects, containers, SSE)
• Event-driven updates via SSE rather than polling
• JWT-based stateless authentication with short-lived access tokens and refresh tokens
• Infrastructure as code via Docker Compose, container isolation per project