How tqthy/cdn-for-ecommerce works
Main Components
• cdn-client: This is the frontend component (built with Vite, React/TypeScript) that serves static assets and user interfaces.
• load-balancer: Contains Dockerfile, Nginx configuration (njs scripts), and Lua scripts. It is responsible for managing and routing incoming requests across available servers.
• edge-server: Also built using Nginx with enhanced Lua and NJS scripts. This layer likely handles caching strategies, request filtering, and can serve as a proxy between the load-balancer and the origin server.
• origin: A NestJS-based backend (as seen in the “origin” folder with app.module.ts and several sub-modules including file, minio, and redis integrations). This is the core API and business logic layer that processes file uploads, interacts with storage backends (Minio integration is indicated), and handles event notifications (webhooks).
• storage: Although minimal in content, this directory represents the file storage system or mount point for static content.
• monitoring: Includes Grafana (preconfigured with plugins and a database) and Prometheus configurations to track system performance and issues.
• (Additional Test/Utility Directories): Directories like [test]tc and load_tests indicate scripts for testing the system, but these can be treated as ancillary support tools.
Relationships and Data Flow
• User requests (originating from a web browser) first encounter the load-balancer.
• The load-balancer routes these requests—via defined Nginx/Lua logic—to the edge-server, which implements caching or rapid response layers.
• If content isn’t cached or needs processing, the edge-server forwards requests to the origin server where business logic (via NestJS modules) comes into play.
• The origin server interacts with external services, such as:
• Object storage (evidenced by the minio/minio-storage modules and webhook instructions indicating integration with a Minio client),
• Caching or state mechanisms (via redis in the origin module and possibly through Lua scripts in the servers).
• The frontend (cdn-client) is served separately—it may be delivered by the load-balancer or edge-server and communicates with the backend over APIs.
• Monitoring components (Grafana and Prometheus) collect system metrics from the various containers and infrastructure components.
Architectural Patterns and Design Principles
• Containerized Microservices: Each core component runs in its own container (docker-compose indicates orchestration).
• Separation of Concerns: There is a clear isolation between the frontend (presentation layer), edge (caching/proxy), load-balancer (traffic management), and origin/backend (business logic) layers.
• Event-driven / Webhook Integration: The README mentions webhooks for Minio events.
• Caching and Smart Routing: Use of Nginx with Lua and NJS in both edge-server and load-balancer shows dynamic request handling and caching logic.
• Containers and Interactions:
• Docker orchestration by indicating that all components run within a Docker network (perhaps as a surrounding “Docker Compose” boundary).
• If possible, include annotations with key configuration details (e.g., “Nginx + Lua scripts” on the edge-server and load-balancer).
• Message flow when static assets and API requests are processed.
• Optionally, mention that internal modules in the Origin (e.g., file handling, minio integration, and caching via Redis) are key sub-components, which could be detailed in a zoomed-in view for further clarity.