How elixir-mint/mint works
Project type and purpose
• Mint is an open-source, low-level HTTP client library written in Elixir/Erlang.
• It provides a “process-less” functional API for HTTP/1.1 and HTTP/2 connections over TCP or SSL.
File structure
• Top-level:
• mix.exs / mix.lock – Elixir project definition
• lib/mint – source code
• test – test suite including integration and proxy tests
• pages – markdown docs (e.g. Architecture.md)
• docker-compose.yml, Caddyfile – test infrastructure
• Inside lib/mint:
• application.ex – OTP application entry point
• core/ – connection struct, headers, utility code, transport interface
• http.ex – public HTTP API that delegates to http1 or http2
• http1/ – HTTP/1.1 framing, parsing, request/response logic
• http2/ – HTTP/2 frame definitions, state machine
• negotiate.ex – protocol negotiation logic (HTTP/1 vs HTTP/2)
• transport/ – adapters for TCP and SSL
• No “frontend” or “backend” directory: this is a library, not a full-stack app.
README for additional insights
• Emphasizes:
• Stateless API: every call returns a new connection struct
• Transparent HTTP/1 vs HTTP/2 selection
• Active socket mode, user handles OTP socket messages, then passes them to Mint.stream/2
• Mentions optional dependencies (castore), integration with higher-level clients like Finch.
a. Main components
• Public API layer: Mint.HTTP (connect, request, stream)
• Protocol negotiation: Mint.negotiate
• HTTP/1.1 stack: Mint.HTTP1 modules (frame assembly, parsing, request, response)
• HTTP/2 stack: Mint.HTTP2 modules (frame definitions, state machine)
• Core connection data model: Mint.Core.Conn, Headers, Types
• Transport adapters: Mint.Core.Transport.TCP and .SSL
• OTP application: Mint.Application (supervision tree, if any)
• External dependencies: Erlang :gen_tcp, :ssl, optional CA store (castore)
b. Relationships and interactions
1. Client code calls Mint.HTTP.connect -> invokes Mint.negotiate -> selects TCP or SSL transport -> returns Conn struct
2. Client calls Mint.HTTP.request with Conn -> forwards to HTTP1 or HTTP2 module -> builds frames, calls transport.send
3. Socket messages (:tcp, :ssl) arrive to user process -> passed to Mint.HTTP.stream(conn, message)
4. stream/2 dispatches to appropriate protocol module, parses frames into response parts
5. Updated Conn struct flows back to client for next operations
6. Under the hood, transport modules wrap :gen_tcp / :ssl calls
c. Architectural patterns and design principles
• Functional, immutable “connection struct” as state container
• No internal processes per connection (process-less)
• Layered protocol stacks: core → negotiation → http1/http2 → transport
• Clear separation of concerns: framing vs parsing vs transport
• OTP application structure for tests and supervision (minimal)
d. Key technologies and libraries
• Elixir/Erlang OTP
• gen_tcp, ssl (Erlang)
• Optional castore for certificates
• Docker Compose + Tinyproxy/Caddy for proxy integration tests