How mcvyp/rust-webserver works
Project type and purpose
• This is a small, single-binary web server written in Rust.
• It provides static file serving (e.g., “index.html” and “404.html”) over HTTP using a thread pool for concurrency.
File structure
• Top-level files:
• Cargo.toml / Cargo.lock — Rust package metadata and dependencies (threadpool, num_cpus)
• README.md — very brief description (“A basic web server with Rust”)
• index.html, 404.html — static assets served by the server
• src directory:
• src/bin/main.rs — entry point; starts the listener and thread pool
• src/lib.rs — core library: contains listener, connection handler, routing logic, thread pool wrapper
• There are no separate frontend/backend directories; this is a pure backend service.
README for additional insights
• It confirms the project is a “basic web server.”
• No extra architecture notes are provided.
Main components
a. External Web Client (Browser / HTTP Client)
b. TCP Listener (accepts incoming HTTP connections)
c. Thread Pool Manager (manages a fixed pool of worker threads)
d. Request Handler (parses HTTP requests, matches routes)
e. Static File Storage (filesystem containing index.html, 404.html)
f. Rust Standard Library & External Crates (threadpool, num_cpus)
Relationships and data flow
• Client → (HTTP request) → TCP Listener
• TCP Listener → dispatch → Thread Pool Manager
• Thread Pool Manager → worker thread → Request Handler
• Request Handler → filesystem read → Static File Storage
• Static File Storage → file data → Request Handler
• Request Handler → (HTTP response) → Client
Architectural patterns & design principles
• Concurrency via a fixed-size thread pool (minimize thread-creation overhead)
• Separation of concerns:
• main.rs only bootstraps listener and pool
• lib.rs contains pure logic (handler, routing, pool abstraction)
• Dependency injection: the thread pool is configured using system CPU count (via num_cpus)
Relevant technologies & libraries
• Rust’s std::net for TCP
• threadpool crate for concurrency
• num_cpus to size the pool
• std::fs for file I/O