# krzysztofmarciniak/minimalistic-posix-c-http-server architecture

> Architecture diagram of the GitHub repository krzysztofmarciniak/minimalistic-posix-c-http-server, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/krzysztofmarciniak/minimalistic-posix-c-http-server
- Repository: https://github.com/krzysztofmarciniak/minimalistic-posix-c-http-server

## Overview

##### Main Components
- Server Core: Represented by src/main.c, this is where the primary logic of the HTTP server resides.
- Configuration Module: Located in src/config.h, it defines critical server settings such as the port number and the routing table mapping URL routes to HTML files.
- Static Content: Files like index.html and contact.html that are being served as responses based on the configured routes.
- Build & Deployment: The Makefile is used to compile the project, and the README outlines how to run the compiled server.
- External Interactions: Clients (web browsers or HTTP clients) that send requests and receive responses.

##### Relationships & Interactions
- Request Handling: The incoming HTTP request first reaches the server core (src/main.c), where the request is parsed and routing decisions are made.
- Routing Logic: From the server, read the routing table in src/config.h to determine which static file corresponds to the URL.
- File Serving: The static HTML files (index.html, contact.html, etc.) are fetched and sent back as HTTP responses.
- Use of POSIX System Calls & Threads: Illustrate that network handling (socket setup, listening) and concurrency (via pthreads) are key to the design, though these details may be internal to the server core.

##### Architectural Patterns & Design Principles
- Single Process, Multi-threaded Design: Indicates that while the server operates as a single process, it may create multiple pthreads to handle client connections concurrently.
- Configuration-driven Routing: Emphasizes the separation of concerns by using a dedicated configuration module (src/config.h) for defining server behavior and routing.
- Static Content Serving: The design focuses on serving pre-defined static files rather than dynamic content generation.

##### Relevant Technologies
- Programming Language & Framework: C with POSIX system calls and pthreads.
- Operating System: Designed for POSIX-compliant systems.
- Build Tool: Makefile for compiling the project.
- HTTP Protocol aspects: Emphasize that the server is designed to handle basic HTTP GET requests and returns standard HTTP status codes (e.g., 200 OK, 404 Not Found).

## Diagram (Mermaid)

```mermaid
graph TD
    %% External Client
    CLIENT["Client (Browser)"]:::client

    %% Core Server Subgraph
    subgraph "Core Server"
        SC["HTTP Server (src/main.c)"]:::server
        CONFIG["Routing Config (src/config.h)"]:::config
    end

    %% Static Content Subgraph
    subgraph "Static Content"
        INDEX["Static File: index.html"]:::static
        CONTACT["Static File: contact.html"]:::static
    end

    %% Build & Deployment Subgraph
    subgraph "Build & Deployment"
        MAKEFILE["Build: Makefile"]:::build
        README["Documentation: README.md"]:::build
    end

    %% Flow Connections
    CLIENT -->|"HTTP_GET"| SC
    SC -->|"reads"| CONFIG
    SC -->|"routes_to"| INDEX
    SC -->|"routes_to"| CONTACT
    INDEX -->|"HTTP_Response"| CLIENT
    CONTACT -->|"HTTP_Response"| CLIENT

    %% Build & Deployment Influence
    MAKEFILE -->|"compiles"| SC
    README ---|"describes"| SC

    %% Annotation for internal mechanisms
    SC ---|"uses_POSIX+pthreads"| SC

    %% Click Events
    click SC "https://github.com/krzysztofmarciniak/minimalistic-posix-c-http-server/blob/main/src/main.c"
    click CONFIG "https://github.com/krzysztofmarciniak/minimalistic-posix-c-http-server/blob/main/src/config.h"
    click INDEX "https://github.com/krzysztofmarciniak/minimalistic-posix-c-http-server/blob/main/index.html"
    click CONTACT "https://github.com/krzysztofmarciniak/minimalistic-posix-c-http-server/blob/main/contact.html"
    click MAKEFILE "https://github.com/krzysztofmarciniak/minimalistic-posix-c-http-server/tree/main/Makefile"
    click README "https://github.com/krzysztofmarciniak/minimalistic-posix-c-http-server/blob/main/README.md"

    %% Styles
    classDef client fill:#FFE680,stroke:#333,stroke-width:2px;
    classDef server fill:#FF9999,stroke:#333,stroke-width:2px;
    classDef config fill:#99CCFF,stroke:#333,stroke-width:2px;
    classDef static fill:#B3FFB3,stroke:#333,stroke-width:2px;
    classDef build fill:#D9B3FF,stroke:#333,stroke-width:2px;
```
