# devdha/webserv architecture

> Architecture diagram of the GitHub repository devdha/webserv, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/devdha/webserv
- Repository: https://github.com/devdha/webserv

## Overview

##### Project type and purpose
- This is a standalone HTTP web‐server (“webserv”) written in C++. It reads configuration files, listens on one or more sockets, parses HTTP requests, dispatches them to either static file serving or CGI executables, constructs HTTP responses, logs activity, and sends responses back to clients.

##### File structure
- Top‐level:
- config/ : server‐ and location‐level configuration files (.conf)
- / : all public headers (Parser, Scanner, Config*, Server, Processor, CgiHandler, FileManager, etc.)
- src/     : implementation (.cpp), including main.cpp which spins up Webserv
- practice/ : sample socket/select code snippets (prototype / experimentation)
- test/    : CGI and end‐to‐end testers
- www/     : sample document root (static files, directories, CGI results)
- Key patterns: single process, event‐driven (select‐based) reactor, modular separation (Config loader → Server objects → Connection / Request / Response modules → CGI or static).

##### Additional notes
Layer 1: Clients
Layer 2: Network / Reactor
Layer 3: Webserv Core (Config, Parser, Processor)
Layer 4: Resources (File System, CGI scripts)
Layer 5: Logging / Monitoring
- Concurrent or blocking points (e.g., fork/exec in CgiHandler)

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Layer 1: Clients"
        Client["Clients (Web Browsers / HTTP Clients)"]:::network
    end

    subgraph "Layer 2: Network / Reactor"
        Reactor["Reactor (select loop)"]:::network
    end

    subgraph "Layer 3: Webserv Core"
        Main["Main Entry Point (main.cpp)"]:::core
        Config["Config Loader & Parser"]:::config
        ServerMgr["Server Manager"]:::core
        Dispatcher["Connection/Request Dispatcher"]:::core
        Processor["Request Processor"]:::core
        FileMgr["Static File Manager"]:::core
        Cgi["CGI Handler"]:::core
        Util["Utilities & Response Builder"]:::core
    end

    subgraph "Layer 4: Resources"
        Confs["Configuration Files (config/*.conf)"]:::resource
        Files["File System (www/)"]:::resource
        CGIexec["External CGI Scripts"]:::resource
    end

    subgraph "Layer 5: Logging"
        Logger["Logger"]:::logger
    end

    Client -->|"HTTP Request"| Reactor
    Reactor -->|"New Connection"| ServerMgr
    Main -->|"initialize"| Config
    Main -->|"start reactor"| Reactor
    Config -->|"load config"| ServerMgr
    Confs --> Config

    Reactor -->|"FD ready"| Dispatcher
    ServerMgr --> Reactor

    Dispatcher -->|"Request Object"| Processor
    Processor -->|"static request"| FileMgr
    Processor -->|"dynamic request"| Cgi

    Files --> FileMgr
    CGIexec --> Cgi

    FileMgr -->|"file bytes"| Util
    Cgi -->|"stdout"| Util

    Util -->|"HTTP Response"| Reactor
    Reactor -->|"send"| Client

    Dispatcher --> Logger
    Processor --> Logger
    Util --> Logger

    classDef network fill:#ADD8E6,stroke:#000;
    classDef core fill:#90EE90,stroke:#000;
    classDef config fill:#FFA07A,stroke:#000;
    classDef resource fill:#FFD700,stroke:#000;
    classDef logger fill:#D3D3D3,stroke:#000;

    click Main "https://github.com/devdha/webserv/blob/main/src/main.cpp"
    click Config "https://github.com/devdha/webserv/blob/main/include/Config.hpp"
    click Config "https://github.com/devdha/webserv/blob/main/include/ConfigCommon.hpp"
    click Config "https://github.com/devdha/webserv/blob/main/include/ConfigLocation.hpp"
    click Config "https://github.com/devdha/webserv/blob/main/include/ConfigServer.hpp"
    click Config "https://github.com/devdha/webserv/blob/main/include/Scanner.hpp"
    click Config "https://github.com/devdha/webserv/blob/main/include/Parser.hpp"
    click Config "https://github.com/devdha/webserv/blob/main/src/Config.cpp"
    click Config "https://github.com/devdha/webserv/blob/main/src/ConfigCommon.cpp"
    click Config "https://github.com/devdha/webserv/blob/main/src/ConfigLocation.cpp"
    click Config "https://github.com/devdha/webserv/blob/main/src/ConfigServer.cpp"
    click Config "https://github.com/devdha/webserv/blob/main/src/Scanner.cpp"
    click Config "https://github.com/devdha/webserv/blob/main/src/Parser.cpp"
    click ServerMgr "https://github.com/devdha/webserv/blob/main/include/Server.hpp"
    click ServerMgr "https://github.com/devdha/webserv/blob/main/src/Server.cpp"
    click Reactor "https://github.com/devdha/webserv/blob/main/include/Webserv.hpp"
    click Reactor "https://github.com/devdha/webserv/blob/main/src/Webserv.cpp"
    click Reactor "https://github.com/devdha/webserv/blob/main/src/Client.cpp"
    click Dispatcher "https://github.com/devdha/webserv/blob/main/include/Request.hpp"
    click Dispatcher "https://github.com/devdha/webserv/blob/main/include/Response.hpp"
    click Dispatcher "https://github.com/devdha/webserv/blob/main/src/Request.cpp"
    click Dispatcher "https://github.com/devdha/webserv/blob/main/src/Response.cpp"
    click Processor "https://github.com/devdha/webserv/blob/main/include/Processor.hpp"
    click Processor "https://github.com/devdha/webserv/blob/main/src/Processor.cpp"
    click FileMgr "https://github.com/devdha/webserv/blob/main/include/FileManager.hpp"
    click FileMgr "https://github.com/devdha/webserv/blob/main/src/FileManager.cpp"
    click Cgi "https://github.com/devdha/webserv/blob/main/include/CgiHandler.hpp"
    click Cgi "https://github.com/devdha/webserv/blob/main/src/CgiHandler.cpp"
    click Util "https://github.com/devdha/webserv/blob/main/include/Utilities.hpp"
    click Util "https://github.com/devdha/webserv/blob/main/src/Utilities.cpp"
    click Logger "https://github.com/devdha/webserv/blob/main/include/Log.hpp"
    click Logger "https://github.com/devdha/webserv/blob/main/src/Log.cpp"
    click Confs "https://github.com/devdha/webserv/tree/main/config/"
    click Files "https://github.com/devdha/webserv/tree/main/www/"
```
