services/

directory
v0.0.0-...-1746241 Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: MIT

README

Services

This directory mixes a few different service styles today:

  • simple app-bound services that wrap core.App
  • stateful runtime services with background workers or caches
  • integration services with external clients
  • compatibility layers that still rely on package-level runtime state

To make new code and gradual refactors more consistent, the preferred baseline is:

  1. Put shared app access behind services/base.
  2. Expose a package-level Descriptor using base.Descriptor.
  3. Keep service config in a dedicated config.go or config/ package.
  4. Prefer app.Settings() as the primary source of persisted configuration.
  5. Use env vars as fallback/bootstrap overrides, not as the only long-term source.
  6. Keep constructors explicit about dependencies.
  7. Limit package-global runtime state to compatibility helpers and adapters.

Recommended service shape:

package example

import (
    "github.com/pafthang/servicebase/core"
    servicebase "github.com/pafthang/servicebase/services/base"
)

var Descriptor = servicebase.Descriptor{
    Name:    "example",
    Purpose: "Short statement of responsibility.",
    Dependencies: []string{
        "core.App",
        "optional collaborators",
    },
    RuntimeState: []string{
        "List mutable state only when it exists",
    },
    Operations: []string{
        "List",
        "FindByID",
        "Delete",
    },
}

type Service struct {
    servicebase.Service
}

func New(app core.App) *Service {
    return &Service{
        Service: servicebase.NewWithApp(app),
    }
}

Recommended config shape:

package example

type Config struct {
    Enabled bool
    BaseURL string
    Timeout time.Duration
}

func DefaultConfig() Config {
    return Config{
        Enabled: false,
        BaseURL: "https://example.com",
        Timeout: 10 * time.Second,
    }
}

func ConfigFromSettings(app core.App) Config {
    cfg := DefaultConfig()

    if app == nil || app.Settings() == nil {
        return cfg
    }

    // Map from app settings here.
    return cfg
}

Field guidance:

  • Purpose: one sentence, focused on business responsibility
  • Dependencies: durable collaborators the service relies on
  • RuntimeState: caches, workers, background loops, package globals, mutexes
  • Operations: the main public entrypoints worth discovering quickly

Config guidance:

  • Prefer settings -> env -> default precedence for long-lived service config
  • Use services/base/config for small shared parsing helpers
  • Keep secrets in settings only when they already participate in redact/validate flows
  • If a service has no durable user-managed config yet, keep env fallback and add settings later

This is intentionally small. The goal is a stable shape for discovery and incremental cleanup, not a new framework around every service.

Directories

Path Synopsis
apis
Package apis owns the HTTP endpoints for the backup service.
Package apis owns the HTTP endpoints for the backup service.
migrations
Package migrations contains backup-owned schema migrations.
Package migrations contains backup-owned schema migrations.
forms
Package models implements various services used for request data validation and applying changes to existing DB models through the app Dao.
Package models implements various services used for request data validation and applying changes to existing DB models through the app Dao.
models
Package models implements all PocketBase DB models and DTOs.
Package models implements all PocketBase DB models and DTOs.
models
package models implements custom Schema and SchemaField datatypes for handling the Collection schema definitions.
package models implements custom Schema and SchemaField datatypes for handling the Collection schema definitions.
migrations
Package migrations owns cron service storage migrations.
Package migrations owns cron service storage migrations.
apis
Package apis owns file service HTTP bindings.
Package apis owns file service HTTP bindings.
forms
Package forms contains file request and submit-flow DTOs.
Package forms contains file request and submit-flow DTOs.
migrations
Package migrations owns the file service schema.
Package migrations owns the file service schema.
queries
Package queries contains file read-side query helpers.
Package queries contains file read-side query helpers.
migrations
Package migrations registers health-owned database migrations.
Package migrations registers health-owned database migrations.
log
forms
Package forms contains log service request and submit forms.
Package forms contains log service request and submit forms.
queries
Package queries contains read-side query helpers for the log service.
Package queries contains read-side query helpers for the log service.
Package mails implements various helper methods for sending user and admin emails like forgotten password, verification, etc.
Package mails implements various helper methods for sending user and admin emails like forgotten password, verification, etc.
Package migrate provides migration command orchestration, migration file generation and collection automigration hooks.
Package migrate provides migration command orchestration, migration file generation and collection automigration hooks.
apis
Package apis is reserved for migrate service HTTP bindings.
Package apis is reserved for migrate service HTTP bindings.
forms
Package forms contains migrate command/request forms when migrate flows need validation-oriented DTOs.
Package forms contains migrate command/request forms when migrate flows need validation-oriented DTOs.
migrations
Package migrations is intentionally empty for the migrate tooling service.
Package migrations is intentionally empty for the migrate tooling service.
queries
Package queries contains migrate service read-side helpers.
Package queries contains migrate service read-side helpers.
migrations
Package migrations owns realtime service storage migrations.
Package migrations owns realtime service storage migrations.
queries
Package queries contains realtime read-side query helpers.
Package queries contains realtime read-side query helpers.
apis
Package apis contains the record service HTTP transport binding layer.
Package apis contains the record service HTTP transport binding layer.
apis
Package apis contains the team service HTTP transport binding layer.
Package apis contains the team service HTTP transport binding layer.
forms
Package forms reserves the service-local form layer for the team service.
Package forms reserves the service-local form layer for the team service.
forms
Package forms contains updater service request/submit forms.
Package forms contains updater service request/submit forms.
queries
Package queries contains read-side helpers for the updater service.
Package queries contains read-side helpers for the updater service.
apis
Package apis contains the user service HTTP transport binding layer.
Package apis contains the user service HTTP transport binding layer.

Jump to

Keyboard shortcuts

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