Technical Architecture & ComponentsΒΆ
Technical Blueprint This document describes HOW Reqivo is built internally.
External References:
ADR/0000-ADR.md - Why these decisions were made.
PROJECT_ANALYSIS.md - Requirements and context.
1. ποΈ High-Level DesignΒΆ
Reqivo follows a strict 3 separate layers architecture. Dependency flows always top-down: Client uses Protocol and Transport, but Transport never knows about Protocol or Client.
USER CODE
β
βΌ
ββββββββββββββββββββββββ
β LAYER 1: CLIENT β π§ "The Brain"
β (Session, Request) β β’ Maintains State (Cookies, Auth)
ββββββββββββ¬ββββββββββββ β’ Decides WHAT to do
β
β 1. Request bytes needed
βΌ
ββββββββββββββββββββββββ
β LAYER 2: PROTOCOL β π "The Translator"
β (HttpParser, Body) β β’ Pure Logic (No I/O)
ββββββββββββ¬ββββββββββββ β’ Converts Objects <-> Bytes
β
β 2. Delivers raw bytes
βΌ
ββββββββββββββββββββββββ
β LAYER 3: TRANSPORT β π "The Truck"
β (Connection, Pool) β β’ Socket I/O & TLS
ββββββββββββ¬ββββββββββββ β’ Moves bytes A -> B
β
β 3. Network traffic
βΌ
INTERNET
Design PrinciplesΒΆ
Separation of Concerns: Each layer has a single purpose.
Protocol Agnostic Transport: Transport layer moves bytes, doesnβt know what HTTP is.
State Isolation: Persistent state lives only in the Client layer (
Session).
2. π§© Component MapΒΆ
Layer 1: CLIENT (Logic & State)ΒΆ
Location: src/reqivo/client/
This is the only layer the end user imports directly.
Session (
session.py): βThe Brainβ.Responsibility: Maintains persistent state between requests.
Data: Cookie Jar, Authentication credentials, Default Headers.
Resources: Manages
ConnectionPoollifecycle.
Request (
request.py): βThe Builderβ.Responsibility: Ephemeral object preparing data for sending.
Action: Validates inputs, serializes body, and delegates sending to session/transport.
Response (
response.py): βThe Resultβ.Responsibility: Parse and expose response comfortably.
Optimization: Uses
__slots__to reduce memory in high-throughput apps.
WebSocket (
websocket.py): RFC 6455 Client.Handles initial handshake (HTTP Upgrade).
Manages frame send/receive loop.
Layer 2: PROTOCOL (Communication Rules)ΒΆ
Location: src/reqivo/http/
Pure HTTP/1.1 implementation. No I/O, only memory data manipulation.
HttpParser (
http11.py):State machine for parsing responses.
Detects message boundaries (Content-Length vs Chunked).
Headers (
headers.py):Specialized case-insensitive dictionary (
Content-Type==content-type).
Body (
body.py):Utilities for reading streams (fixed-length, chunked).
Layer 3: TRANSPORT (The Network)ΒΆ
Location: src/reqivo/transport/
In charge of moving bytes from A to B.
Connection (
connection.py):Wrapper over native
socket.socket.Handles TLS handshake (
ssl.wrap_socket).Applies socket-level timeouts.
ConnectionPool (
connection_pool.py):Store of active connections.
LIFO (Last-In, First-Out) Strategy: Reuses most recent connection to improve cache locality and reduce server timeout closures.
3. π Data FlowΒΆ
Request Lifecycle (Sync)ΒΆ
USER SESSION POOL CONNECTION INTERNET
β β β β β
β 1. get(url) β β β β
ββββββββββββββββββββΊβ β β β
β β 2. get_conn() β β β
β βββββββββββββββββΊβ β β
β β β 3. Pop LIFO β β
β β βββββββββββββββββββΊβ β
β β β β β
β β 4. send() β β 5. write() β
β ββββββββββββββββββββββββββββββββββββΊββββββββββββββββββΊβ
β β β β β
β β β β 6. read() β
β β 7. parse() β βββββββββββββββββββ€
β βββββββββββββββββββββββββββββββββββββ€ β
β β β β β
β β 8. put_conn() β β β
β βββββββββββββββββΊβ β β
β 9. Response β β β β
βββββββββββββββββββββ€ β β β
Preparation:
Sessioncombines user headers + cookie jar + auth headers.Acquisition: Connection requested from
ConnectionPool. If one alive exists for that host (LIFO), itβs used; else, open socket + TLS.Transmission: Raw bytes sent via socket.
Reception: Bytes read until headers complete.
Parsing:
HttpParservalidates and structures response.Release: Connection returned to pool for reuse.
4. β‘ Concurrency ModelΒΆ
Reqivo is Async-First. This means the βtrueβ implementation is asynchronous.
Sync/Async DualityΒΆ
To avoid duplicating complex logic, Reqivo uses a Synchronous Wrapper pattern:
Base Code: All Protocol and Utilities code is shared (pure CPU-bound).
Native IO: Two Transport implementations exist:
AsyncConnection: Usesasyncio.StreamReader/Writer.Connection: Uses blockingsocket.
Client:
AsyncSession: UsesAsyncConnectionandawait.Session: UsesConnectionand blocks current thread.
Note: Unlike other libraries wrapping async code in a hidden loop (overhead), Reqivo implements the synchronous transport layer natively with blocking sockets for maximum performance in sync contexts.
5. π‘οΈ Security & RobustnessΒΆ
Error HandlingΒΆ
The system transforms low-level errors (socket.timeout, ssl.SSLError) into semantic Reqivo exceptions before reaching Client layer.
ConnectTimeout: Failure establishing TCP/TLS.ReadTimeout: Failure waiting for data (TTFB or body gap).TlsError: Certificate validation failure.
Resource SafetyΒΆ
Context Managers: Using
with Session()guarantees socket closure.Finalizers:
ConnectionPoolattempts to clean up connections when collected by GC (best effort).