Go Backend Services
Relevant source files
The following files were used as context for generating this wiki page:
Go backend services constitute the core application logic of the Speakeasy AI Control Plane. The system manages Model Context Protocol (MCP) servers, skills, and assistants while providing observability, security enforcement, and fine-grained access control. The backend utilizes a design-first API approach with Goa and handles long-running processes via Temporal workflows.
Sources: README.md:17-23, GEMINI.md:37-43
Project Architecture
The Go codebase is organized into three primary areas: the main server, the command-line interface (CLI), and the serverless function runner.
| Directory | Component | Description |
|---|---|---|
server/ | Main Backend | Implementation of the Speakeasy service, background workers, and database migrations. |
cli/ | Speakeasy CLI | Command-line tool for user interaction with the Speakeasy service. |
functions/ | Function Runner | Serverless environment for executing Speakeasy Functions. |
server/internal/ | Core Logic | Contains service implementations, Temporal workflows, and internal utilities. |
server/design/ | API Design | Goa DSL files defining the public HTTP-RPC interface. |
Sources: GEMINI.md:37-72, REVIEW.md:7-12
Backend Component Relationships
The following diagram illustrates how the process manager coordinates local backend services during development.
The pitchfork process manager runs all local services in a single terminal interface.
Sources: GEMINI.md:43-47, CONTRIBUTING.md:139-145
API Implementation Guidelines
Backend services follow strict coding conventions to ensure maintainability and security.
Service Structure and Dependency Injection
Services utilize constructor-based injection. Dependencies must be stored on service structs and never hidden in session manager state. For database access, new services inject *pgxpool.Pool and initialize the SQLc repository using repo.New(s.db) within handler methods.
Sources: REVIEW.md:52-58
Security and RBAC
Every mutating handler must enforce Role-Based Access Control (RBAC) before performing database operations. Developers must call s.authz.Require(ctx, authz.Check{...}) to validate permissions. List endpoints utilize authz.Filter to ensure users only see resources they are authorized to access.
Sources: REVIEW.md:99-103
Audit Logging
Mutations on project or organization-scoped resources require audit entries for every affected row. These writes must occur within the same database transaction (dbtx) as the mutation to ensure atomicity. Failures in audit logging are treated as oops.CodeUnexpected, resulting in a request failure.
Sources: REVIEW.md:105-110
Data Persistence and Messaging
Database Strategy
Speakeasy uses PostgreSQL for relational data and ClickHouse for telemetry.
- PostgreSQL: Managed via SQLc for type-safe queries and Atlas for migrations. Every table must include
project_id,created_at, andupdated_at. - ClickHouse: Used for logs, costs, and token use observability. The
telemetrypackage utilizes the Squirrel query builder for ClickHouse only.
Sources: REVIEW.md:129-138, REVIEW.md:162-166, README.md:17-23
Pub/Sub Topology
The system leverages a compiled proto-based topology for messaging. Call sites in Go are resolved to proto full names via infra/internal/diagram/diagram.go to ensure publishers and subscribers align with the declared topology.
The diagram shows the flow from message construction to consumption through declared Pub/Sub channels.
Sources: infra/internal/diagram/diagram.go:37-65, infra/internal/diagram/diagram.go:610-630
Development and Testing
Testing Framework
Assertions must exclusively use the testify/mock and require packages. Tests should use t.Context() rather than context.Background() to align with test lifecycles. Mocking is required for third-party integrations to prevent external dependencies during testing.
Sources: REVIEW.md:76-88
Logging and Error Handling
Services must use context-aware slog methods (e.g., InfoContext). Errors are wrapped concisely using fmt.Errorf("action: %w", err) without generic prefixes like "failed to". In HTTP handlers, the oops package maps errors to user-facing responses.
Sources: REVIEW.md:31-40, REVIEW.md:46-50
Local Environment Setup
The ./zero script automates the installation of dependencies, database migrations, and service startup. It configures a local identity provider (dev-idp) that synthesizes identities based on git committer emails, allowing for non-interactive logins during development.
Sources: CONTRIBUTING.md:5-10, CONTRIBUTING.md:111-125
Conclusion
Go Backend Services provide a secure, observable, and scalable control plane for AI agents. By enforcing strict patterns for RBAC, audit logging, and design-first API implementation, the architecture maintains high standards for security and reliability across both the core server and distributed function runners.
Sources: README.md:17-23, REVIEW.md:3-5