Skip to main content

Architecture Overview

Sercha Core uses hexagonal architecture (also known as ports and adapters) to achieve clean separation between business logic and infrastructure concerns.

Why Hexagonal Architecture?

Sercha Core needs to:

  1. Support multiple data sources - Google Drive, Dropbox, GitHub, local files, etc.
  2. Support multiple search backends - Vespa today, potentially others tomorrow
  3. Support multiple embedding providers - OpenAI, Ollama, or none at all
  4. Run in multiple modes - API server, background worker, or combined

Hexagonal architecture makes these variations possible by isolating the core business logic from external dependencies.

The Hexagon

Key Concepts

Driving Adapters (Input)

These call INTO the core domain:

AdapterPurpose
HTTP APIREST endpoints for clients
Background WorkerJob processing and sync scheduling

Core Domain

The heart of the system, containing:

ComponentPurpose
Domain EntitiesUser, Document, Source, Chunk, Session
Driving PortsService interfaces (AuthService, SearchService, etc.)
Driven PortsInfrastructure interfaces (UserStore, SearchEngine, etc.)
ServicesBusiness logic implementation

Driven Adapters (Output)

These are called BY the core domain:

Required:

AdapterPurpose
PostgreSQLUser, document, source metadata, sessions, job queue
VespaSearch engine (BM25 + vector)

Optional:

AdapterPurpose
RedisSession caching, job queue (improves performance at scale)
Embedding APISemantic search - find documents by meaning
LLM APIQuery expansion, summarization

See AI Models for embedding and LLM configuration.

Dependency Rule

Dependencies always point inward:

Adapters → Ports → Domain
  • Adapters depend on ports (interfaces)
  • Ports depend on domain entities
  • Domain entities have no external dependencies

Benefits

BenefitHow It's Achieved
TestabilityMock adapters for unit tests
FlexibilitySwap adapters without changing core
MaintainabilityClear boundaries between concerns
Graceful degradationOptional adapters (embedding)

Next