ADR-011: Three-Layer ArchitectureΒΆ
Estado: β Accepted Date: 2026-01-29 Deciders: Rodrigo RoldΓ‘n
ContextΒΆ
Arquitectura de cliente HTTP puede organizarse de varias formas:
Monolithic: Todo en un solo mΓ³dulo
Two-layer: Client + Transport
Three-layer: Client + Protocol + Transport
Multi-layer: Muchas capas de abstracciΓ³n
DecisionΒΆ
Arquitectura de 3 capas claramente separadas:
βββββββββββββββββββββββββββββββββββββββββββ
β CLIENT LAYER β
β Session, Request, Response, WebSocket β β API pΓΊblica, lΓ³gica de negocio
β Responsabilidad: Estado, cookies, auth β
βββββββββββββββββββββββββββββββββββββββββββ€
β PROTOCOL LAYER β
β HttpParser, Headers, Body, URL β β Parsing HTTP/1.1, WebSocket frames
β Responsabilidad: Protocolo HTTP β
βββββββββββββββββββββββββββββββββββββββββββ€
β TRANSPORT LAYER β
β Connection, ConnectionPool, TLS β β Sockets, TLS, I/O
β Responsabilidad: Red, conexiones β
βββββββββββββββββββββββββββββββββββββββββββ
Principios:
Separation of concerns: Cada capa tiene responsabilidad ΓΊnica
Dependency direction: Client β Protocol β Transport (nunca al revΓ©s)
Reusability: Protocol layer compartido entre sync y async
Testability: Cada capa testeable independientemente
Mapeo a cΓ³digo:
src/reqivo/
βββ client/ β CLIENT LAYER
β βββ session.py
β βββ request.py
β βββ response.py
β βββ websocket.py
β βββ auth.py
βββ http/ β PROTOCOL LAYER
β βββ http11.py
β βββ headers.py
β βββ body.py
β βββ url.py
βββ transport/ β TRANSPORT LAYER
β βββ connection.py
β βββ connection_pool.py
β βββ tls.py
βββ utils/ β Cross-cutting concerns
βββ timing.py
βββ validators.py
ConsequencesΒΆ
Positive β ΒΆ
Clear separation: Cada capa tiene propΓ³sito definido
Testability: Mockear capas inferiores fΓ‘cilmente
Reusability: Protocol layer usado por sync y async
Maintainability: Cambios localizados en capa correcta
Understandability: Estructura clara para nuevos devs
Negative βΒΆ
Indirection: MΓ‘s archivos, mΓ‘s imports
Over-engineering: Puede ser excesivo para proyecto pequeΓ±o
Coupling: Capas deben coordinarse cuidadosamente
MitigationsΒΆ
Clear interfaces: Cada capa con API bien definida
Documentation: Arquitectura documentada en ADR (este doc)
Refactoring freedom: Internals pueden reorganizarse
Layer ResponsibilitiesΒΆ
CLIENT LAYER:
Estado de sesiΓ³n (cookies, headers, auth)
API pΓΊblica de alto nivel
GestiΓ³n de connection pool
Business logic (redirects, retries)
PROTOCOL LAYER:
Parsing HTTP responses
ConstrucciΓ³n HTTP requests
WebSocket frame handling
Protocol compliance (RFC 7230-7235, RFC 6455)
TRANSPORT LAYER:
Socket management (TCP)
TLS/SSL handshake
Timeout enforcement
ConexiΓ³n fΓsica a servidor
Alternatives ConsideredΒΆ
Monolithic: Rejected. DifΓcil mantener y testear.
Two-layer: Rejected. Protocol y transport muy acoplados.
Four+ layers: Rejected. Over-engineering innecesario.
ReferencesΒΆ
Clean Architecture (Robert C. Martin)
Layered Architecture Pattern