Build production-ready REST APIs in Go with automatic code generation
ποΈ Code Generator for Go REST APIs Transform Go structs into production-ready REST APIs with OpenAPI specs, storage backends, and middleware in minutes.
| Resource | Description |
|---|---|
| Full Documentation | Complete guides, tutorials, and best practices |
| API Reference (GoDoc) | Comprehensive Go package documentation |
| Quickstart | Five minute quickstart |
| Getting Started Guide | Step-by-step introduction to Fabrica |
| Examples | Hands-on learning with real-world projects |
| MCP Mode | Configure Fabrica as an MCP server for coding agents |
Fabrica is a powerful code generation tool that accelerates API development by transforming simple Go struct definitions into complete, production-ready REST APIs. Define your resources once, and Fabrica generates everything you need: handlers, storage layers, clients, validation, OpenAPI documentation, and more.
- π Zero-Config Generation - Define resources as Go structs, get complete APIs instantly
- π Multiple Storage Backends - Choose between file-based storage or SQL databases (SQLite, PostgreSQL, MySQL)
- π Security Ready - Flexible middleware system for custom authentication and authorization
- π OpenAPI Native - Auto-generated specs with Swagger UI out of the box
- π― Smart Validation - Request validation with detailed, structured error responses
- β‘ Developer Experience - CLI tools, hot-reload development, comprehensive testing
- π‘ CloudEvents Integration - Automatic event publishing for resource lifecycle (CRUD) and condition changes
- π Cloud-Native Ready - Hub/spoke API versioning, conditional requests (ETags), event-driven patterns
- π API Versioning (Hub/Spoke) - Kubebuilder-style versioning with automatic conversion between versions
- ποΈ Production Patterns - Consistent API structure, error handling, and middleware
- Microservices Architecture - Maintain consistent API patterns across services
- Rapid Prototyping - From struct definition to running API in under 5 minutes
- API Standardization - Enforce best practices and patterns across development teams
- OpenAPI-First Development - Generate comprehensive documentation alongside your code
macOS/Linux:
# Direct download and install
curl -L https://github.com/openchami/fabrica/releases/download/v0.4.1/fabrica-$(uname -s)-$(uname -m) -o fabrica
chmod +x fabrica
sudo mv fabrica /usr/local/bin/
# Verify installation
fabrica versionUsing Go:
go install github.com/openchami/fabrica/cmd/fabrica@v0.4.1git clone https://github.com/openchami/fabrica.git
cd fabrica
make installFor local codegen testing against your checkout without editing a generated project's go.mod, run:
fabrica generate --fabrica-source /path/to/fabricaOr set an environment variable for the session:
export FABRICA_SOURCE_PATH=/path/to/fabrica
fabrica generateThis override only affects fabrica generate; projects that do not opt in continue to use the released Fabrica module resolved from their own go.mod.
Fabrica can run as a local MCP server over stdio:
fabrica mcp --workspace /path/to/workspaceUse the workspace root that contains the projects the agent may inspect or modify. If fabrica is not on your PATH, replace fabrica with the absolute path to the binary. Mutating MCP tools default to dry-run behavior; pass mode: "execute" when you want the agent to apply changes.
Add Fabrica as a local stdio MCP server:
claude mcp add fabrica -- fabrica mcp --workspace /path/to/workspaceFor a project-scoped configuration, add .mcp.json at the project root:
{
"mcpServers": {
"fabrica": {
"command": "fabrica",
"args": ["mcp", "--workspace", "/path/to/workspace"]
}
}
}Register the server from the Codex CLI:
codex mcp add fabrica -- fabrica mcp --workspace /path/to/workspaceOr add it to ~/.codex/config.toml:
[mcp_servers.fabrica]
command = "fabrica"
args = ["mcp", "--workspace", "/path/to/workspace"]After connecting, ask the agent to call describe_workflow with goal: "new_crud_api" for guided API construction, or call tools such as inspect_project, validate_project, define_resource_schema, add_resource, generate_code, sync_dependencies, and build_project directly.
Explore hands-on examples in the examples/ directory:
- Basic CRUD β‘ - Start here! Complete CRUD API in 5 minutes
- FRU Service π - Production patterns with database integration
- Rack Reconciliation π - Event-driven resource management
- CloudEvents Integration π‘ - Automatic event publishing for lifecycle and condition changes
- Status Subresource π‘οΈ - Separate spec and status updates
- Export/Import πΎ - Offline backup and restore operations
π Learning Path: Start with Example 1 to understand core concepts, try Example 5 for CloudEvents, then advance to Example 3 for production patterns and database integration.
Fabrica follows clean architecture principles and generates well-structured projects:
π Generated Project Structure
βββ π cmd/
β βββ π server/ # π REST API server with all endpoints
β βββ π cli/ # π₯οΈ Command-line client tools
βββ π pkg/
β βββ π client/ # π Generated HTTP client with proper error handling
βββ π apis/ # π Your versioned resource types (you write these)
β βββ π <group>/<version>/ # e.g., example.fabrica.dev/v1/*_types.go
βββ π internal/
β βββ π storage/ # πΎ Generated storage layer (file or database)
β βββ π middleware/ # βοΈ Generated middleware (auth, validation, etc.)
βββ π docs/ # π Generated OpenAPI specs and documentation
βββ π .fabrica.yaml # βοΈ Project configuration
πͺ Storage Backends:
- π File Backend - JSON files with atomic operations, perfect for development and small datasets
- ποΈ Ent Backend - Type-safe ORM supporting SQLite, PostgreSQL, MySQL for production workloads
β‘ Generated Features:
- β REST handlers with proper HTTP methods, status codes, and content negotiation
- β Comprehensive request/response validation with structured error messages
- β OpenAPI 3.0 specifications with interactive Swagger UI
- β Type-safe HTTP clients with automatic retries and error handling
- β CLI tools for testing, administration, and automation
- β Middleware for authentication, authorization, versioning, and caching
β οΈ IMPORTANT: Code RegenerationFabrica supports regenerating code when you modify your resources or configuration. This means:
β SAFE TO EDIT:
apis/<group>/<version>/*_types.go- Your resource definitions (spec/status structs)apis.yaml- API group and version configuration.fabrica.yaml- Feature flags and project settingscmd/server/main.go- Server customizations (before first// Generatedcomment)β NEVER EDIT:
- Any file ending in
_generated.go- These are completely regenerated on eachfabrica generate- Files in generated directories after running
fabrica generateπ Regeneration Command:
fabrica generate # Safely regenerates all *_generated.go filesYour custom code in resource definitions and main.go will be preserved, but all generated files will be completely rewritten.
Fabrica uses a Kubernetes-inspired envelope pattern that provides consistent structure across all resources. Every API resource follows this standardized format:
{
"apiVersion": "v1",
"kind": "Device",
"metadata": {
"name": "web-server-01",
"uid": "550e8400-e29b-41d4-a716-446655440000",
"labels": {
"environment": "production",
"team": "platform"
},
"annotations": {
"description": "Primary web server for customer portal"
},
"createdAt": "2025-10-15T10:30:00Z",
"updatedAt": "2025-10-15T14:22:15Z"
},
"spec": {
"type": "server",
"ipAddress": "192.168.1.100",
"status": "active",
"port": 443,
"tags": {"role": "web", "datacenter": "us-west-2"}
},
"status": {
"health": "healthy",
"uptime": 2592000,
"lastChecked": "2025-10-15T14:22:15Z",
"errorCount": 0,
"version": "1.2.3"
}
}| Component | Purpose | Your Code | Generated |
|---|---|---|---|
apiVersion |
API compatibility versioning | β | β Auto-managed |
kind |
Resource type identifier | β | β From struct name |
metadata |
Resource identity & organization | β | β Standard fields |
spec |
Desired state (your data) | β You define | β |
status |
Observed state (runtime info) | β You define | β |
spec struct - The desired configuration/state of your resource:
type DeviceSpec struct {
Type string `json:"type" validate:"required,oneof=server switch router"`
IPAddress string `json:"ipAddress" validate:"required,ip"`
Status string `json:"status" validate:"oneof=active inactive maintenance"`
// ... your business logic fields
}status struct - The observed/runtime state of your resource:
type DeviceStatus struct {
Health string `json:"health" validate:"oneof=healthy degraded unhealthy"`
Uptime int64 `json:"uptime"`
LastChecked time.Time `json:"lastChecked"`
// ... your runtime/monitoring fields
}- π Consistency - All resources follow the same structure regardless of domain
- π·οΈ Rich Metadata - Built-in support for labels, annotations, and timestamps
- π State Separation - Clear distinction between desired (
spec) and observed (status) state - π§ Tooling Integration - Compatible with Kubernetes tooling and patterns
- π Scalability - Proven pattern used by Kubernetes for managing complex systems
π‘ Pro Tip: Focus on designing your
specandstatusstructs - Fabrica handles all the envelope complexity automatically!
π Quick Learning:
- Complete Getting Started Guide - Step-by-step tutorial
- Quickstart Examples - Hands-on learning with working code
- Full Documentation Website - All guides and tutorials
ποΈ Architecture & Design:
- Architecture Overview - Understanding Fabrica's design principles
- Resource Model Guide - How to design and define resources
- API Versioning Guide - Hub/Spoke versioning patterns
- API Configuration Reference - apis.yaml structure and workflows
πΎ Storage & Data:
- Storage Systems - File vs database backends comparison
- Ent Storage Integration - Database setup and configuration
βοΈ Advanced Topics:
- Code Generation Reference - How templates work and customization
- CLI Command Reference - Complete CLI documentation with flags and workflows
- Middleware Customization - Adding custom middleware for authentication, logging, etc.
- Validation System - Request validation and error handling
- Event System - CloudEvents integration and event-driven patterns
- Reconciliation - Controller pattern for resource management
- Conditional Requests & PATCH - ETag-based preconditions
π API Documentation:
- GoDoc Package Reference - Complete Go API documentation
We welcome contributions from the community! Here's how to get involved:
π Report Issues:
π» Code Contributions:
- Fork the repository and create a feature branch
- Write tests for your changes
- Ensure all tests pass:
make test integration - Submit a pull request with a clear description
π¬ Community:
- GitHub Discussions - Ask questions and share ideas
Current Version: v0.4.1
π Recent Updates:
- β Hub/Spoke API versioning with automatic conversion
- β Flattened resource envelope with explicit fields (breaking change)
- β
Version registry and
apis.yamlconfiguration support - β SQLite foreign key defaults fixed for Ent storage
π Resources:
- π Release Notes - Detailed changelog for each version
- Full Changelog - Complete project history
This project is licensed under the MIT License - see the license file for details.