# 42-adbouras/webserv-1337med architecture

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

- Interactive diagram: https://gitdiagram.com/42-adbouras/webserv-1337med
- Repository: https://github.com/42-adbouras/webserv-1337med

## Overview

##### Project type and purpose
- This is a standalone, high-performance HTTP server written in C++.
- Purpose: listen on TCP sockets, parse HTTP requests, serve static files (in webserv/www), execute CGI scripts, handle errors, and send back HTTP responses.

##### File structure
- Top-level “webserv” directory contains:
- configs/ (config.conf)
- includes/ (public headers: CGI, Config, Lexer, Utils, request/response, serverHeader)
- sources/ (implementation: main, parser, request, response, server, CGI, error handlers)
- www/ (static assets: HTML, CSS, images, default error pages)
- Pattern: clear separation of concerns—configuration parsing, request processing, response building, server networking, CGI handling.
- Build artifacts driven by Makefile under webserv/Makefile.

##### README
- Confirms: it’s an HTTP server—receives requests, returns web content.

##### Elements
[Client Browser] → [SocketManager/Listener] → [Request Parser] → [Router] → {Static File Server | CGI Handler} → [Response Builder] → [SocketManager] → [Client]
- Networking (blue)
- Parsing & Config (yellow)
- Business logic (green)
- IO & CGI (orange)
- Interactions (fork/exec, file read, config load).

##### Final guidance
- Essential modules from the file tree.
- Use consistent naming matching headers/sources (e.g., “Config,” “Lexer,” “Utils”).
- Notes on ports, timeouts, and config locations if needed.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client interacts
    ClientBrowser["Client Browser"]:::external

    subgraph "Networking Layer"
        direction TB
        Listener["Listener"]:::networking
        SocketManager["SocketManager"]:::networking
        ClientHandler["Client Connection Handler"]:::networking
    end

    subgraph "Startup & Config Parsing"
        direction TB
        ConfigLoader["Configuration Loader"]:::parsing
        Lexer["Lexer"]:::parsing
        ParserUtils["Parser Utils"]:::parsing
    end

    subgraph "Request Processing"
        direction TB
        RequestParser["Request Parser"]:::parsing
    end

    subgraph "Routing & Business Logic"
        direction TB
        Router["Router & Resource Resolver"]:::business
        CGIHandler["CGI Handler"]:::io
        StaticServer["Static File Server"]:::io
    end

    subgraph "Response & Error Handling"
        direction TB
        ResponseBuilder["Response Builder"]:::business
        ErrorHandler["Error Handler"]:::error
    end

    %% Data flow
    ClientBrowser -->|opens TCP connection| Listener
    Listener --> SocketManager
    SocketManager --> ClientHandler
    ClientHandler -->|reads raw data| RequestParser

    RequestParser --> Router
    Router -->|static content| StaticServer
    Router -->|CGI request| CGIHandler
    Router -->|error or missing| ErrorHandler

    StaticServer --> ResponseBuilder
    CGIHandler --> ResponseBuilder
    ErrorHandler --> ResponseBuilder

    ResponseBuilder -->|writes to socket| SocketManager
    SocketManager -->|sends response| ClientBrowser

    %% Startup flow
    Listener --> ConfigLoader
    ConfigLoader --> Lexer
    Lexer --> ParserUtils

    %% Click Events
    click SocketManager "https://github.com/42-adbouras/webserv-1337med/blob/main/webserv/includes/serverHeader/SocketManager.hpp"
    click SocketManager "https://github.com/42-adbouras/webserv-1337med/blob/main/webserv/sources/server/SocketManager.cpp"
    click ClientHandler "https://github.com/42-adbouras/webserv-1337med/blob/main/webserv/includes/serverHeader/Client.hpp"
    click ClientHandler "https://github.com/42-adbouras/webserv-1337med/blob/main/webserv/sources/server/Client.cpp"
    click ConfigLoader "https://github.com/42-adbouras/webserv-1337med/blob/main/webserv/includes/Config.hpp"
    click Lexer "https://github.com/42-adbouras/webserv-1337med/blob/main/webserv/includes/Lexer.hpp"
    click ConfigLoader "https://github.com/42-adbouras/webserv-1337med/blob/main/webserv/sources/parser/Config.cpp"
    click Lexer "https://github.com/42-adbouras/webserv-1337med/blob/main/webserv/sources/parser/Lexer.cpp"
    click ParserUtils "https://github.com/42-adbouras/webserv-1337med/blob/main/webserv/sources/parser/ParserUtils.cpp"
    click RequestParser "https://github.com/42-adbouras/webserv-1337med/blob/main/webserv/includes/request.hpp"
    click RequestParser "https://github.com/42-adbouras/webserv-1337med/blob/main/webserv/sources/request/request.cpp"
    click ParserUtils "https://github.com/42-adbouras/webserv-1337med/blob/main/webserv/sources/request/utils.cpp"
    click Router "https://github.com/42-adbouras/webserv-1337med/blob/main/webserv/includes/serverHeader/Server.hpp"
    click Router "https://github.com/42-adbouras/webserv-1337med/blob/main/webserv/sources/server/server.cpp"
    click Router "https://github.com/42-adbouras/webserv-1337med/blob/main/webserv/includes/serverHeader/ServerUtils.hpp"
    click Router "https://github.com/42-adbouras/webserv-1337med/blob/main/webserv/includes/serverHeader/ServerExcept.hpp"
    click Router "https://github.com/42-adbouras/webserv-1337med/blob/main/webserv/sources/server/ServerExcept.cpp"
    click StaticServer "https://github.com/42-adbouras/webserv-1337med/tree/main/webserv/www/"
    click CGIHandler "https://github.com/42-adbouras/webserv-1337med/blob/main/webserv/includes/CGI.hpp"
    click CGIHandler "https://github.com/42-adbouras/webserv-1337med/blob/main/webserv/sources/cgi/CGI.cpp"
    click ResponseBuilder "https://github.com/42-adbouras/webserv-1337med/blob/main/webserv/includes/response.hpp"
    click ResponseBuilder "https://github.com/42-adbouras/webserv-1337med/blob/main/webserv/sources/response/response.cpp"
    click ErrorHandler "https://github.com/42-adbouras/webserv-1337med/blob/main/webserv/sources/errors/req_errors.cpp"
    click ErrorHandler "https://github.com/42-adbouras/webserv-1337med/tree/main/webserv/www/defaultErrorPages/"

    %% Styles
    classDef networking fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef parsing fill:#FFFF99,stroke:#333,stroke-width:1px
    classDef business fill:#90EE90,stroke:#333,stroke-width:1px
    classDef io fill:#FFDAB9,stroke:#333,stroke-width:1px
    classDef error fill:#FFB6C1,stroke:#333,stroke-width:1px
    classDef external fill:#E0E0E0,stroke:#333,stroke-width:1px,stroke-dasharray: 5 5
```
