How anubhav126/reverse-proxy works
Main Components
• Primary Process (Master): This node is responsible for setting up the core HTTP server, spawning worker processes, and handling inter-process communication.
• Worker Processes: These are the child processes that deal with individual HTTP requests, performing routing based on configuration rules, proxying requests to upstream servers, and validating messages.
• Configuration Module: Includes configuration files (config.yaml and the schema-related files in both src/ and dist/ directories) that determine routing rules and proxy targets.
• External Dependencies: Include Node.js core modules (such as cluster and HTTP), as well as external libraries listed in package.json.
• Upstream Servers: Although not directly implemented in the code, these represent external services to which the load balancer proxies incoming requests.
Relationships and Interactions
• The Primary Process initializes the system, loads the configuration, and then spawns multiple Worker Processes using Node’s clustering capabilities.
• Worker Processes then engage in routing and proxying requests to the appropriate Upstream Servers based on the configuration rules.
Architectural Patterns and Design Principles
• Multi-Process Architecture using Node.js clustering to improve resource usage.
• Reverse Proxy Design: Directing incoming requests to the appropriate upstream server.
• Configuration-Driven Routing: Emphasis on schema validation for both server and configuration settings to ensure robustness.
• Use of TypeScript to ensure type safety, shown by the presence of tsconfig.json and .ts files.
Relevant Technologies/Frameworks
• Node.js (built-in cluster, HTTP modules)
• TypeScript for type safety
• JSON/Schema validation libraries (inferred from config-schema and server-schema files)
• Possibly external HTTP proxy libraries if implemented
Elements
• Incoming HTTP requests first hitting the Primary Process.
• The distribution of requests from the Primary Process to each Worker Process (round-robin).
• Worker Processes forwarding the requests to appropriate Upstream Servers.
• Callout sections for the schema validation steps (configuration and server schema) and note where error handling comes into play.