Skip to main content
Version: 0.2.3

Extensibility

Sercha is designed for maximum extensibility with minimum coupling. This page explains the extension mechanisms.

Extension Points

The Factory Pattern

ConnectorFactory

How it works:

  1. Each connector registers a builder function
  2. Factory stores type → builder mapping
  3. When source config arrives, factory looks up type
  4. Builder creates configured instance

Zero coupling: Factory doesn't import connector packages directly. Registration happens at startup.

NormaliserRegistry

Priority System:

PriorityTypeExample
90-100Connector-specificGmail email normaliser
50-89Format-specificPDF, Markdown
10-49GenericHTML, plaintext
1-9FallbackRaw text extraction

Adding a Connector

What you create:

  • One package under connectors/
  • Implements Connector interface

What you touch:

  • One line in main.go for registration

What you DON'T touch:

  • Core domain
  • Services
  • Workers
  • Other connectors

Connector Checklist

  • Create package under connectors/<name>/
  • Implement NewConnector(source Source) (Connector, error)
  • Implement FullSync(ctx) (<-chan RawDocument, <-chan error)
  • Implement Capabilities() returning supported features
  • Register in main.go: factory.Register("<name>", <name>.NewConnector)
  • Add tests in connector_test.go

Adding a Normaliser

Normaliser Types:

TypeLocationPriorityUse Case
Generic MIMEnormalisers/pdf/50-89PDF from any source
Connector-specificconnectors/gmail/90-100Gmail email format
Fallbacknormalisers/plaintext/1-9Unknown formats

Normaliser Checklist

  • Create package under normalisers/<mime>/ (or in connector package)
  • Implement SupportedMIMETypes() []string
  • Implement Priority() int (see table above)
  • Implement Normalise(ctx, RawDocument) (*NormaliseResult, error)
  • Register in main.go: registry.Register(<name>.NewNormaliser())
  • Add tests in normaliser_test.go

Interface Stability

Stability guarantees:

  • Interfaces change only for major versions
  • Implementations can change anytime
  • Core domain is most stable

Capability System

Connectors declare what they support:

Capability flags:

CapabilityMeaningExamples
SupportsIncrementalCan fetch only changesGmail, GitHub
SupportsWatchCan push real-time eventsFilesystem, Slack
SupportsHierarchyHas nested structureDrive, GitHub repos
SupportsBinaryHandles binary contentAll

Worker Abstraction

Workers never:

  • Check connector type
  • Check MIME type
  • Import connector packages
  • Import normaliser packages

Workers only:

  • Call factory to create connectors
  • Call registry to normalise
  • Call storage to persist

Extension Isolation

Bug isolation: A bug in Gmail connector cannot affect:

  • GitHub connector
  • Core services
  • Search functionality
  • Other users' data

Next