backend

module
v0.0.0-...-e13e1e3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 18, 2026 License: AGPL-3.0

README

Expensor Backend

Daemon that reads expense transactions from email sources and writes them to PostgreSQL.

Directory Structure

backend/
├── cmd/
│   ├── server/              # Process-only daemon entry point
│   │   └── main.go
│   └── auth/                # Standalone OAuth flow binary
│       └── main.go
├── internal/
│   ├── app/                 # Application composition and lifecycle
│   ├── catalog/             # Validated embedded rules, taxonomy, guides, and prompts
│   ├── community/           # Community content synchronization
│   ├── daemon/              # Reader → store ingestion pipeline and scan control
│   ├── httpapi/             # HTTP transport and consumer-owned control interfaces
│   ├── store/               # Backend-neutral store types and instrumentation
│   │   └── postgres/        # PostgreSQL persistence, read models, and migrations
│   └── plugins/             # Reader plugin catalog/registry
│       └── registry.go
└── pkg/
    ├── api/                 # Core interfaces & types (Reader, Rule, Labels)
    ├── client/              # OAuth2 HTTP client helper
    ├── config/              # TOML and environment-based configuration
    ├── extractor/           # Regex amount & merchant extraction
    ├── observability/       # slog setup plus OpenTelemetry traces/metrics
    ├── state/               # SHA-256 keyed dedup state (prevents reprocessing)
    ├── reader/
    │   ├── gmail/           # Gmail API reader
    │   └── thunderbird/     # MBOX file reader

Plugin System

Email providers are registered at startup via the plugin registry. Adding a new provider requires implementing the required capabilities and registering the provider. PostgreSQL ingestion is owned by internal/store.

Providers
type Provider struct {
    Metadata ProviderMetadata

    NewReader func(ProviderInput) (api.Reader, error)
    NewEmailSearcher func(ProviderInput) (api.EmailSearcher, error)
}

Registered providers: gmail, thunderbird

Adding a New Plugin

New Provider
  1. Implement the reader in backend/pkg/reader/{name}/
  2. Add the provider metadata and constructor adapters in backend/pkg/reader/{name}/plugin.go
  3. Register in backend/internal/app/readers.go:
    registry.RegisterProvider(newreader.Provider(guideData))
    
  4. Add any required config fields to backend/pkg/config/config.go

Building

task build          # go build ./...
task build:binary   # optimised binary at ../bin/expensor

Running

# Local backend using tests/config.dev.toml and the Postgres dev container
task run

# Full local app stack
task dev

The local tasks load tests/config.dev.toml through EXPENSOR_CONFIG_FILE. Override values with environment variables when needed, for example task run DB_BACKEND=postgres. See the root README for the full configuration reference.

Directories

Path Synopsis
cmd
server command
internal
app
auth
Package auth contains authentication primitives shared by the HTTP and store layers.
Package auth contains authentication primitives shared by the HTTP and store layers.
catalog
Package catalog loads the application content embedded in the server binary.
Package catalog loads the application content embedded in the server binary.
community
Package community synchronizes community-maintained taxonomy content.
Package community synchronizes community-maintained taxonomy content.
daemon
Package daemon provides the core daemon runner for Expensor.
Package daemon provides the core daemon runner for Expensor.
extractor
Package extractor provides common transaction extraction logic for email readers.
Package extractor provides common transaction extraction logic for email readers.
httpapi
Package httpapi provides Expensor's HTTP server, routes, handlers, and transport types.
Package httpapi provides Expensor's HTTP server, routes, handlers, and transport types.
llm
Package llm provides provider-neutral primitives for LLM-backed workflows.
Package llm provides provider-neutral primitives for LLM-backed workflows.
oauth
Package client provides OAuth2 client setup for Google APIs.
Package client provides OAuth2 client setup for Google APIs.
plugins
Package plugins provides a provider registry for email-backed integrations.
Package plugins provides a provider registry for email-backed integrations.
rules
Package rules provides Expensor rule document, fixture, and merge utilities.
Package rules provides Expensor rule document, fixture, and merge utilities.
state
Package state provides processed-message deduplication for Expensor readers.
Package state provides processed-message deduplication for Expensor readers.
store/postgres
Package postgres provides PostgreSQL query and persistence operations for Expensor.
Package postgres provides PostgreSQL query and persistence operations for Expensor.
store/postgres/migrations
Package migrations embeds and applies Expensor's numbered SQL migrations.
Package migrations embeds and applies Expensor's numbered SQL migrations.
store/storetest
Package storetest provides backend-neutral conformance tests for store.Backend.
Package storetest provides backend-neutral conformance tests for store.Backend.
pkg
api
Package api defines the core interfaces and data structures for expensor.
Package api defines the core interfaces and data structures for expensor.
config
Package config provides application configuration loaded from a TOML file and environment variables.
Package config provides application configuration loaded from a TOML file and environment variables.
errors
Package errors provides structured application errors.
Package errors provides structured application errors.
reader/gmail
Package gmail implements a Reader that extracts transactions from Gmail.
Package gmail implements a Reader that extracts transactions from Gmail.
reader/thunderbird
Package thunderbird provides the Thunderbird reader and its plugin integration.
Package thunderbird provides the Thunderbird reader and its plugin integration.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL