Skip to main content
Version: 0.2.3

Architecture Overview

Sercha uses Hexagonal Architecture (Ports & Adapters) to achieve maximum extensibility with minimum coupling.

The Problem

Sercha needs to support many moving parts:

RequirementExamples
Multiple data sourcesGmail, Slack, GitHub, Filesystem, Notion
Multiple file formatsPDF, Markdown, HTML, DOCX, emails, code
Multiple search backendsFull-text (Xapian), Vector (HNSWlib)
Multiple UIsCLI, TUI, MCP server

Without careful architecture, this becomes tangled:

Every component knows about every other. Changes ripple everywhere.

The Solution

Driving ports (left): Interfaces that UI adapters call INTO the core

Driven ports (right): Interfaces that core calls OUT to infrastructure

Core knows nothing about the outside world. It only knows abstract interfaces.

Key Insight

The core never imports concrete implementations:

Adding Gmail support requires zero changes to core code.

The Rule: Dependencies Flow Inward

Adapters depend on ports. Ports depend on core. Core depends on nothing external.

Core Purity

The core/ package is pure Go—no CGO, no network calls, no file I/O. All external interactions happen through driven adapters.

Required vs Optional Services

Not all driven adapters are required. Sercha degrades gracefully when optional services are unavailable:

ServiceRequired?Without It
SQLite (metadata)YesCannot function
Xapian (full-text)YesCannot search
HNSWlib (vectors)NoNo semantic search
Embedding ServiceNoNo vector generation
LLM ServiceNoNo query rewriting

This allows Sercha to work on systems without AI services configured—pure keyword search is always available.

Benefits

BenefitHow
Plugin-like extensibilityNew connector = new package + one registration line
Parallel developmentTeams work on isolated packages, no merge conflicts
TestabilityCore services tested with mock adapters
Technology independenceSwap Xapian for Elasticsearch without touching business logic
Bug isolationGmail bug cannot break GitHub connector

Trade-offs

BenefitCost
FlexibilityMore interfaces to define upfront
TestabilityIndirection adds complexity
IndependenceLearning curve for contributors

For Sercha's requirements (many integrations, open-source contributors, long-term maintenance), the benefits far outweigh the costs.

Why Not Other Patterns?

PatternWhen to UseWhy Not for Sercha
LayeredSimple CRUD appsToo rigid for plugin system
MicroservicesDistributed teamsOverkill for single binary
HexagonalMany integrationsPerfect fit

Next