Skip to content

Architecture

NectoProxy is organized as a monorepo with seven packages, managed by pnpm workspaces and Turborepo. This page provides a detailed overview of each package, their responsibilities, and how data flows through the system.

Monorepo Structure

nectoproxy/
  apps/
    cli/                  # nectoproxy (CLI) -- the npm package users install
    web/                  # @nectoproxy/web -- React SPA
  packages/
    shared/               # @nectoproxy/shared -- TypeScript types
    certs/                # @nectoproxy/certs -- Certificate generation
    storage/              # @nectoproxy/storage -- SQLite + Drizzle ORM
    core/                 # @nectoproxy/core -- MITM proxy engine
    server/               # @nectoproxy/server -- REST API + Socket.IO

The monorepo uses:

  • pnpm workspaces for dependency management across packages
  • Turborepo for orchestrating builds, tests, and dev tasks with caching and parallelism
  • TypeScript throughout, with a shared tsconfig.base.json
  • Vitest as the test runner

Package Dependency Graph

                    @nectoproxy/shared
                   /        |         \
                  /         |          \
    @nectoproxy/certs  @nectoproxy/storage  @nectoproxy/web
                  \         |
                   \        |
                @nectoproxy/core
                        |
                @nectoproxy/server
                        |
                   nectoproxy (CLI)

Build order follows this dependency graph. Turborepo resolves it automatically via the dependsOn: ["^build"] configuration.

Package Details

@nectoproxy/shared

Path: packages/shared/

Purpose: Central repository of TypeScript type definitions shared across all packages. This package ensures type consistency across the entire codebase.

Key files:

  • types/traffic.ts -- TrafficEntry type for HTTP request/response pairs
  • types/rules.ts -- Rule, RuleAction, RuleMatcher, and action config types (Mock, Block, Delay, Throttle, MapRemote, MapLocal, ModifyRequest, ModifyResponse)
  • types/session.ts -- Session type for capture sessions
  • types/settings.ts -- Settings, ProxySettings, UISettings, StorageSettings, CertificateSettings, UpstreamProxyConfig types with DEFAULT_SETTINGS
  • types/network.ts -- NetworkProfile type and NETWORK_PRESETS array (Slow 2G through Offline)
  • types/breakpoints.ts -- Breakpoint, BreakpointHit, BreakpointResume types
  • types/events.ts -- Socket.IO event type definitions
  • types/har.ts -- HAR (HTTP Archive) format types
  • types/sslPassthrough.ts -- SSL passthrough domain types
  • types/dns.ts -- DNS mapping types
  • types/annotations.ts -- Traffic annotation types

Dependencies: None (leaf package).


@nectoproxy/certs

Path: packages/certs/

Purpose: Handles all certificate operations -- generating the root CA, creating per-domain certificates on-the-fly, and managing the certificate cache.

Key components:

ClassResponsibility
CertificateManagerHigh-level certificate management. Initializes the CA, generates and caches domain certificates, provides installation instructions.
CAGeneratorGenerates the root CA key pair and self-signed certificate using node-forge. CA is valid for 10 years with 2048-bit RSA keys.
DomainCertGeneratorGenerates per-domain certificates signed by the CA. Certificates are valid for 365 days. Supports SAN (Subject Alternative Name) for proper domain validation.

How it works:

  1. On first launch, CAGenerator creates a CA key pair and certificate, saved to ~/.nectoproxy/certs/.
  2. When the proxy intercepts an HTTPS connection to example.com, CertificateManager.getCertificateForDomain('example.com') is called.
  3. If a cached certificate exists and is valid, it is returned. Otherwise, DomainCertGenerator creates a new one, signs it with the CA, caches it, and returns it.
  4. The generated certificate is used to establish a TLS connection with the client, allowing NectoProxy to decrypt and inspect the traffic.

Dependencies: @nectoproxy/shared, node-forge


@nectoproxy/storage

Path: packages/storage/

Purpose: Manages all persistent data storage using SQLite with the Drizzle ORM.

Key components:

