Prefab Development Guide
Prefab is a Go server framework that simplifies building production-ready gRPC and HTTP services with a plugin-based architecture.
Core Concepts
- Server: Central component that manages gRPC/HTTP services and plugins
- Plugins: Modular components for auth, storage, templates, etc.
- Services: gRPC service implementations with automatic HTTP gateway
- Handlers: Custom HTTP handlers for non-gRPC endpoints
Prefab servers commonly compose multiple gRPC services into a single process. This enables a service-oriented monolith architecture where related services share infrastructure (auth, storage, logging) while maintaining clear boundaries. As utilization requirements become known, individual services can be extracted into separate deployments without changing their interfaces.
Quick Start Pattern
import "github.com/dpup/prefab"
func main() {
s := prefab.New(
prefab.WithPort(8080),
prefab.WithPlugin(auth.Plugin()),
// Add more options...
)
s.RegisterService(
&myservice.MyService_ServiceDesc,
myservice.RegisterMyServiceHandler,
&myServiceImpl{},
)
if err := s.Start(); err != nil {
log.Fatal(err)
}
}
Resources
Load these resources based on the specific task:
Server & Services
- Project Setup - Proto files, Makefile, project structure
- Server Setup - Server creation, initialization, and basic configuration
- gRPC & HTTP - Registering services, HTTP handlers, static files
Authentication & Authorization
- Authentication - OAuth, password auth, magic links, fake auth for testing
- OAuth Server - Build an OAuth2 authorization server for third-party apps
- Authorization - Declarative access control with proto annotations, policies, role describers
Features
- SSE Streaming - Server-Sent Events for real-time updates
- Configuration - YAML, environment variables, functional options
- Storage - Storage plugins (memory, SQLite)
- File Uploads - File upload/download with authorization
- Email - SMTP email sending
- Templates - Go HTML template rendering
- Event Bus - Publish/subscribe inter-plugin communication
Development
- Custom Plugins - Creating plugins with dependencies and lifecycle
- Error Handling - Stack traces, gRPC codes, log fields
- Logging - Structured context-aware logging
- Security - CSRF, headers, HTTPS, token security
Code Style
- Use
errors.New(), errors.NewC(), errors.Wrap() for errors with stack traces
- Standard library imports first, then third-party
- Document public APIs with GoDoc comments
- Follow plugin interface patterns with
Plugin() function and PluginName constant
When to Load Resources
| Task |
Resources to Load |
| Starting a new project |
project-setup.md, server-setup.md |
| Creating a new server |
server-setup.md, configuration.md, logging.md |
| Adding authentication |
auth.md, server-setup.md |
| Building an OAuth server |
oauth-server.md, auth.md, storage.md |
| Setting up access control |
authz.md, auth.md |
| Adding real-time features |
sse.md |
| Creating a custom plugin |
plugins.md, eventbus.md |
| Handling errors properly |
errors.md, logging.md |
| Security review |
security.md |
| Adding storage |
storage.md |
| Adding HTTP/gRPC endpoints |
grpc-http.md |
| Adding file uploads |
uploads.md, authz.md |
| Sending emails |
email.md, templates.md |
| Rendering templates |
templates.md |
| Inter-plugin communication |
eventbus.md |
| Setting up logging |
logging.md |
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: dpup-prefab-prefab-dev3description: Prefab Development Guide4---56# Prefab Development Guide78Prefab is a Go server framework that simplifies building production-ready gRPC and HTTP services with a plugin-based architecture.910## Core Concepts1112- **Server**: Central component that manages gRPC/HTTP services and plugins13- **Plugins**: Modular components for auth, storage, templates, etc.14- **Services**: gRPC service implementations with automatic HTTP gateway15- **Handlers**: Custom HTTP handlers for non-gRPC endpoints1617Prefab servers commonly compose multiple gRPC services into a single process. This enables a service-oriented monolith architecture where related services share infrastructure (auth, storage, logging) while maintaining clear boundaries. As utilization requirements become known, individual services can be extracted into separate deployments without changing their interfaces.1819## Quick Start Pattern2021```go22import "github.com/dpup/prefab"2324func main() {25 s := prefab.New(26 prefab.WithPort(8080),27 prefab.WithPlugin(auth.Plugin()),28 // Add more options...29 )3031 s.RegisterService(32 &myservice.MyService_ServiceDesc,33 myservice.RegisterMyServiceHandler,34 &myServiceImpl{},35 )3637 if err := s.Start(); err != nil {38 log.Fatal(err)39 }40}41```4243## Resources4445Load these resources based on the specific task:4647### Server & Services48- **[Project Setup](resources/project-setup.md)** - Proto files, Makefile, project structure49- **[Server Setup](resources/server-setup.md)** - Server creation, initialization, and basic configuration50- **[gRPC & HTTP](resources/grpc-http.md)** - Registering services, HTTP handlers, static files5152### Authentication & Authorization53- **[Authentication](resources/auth.md)** - OAuth, password auth, magic links, fake auth for testing54- **[OAuth Server](resources/oauth-server.md)** - Build an OAuth2 authorization server for third-party apps55- **[Authorization](resources/authz.md)** - Declarative access control with proto annotations, policies, role describers5657### Features58- **[SSE Streaming](resources/sse.md)** - Server-Sent Events for real-time updates59- **[Configuration](resources/configuration.md)** - YAML, environment variables, functional options60- **[Storage](resources/storage.md)** - Storage plugins (memory, SQLite)61- **[File Uploads](resources/uploads.md)** - File upload/download with authorization62- **[Email](resources/email.md)** - SMTP email sending63- **[Templates](resources/templates.md)** - Go HTML template rendering64- **[Event Bus](resources/eventbus.md)** - Publish/subscribe inter-plugin communication6566### Development67- **[Custom Plugins](resources/plugins.md)** - Creating plugins with dependencies and lifecycle68- **[Error Handling](resources/errors.md)** - Stack traces, gRPC codes, log fields69- **[Logging](resources/logging.md)** - Structured context-aware logging70- **[Security](resources/security.md)** - CSRF, headers, HTTPS, token security7172## Code Style7374- Use `errors.New()`, `errors.NewC()`, `errors.Wrap()` for errors with stack traces75- Standard library imports first, then third-party76- Document public APIs with GoDoc comments77- Follow plugin interface patterns with `Plugin()` function and `PluginName` constant7879## When to Load Resources8081| Task | Resources to Load |82|------|-------------------|83| Starting a new project | project-setup.md, server-setup.md |84| Creating a new server | server-setup.md, configuration.md, logging.md |85| Adding authentication | auth.md, server-setup.md |86| Building an OAuth server | oauth-server.md, auth.md, storage.md |87| Setting up access control | authz.md, auth.md |88| Adding real-time features | sse.md |89| Creating a custom plugin | plugins.md, eventbus.md |90| Handling errors properly | errors.md, logging.md |91| Security review | security.md |92| Adding storage | storage.md |93| Adding HTTP/gRPC endpoints | grpc-http.md |94| Adding file uploads | uploads.md, authz.md |95| Sending emails | email.md, templates.md |96| Rendering templates | templates.md |97| Inter-plugin communication | eventbus.md |98| Setting up logging | logging.md |99100---101> Converted and distributed by [TomeVault](https://tomevault.io/claim/dpup) — claim your Tome and manage your conversions.102<!-- tomevault:4.0:skill_md:2026-04-13 -->