Skip to main content
Version: 0.2.3

System Layers

Sercha is organized into distinct layers, each with clear responsibilities and dependencies.

Layer Diagram

Layer Responsibilities

UI Layer (Driving Adapters)

ComponentPurpose
CLICommand-line interface for users
TUIInteractive terminal interface
MCPModel Context Protocol server for AI tools

Rule: UI adapters only call driving ports. They never access infrastructure directly.

Application Layer (Services)

ServiceResponsibility
Sync OrchestratorCoordinates sync execution across sources
Search ServiceExecutes queries, combines results
Source ServiceCRUD operations for data sources
SchedulerBackground task execution (token refresh, document sync)

Rule: Services orchestrate domain logic. They don't know about specific connectors or storage.

Domain Layer (Core)

ComponentPurpose
EntitiesDocument, Chunk, Source, RawDocument
Driving PortsInterfaces for UI to call
Driven PortsInterfaces for infrastructure

Rule: Domain has ZERO external dependencies. Pure business logic.

Infrastructure Layer (Driven Adapters)

CategoryComponentsRequired?
ConnectorsFilesystem, Gmail, GitHubAt least one
NormalisersPDF, Markdown, HTMLAt least one
PostProcessorsChunker, Embedder, SummariserNo (optional pipeline stages)
StorageSQLite, XapianYes (core functionality)
StorageHNSWlibNo (only when embeddings configured)
CGOBindingsYes (for Xapian/HNSWlib)

Rule: Infrastructure implements driven port interfaces.

Dependency Direction

Dependencies point inward toward the domain. Infrastructure depends on domain, not vice versa.

Directory Mapping

internal/
├── adapters/
│ ├── driving/ # UI Layer
│ │ ├── cli/
│ │ ├── tui/
│ │ └── mcp/
│ └── driven/ # Infrastructure (Storage)
│ ├── sqlite/
│ ├── xapian/
│ └── hnsw/
├── core/
│ ├── domain/ # Domain Layer (Entities)
│ ├── ports/
│ │ ├── driving/ # Domain Layer (Driving Ports)
│ │ └── driven/ # Domain Layer (Driven Ports)
│ └── services/ # Application Layer (incl. Scheduler)
├── connectors/ # Infrastructure (Connectors)
├── normalisers/ # Infrastructure (Normalisers)
├── postprocessors/ # Infrastructure (PostProcessors)
cgo/ # CGO Bindings
clib/ # C++ Libraries

Dependency Matrix

This matrix defines what each layer may import. Violations break architectural purity.

LayerCan ImportCannot Import
ConnectorsHTTP libs, OAuth libs, core/domain, core/ports/drivencore/services, other connectors
NormalisersParsing libs, core/domain, core/ports/drivencore/services, connectors
PostProcessorsLLM libs, core/domain, core/ports/drivencore/services, connectors
Servicescore/domain, core/ports/*Connectors, normalisers, adapters
DomainStandard library onlyEverything else
Driving Adapterscore/ports/drivingcore/services directly
warning

New contributors often break purity by importing connectors into services. This couples core to infrastructure. Use the factory pattern instead.

Next