FileResponsibility
db/connection.tsCreates and manages the SQLite database connection. Initializes tables, enables WAL mode, and manages migrations.
db/schema.tsDrizzle ORM schema definitions for all 9 tables.
repositories/*.tsRepository classes providing CRUD operations for each entity.

Database tables:

TableRepositoryDescription
sessionsSessionRepositoryCapture sessions with metadata (name, active flag, traffic count, total bytes)
trafficTrafficRepositoryHTTP request-response pairs with full headers, bodies, timing, and flags
rulesRuleRepositoryTraffic manipulation rules (match, action, config, priority)
breakpointsBreakpointRepositoryBreakpoint definitions for intercepting requests/responses
ssl_passthroughSSLPassthroughRepositoryDomains that bypass MITM interception
dns_mappingsDnsMappingRepositoryCustom DNS hostname-to-IP mappings
settingsSettingsRepositoryKey-value settings store
ws_framesWebSocketFrameRepositoryIndividual WebSocket frames linked to traffic entries
annotationsAnnotationRepositoryUser notes and tags on traffic entries

Database features:

  • WAL (Write-Ahead Logging) mode for concurrent reads and writes
  • Foreign key cascading deletes (e.g., deleting a session deletes all its traffic)
  • Indexed columns for fast querying (session ID, timestamp, host, method, status)

Dependencies: @nectoproxy/shared, better-sqlite3, drizzle-orm


@nectoproxy/core

Path: packages/core/

Purpose: The MITM (man-in-the-middle) proxy engine. This is the heart of NectoProxy -- it intercepts, inspects, and optionally modifies HTTP/HTTPS/WebSocket traffic.

Key components:

ClassResponsibility
ProxyServerMain proxy server. Creates an HTTP server, handles CONNECT tunnels for HTTPS, manages TLS termination, and coordinates all subsystems.
RuleEngineEvaluates traffic against configured rules and returns actions (mock, block, delay, throttle, map-remote, map-local, modify).
RuleMatcherPattern matching engine for URL, method, host, path, headers, and body content.
BreakpointManagerManages breakpoints. Pauses request/response flow, emits events, waits for user interaction, and implements auto-continue timeout.
WebSocketHandlerIntercepts WebSocket upgrade requests, establishes proxy connections, and captures individual frames in both directions.
ThrottleServiceApplies network conditioning (bandwidth limits, latency, jitter, packet loss) based on the active network profile.
UpstreamProxyAgentManages connections through upstream proxies (HTTP, HTTPS, SOCKS4, SOCKS5) with authentication and bypass rules.

Rule actions (in rules/actions/):

ActionClassDescription
mockMockActionReturns a custom response without contacting the server
blockBlockActionBlocks the request entirely
delayDelayActionAdds a time delay before forwarding
throttleThrottleActionLimits bandwidth for the matched request
map-remoteMapRemoteActionRedirects the request to a different URL
map-localMapLocalActionServes a response from a local file
modify-requestModifyRequestActionModifies request headers, body, or query params
modify-responseModifyResponseActionModifies response status, headers, or body

HTTPS interception flow:

  1. Client sends CONNECT example.com:443 to the proxy.
  2. ProxyServer.handleConnect() checks SSL passthrough. If the domain is in the passthrough list, it tunnels directly.
  3. Otherwise, it fetches a certificate for example.com from CertificateManager.
  4. Acknowledges the CONNECT with 200 Connection Established.
  5. Wraps the socket in a TLSSocket using the generated certificate.
  6. Creates an HTTP parser on the TLS socket to handle decrypted requests.
  7. Processes the HTTP request through rules, breakpoints, and throttling.
  8. Forwards to the target server (or upstream proxy) and returns the response.

Dependencies: @nectoproxy/shared, @nectoproxy/certs, uuid


@nectoproxy/server

Path: packages/server/

Purpose: Provides the REST API and real-time event system that bridges the proxy engine with the Web UI.

Key components:

ComponentResponsibility
app.tsExpress application factory. Registers routes, serves static Web UI files, configures middleware.
SocketServerSocket.IO server for real-time events. Emits traffic updates, breakpoint hits, WebSocket frames, and proxy status to connected Web UI clients.
HarConverterConverts between NectoProxy's internal TrafficEntry format and the HAR (HTTP Archive) standard.
ReplayServiceReplays captured requests against the real server.

API routes (routes/):

RoutePathDescription
sessions.ts/api/sessionsCRUD for capture sessions
traffic.ts/api/trafficQuery and manage traffic entries
rules.ts/api/rulesCRUD for traffic manipulation rules
breakpoints.ts/api/breakpointsCRUD for breakpoint definitions
settings.ts/api/settingsRead/write application settings
certificates.ts/api/certificatesCertificate info and download
har.ts/api/harHAR export/import
ssl-passthrough.ts/api/ssl-passthroughCRUD for SSL passthrough domains
dns.ts/api/dnsCRUD for DNS mappings
annotations.ts/api/annotationsCRUD for traffic annotations
websocket.ts/api/websocketWebSocket frame queries
network.ts/api/networkNetwork conditioning profiles
upstream-proxy.ts/api/upstream-proxyUpstream proxy configuration
snapshot.ts/api/snapshotTraffic snapshot operations

Real-time events (Socket.IO):

EventDirectionDescription
traffic:newServer -> ClientNew traffic entry captured
traffic:updateServer -> ClientTraffic entry updated (response received)
breakpoint:hitServer -> ClientA breakpoint was triggered
breakpoint:resumedServer -> ClientA breakpoint was resumed
breakpoint:timeoutServer -> ClientA breakpoint timed out
breakpoint:resumeClient -> ServerUser resumes a breakpoint
websocket:openServer -> ClientWebSocket connection opened
websocket:frameServer -> ClientWebSocket frame captured
websocket:closeServer -> ClientWebSocket connection closed
proxy:startedServer -> ClientProxy server started
proxy:stoppedServer -> ClientProxy server stopped
proxy:errorServer -> ClientProxy error occurred

Dependencies: @nectoproxy/shared, @nectoproxy/storage, @nectoproxy/core, express, socket.io, multer


@nectoproxy/web

Path: apps/web/

Purpose: The React single-page application that provides the NectoProxy Web UI.

Technology stack:

  • React 18 -- UI framework
  • Vite -- Build tool and dev server with HMR
  • TailwindCSS -- Utility-first CSS framework
  • Zustand -- Lightweight state management
  • React Query -- Server state and API call management
  • Socket.IO Client -- Real-time event handling
  • Lucide React -- Icon library
  • qrcode.react -- QR code generation for mobile certificate download

Key components:

ComponentDescription
HeaderTop toolbar with recording controls, view toggles, theme switch, filters
TrafficListVirtualized list of traffic entries with sorting and selection
DetailPanelDetailed view of a selected traffic entry (request/response headers, body, timing)
FilterBarSearch and filter controls for the traffic list
RulesPanel / RuleEditorCreate and manage traffic manipulation rules
BreakpointsPanel / BreakpointEditorCreate and manage breakpoints
InterceptedPanelShows breakpoint-hit requests/responses for modification
SettingsPanelApplication settings with mobile configuration and QR code
NetworkConditionPanelNetwork conditioning presets and custom profiles
UpstreamProxyConfigUpstream proxy configuration dialog
SSLPassthroughPanelSSL passthrough domain management
DnsMappingPanelCustom DNS mapping configuration
WebSocketMessagesViewerView individual WebSocket frames
HarExportImportExport/import traffic as HAR files
SessionTabsSwitch between capture sessions
CodeGeneratorModalGenerate code snippets (curl, Python, Go, etc.) from traffic entries
DashboardViewVisual dashboard with charts (requests/sec, error rate, response times)
SecurityTabSecurity analysis of captured traffic
WaterfallChartRequest timing waterfall visualization
TimingBreakdownDetailed timing breakdown for individual requests
CommandPaletteKeyboard-driven command palette
ReplayEditorEdit and replay captured requests
CodeViewerSyntax-highlighted code viewer for various languages
GraphQLViewerGraphQL query/response viewer
GRPCViewergRPC message viewer

State management (Zustand stores):

StoreState
trafficStoreTraffic entries, selected entry, filters, pause state
rulesStoreActive rules
breakpointStoreBreakpoints and pending breakpoint hits
sessionStoreSessions and active session
settingsStoreApplication settings
viewStoreUI view state (panels, layouts)
compareStoreTraffic comparison state

Dependencies: @nectoproxy/shared, react, vite, tailwindcss, zustand, socket.io-client


nectoproxy (CLI)

Path: apps/cli/

Purpose: The command-line interface and the npm package that end users install. It bundles the compiled Web UI and orchestrates all other packages.

Commands:

CommandDescription
nectoproxy startStart the proxy server and Web UI
nectoproxy certCertificate management (install, path, clear-cache)
nectoproxy sessionsSession management (list, create, delete)

How start works:

  1. Initializes the SQLite database via @nectoproxy/storage.
  2. Initializes the certificate manager via @nectoproxy/certs.
  3. Creates or resumes an active session.
  4. Creates the ProxyServer from @nectoproxy/core.
  5. Creates the Express app and Socket.IO server from @nectoproxy/server, serving the bundled Web UI from apps/cli/dist/web-ui/.
  6. Connects proxy events (traffic, breakpoints, WebSocket, errors) to the Socket.IO server and database.
  7. Starts both servers and optionally opens the browser.

Dependencies: All packages. commander, chalk, ora, open


Data Flow

The following diagram shows how data flows through the system when a browser makes an HTTPS request through NectoProxy:

 Browser                NectoProxy                           Internet
    |                       |                                    |
    |  CONNECT example.com  |                                    |
    |---------------------->|                                    |
    |  200 Connection Est.  |                                    |
    |<----------------------|                                    |
    |                       |                                    |
    |  TLS Handshake        |  (uses generated cert)             |
    |<--------------------->|                                    |
    |                       |                                    |
    |  GET /api/data        |                                    |
    |  (encrypted)          |                                    |
    |---------------------->|                                    |
    |                       |                                    |
    |                       |  1. Decrypt request                |
    |                       |  2. Evaluate Rules                 |
    |                       |  3. Check Breakpoints              |
    |                       |  4. Apply Network Conditioning     |
    |                       |  5. Emit traffic:new via Socket.IO |
    |                       |                                    |
    |                       |  GET /api/data (new TLS)           |
    |                       |----------------------------------->|
    |                       |                                    |
    |                       |  200 OK + JSON body                |
    |                       |<-----------------------------------|
    |                       |                                    |
    |                       |  6. Decompress response            |
    |                       |  7. Evaluate response rules        |
    |                       |  8. Check response breakpoints     |
    |                       |  9. Apply response throttling      |
    |                       | 10. Save to SQLite (async)         |
    |                       | 11. Emit traffic:update via        |
    |                       |     Socket.IO                      |
    |                       |                                    |
    |  200 OK + JSON body   |                                    |
    |  (re-encrypted)       |                                    |
    |<----------------------|                                    |
    |                       |                                    |


 Web UI (React SPA)
    |
    |  Receives traffic:new via Socket.IO
    |  Updates trafficStore (Zustand)
    |  React re-renders TrafficList
    |
    |  Receives traffic:update via Socket.IO
    |  Updates entry with response data
    |  React re-renders DetailPanel
    |

Build Pipeline

Turborepo manages the build pipeline with the following task configuration:

json
{
  "build": {
    "dependsOn": ["^build"],
    "outputs": ["dist/**"]
  },
  "dev": {
    "cache": false,
    "persistent": true
  },
  "test": {
    "dependsOn": ["build"]
  }
}
  • ^build means "build all dependencies first". This ensures @nectoproxy/shared is built before @nectoproxy/core, which depends on it.
  • outputs: ["dist/**"] tells Turborepo to cache the dist/ directories. If source files have not changed, the cached output is reused.
  • test depends on build, ensuring tests run against compiled code.