forge

module
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2025 License: Apache-2.0

README ΒΆ

πŸ”¨ Forge

Forgeβ„’ is a backend framework, and Forge Cloudβ„’ is its AI cloud offering, maintained by XRAPHβ„’.

Enterprise-Grade Web Framework for Go

Build scalable, maintainable, and observable Go applications with Forgeβ€”the modern framework that brings clean architecture, dependency injection, and powerful extensions to your production services.

Go Version License GitHub Stars CI/CD


πŸš€ Quick Start

Installation
# Install the Forge CLI
go install github.com/xraph/forge/cmd/forge@latest

# Verify installation
forge --version
Forge Your First App
# Initialize a new project
forge init my-app

# Start the development server
forge dev
Minimal Example
package main

import "github.com/xraph/forge"

func main() {
    // Create app with default configuration
    app := forge.NewApp(forge.AppConfig{
        Name:        "my-app",
        Version:     "1.0.0",
        Environment: "development",
        HTTPAddress: ":8080",
    })

    // Register routes
    router := app.Router()
    router.GET("/", func(ctx forge.Context) error {
        return ctx.JSON(200, map[string]string{
            "message": "Hello, Forge v2!",
        })
    })

    // Run the application (blocks until SIGINT/SIGTERM)
    app.Run()
}

Built-in endpoints:

  • /_/info - Application information
  • /_/metrics - Prometheus metrics
  • /_/health - Health checks

✨ Key Features

πŸ—οΈ Core Framework
  • βœ… Dependency Injection - Type-safe container with service lifecycle
  • βœ… HTTP Router - Fast, lightweight routing with middleware support
  • βœ… Middleware - Auth, CORS, logging, rate limiting, and more
  • βœ… Configuration - YAML/JSON/TOML support with environment variable override
  • βœ… Observability - Structured logging, metrics, distributed tracing
  • βœ… Health Checks - Automatic discovery and reporting
  • βœ… Lifecycle Management - Graceful startup and shutdown
πŸ”Œ Extensions
Extension Description Status
AI LLM integration, agents, inference engine βœ…
Auth Multi-provider authentication (OAuth, JWT, SAML) βœ…
Cache Multi-backend caching (Redis, Memcached, In-Memory) βœ…
Consensus Raft consensus for distributed systems βœ…
Database SQL (Postgres, MySQL, SQLite) + MongoDB support βœ…
Events Event bus and event sourcing βœ…
GraphQL GraphQL server with schema generation βœ…
gRPC gRPC server with reflection βœ…
HLS HTTP Live Streaming βœ…
Kafka Apache Kafka integration βœ…
MCP Model Context Protocol βœ…
MQTT MQTT broker and client βœ…
orpc ORPC transport protocol βœ…
Queue Message queue management βœ…
Search Full-text search (Elasticsearch, Typesense) βœ…
Storage Multi-backend storage (S3, GCS, Local) βœ…
Streaming WebSocket, SSE, WebRTC βœ…
WebRTC Real-time peer-to-peer communication βœ…
πŸ› οΈ CLI Tools
  • βœ… Project Scaffolding - Initialize new projects with templates
  • βœ… Code Generation - Generate handlers, controllers, and services
  • βœ… Database Migrations - Schema management with versioning
  • βœ… Interactive Prompts - Arrow-key navigation, multi-select
  • βœ… Server Management - Development server with hot reload
  • βœ… Testing - Built-in test runner and coverage reports

πŸ“– Documentation

Getting Started
Core Concepts
Extensions
CLI Reference

🌟 Why Forge?

Production-Ready

Forge is built for production from day one:

  • βœ… Graceful Shutdown - Proper resource cleanup on SIGTERM
  • βœ… Health Monitoring - Automatic discovery and reporting
  • βœ… Observability - Metrics, logging, and distributed tracing
  • βœ… Error Handling - Comprehensive error management
  • βœ… Security - Built-in security best practices
Developer Experience
  • βœ… Type Safety - Generics and compile-time guarantees
  • βœ… Zero Config - Sensible defaults with full customization
  • βœ… Hot Reload - Instant feedback during development
  • βœ… CLI Tools - Fast project scaffolding and generation
  • βœ… Rich Docs - Comprehensive documentation and examples
Performance
  • βœ… Low Latency - Optimized HTTP router and middleware
  • βœ… Efficient Routing - Trie-based path matching
  • βœ… Concurrent Safe - Thread-safe components
  • βœ… Memory Efficient - Minimal allocations
Extensible
  • βœ… Extension System - Modular, composable extensions
  • βœ… Plugin Architecture - Easy to add custom functionality
  • βœ… Multi-Backend - Switch implementations without code changes
  • βœ… Middleware Chain - Powerful middleware composition

πŸ›οΈ Architecture

// Application Structure
app := forge.NewApp(forge.AppConfig{
    Name:        "my-service",
    Version:     "1.0.0",
    Environment: "production",
    
    // Extensions
    Extensions: []forge.Extension{
        database.NewExtension(database.Config{
            Databases: []database.DatabaseConfig{
                {
                    Name: "primary",
                    Type: database.TypePostgres,
                    DSN:  "postgres://localhost/mydb",
                },
            },
        }),
        
        auth.NewExtension(auth.Config{
            Provider: "oauth2",
            // ... auth configuration
        }),
    },
})

// Dependency Injection
forge.RegisterSingleton(app.Container(), "userService", func(c forge.Container) (*UserService, error) {
    db, err := database.GetSQL(c)
    if err != nil {
        return nil, err
    }
    logger := forge.Must[forge.Logger](c, "logger")
    return NewUserService(db, logger), nil
})

// Routing
router := app.Router()
router.GET("/users/:id", getUserHandler)
router.POST("/users", createUserHandler)

// Run
app.Run()

🧩 Extension Example

Using the AI Extension
package main

import (
    "github.com/xraph/forge"
    "github.com/xraph/forge/extensions/ai"
)

func main() {
    app := forge.NewApp(forge.AppConfig{
        Extensions: []forge.Extension{
            ai.NewExtension(ai.Config{
                LLMProviders: map[string]ai.LLMProviderConfig{
                    "openai": {
                        APIKey: os.Getenv("OPENAI_API_KEY"),
                        Model:  "gpt-4",
                    },
                },
            }),
        },
    })

    // Access AI service via DI using helper function
    aiService, err := ai.GetAIService(app.Container())
    if err != nil {
        log.Fatal(err)
    }

    // Use in your handlers
    router := app.Router()
    router.POST("/chat", func(ctx forge.Context) error {
        result, err := aiService.Chat(ctx, ai.ChatRequest{
            Messages: []ai.Message{
                {Role: "user", Content: "Hello!"},
            },
        })
        if err != nil {
            return err
        }
        return ctx.JSON(200, result)
    })

    app.Run()
}

πŸ› οΈ Development

Prerequisites
  • Go 1.24+ - Latest Go compiler
  • Make - Build tool (optional but recommended)
Build
# Build the CLI
make build

# Build with debug symbols
make build-debug

# Build for all platforms
make release
Run Tests
# Run all tests
make test

# Run with coverage
make test-coverage

# Run specific package
go test ./extensions/ai/...
Code Quality
# Format code
make fmt

# Run linter
make lint

# Fix linting issues
make lint-fix

# Run security scan
make security-scan

# Check vulnerabilities
make vuln-check
Development Server
# Start development server
forge dev

# Start with hot reload
forge dev --watch

# Start on custom port
forge dev --port 3000

πŸ“Š Project Status

Core Framework
  • βœ… Dependency Injection - Production ready
  • βœ… HTTP Router - Fast, lightweight
  • βœ… Middleware System - Comprehensive
  • βœ… Configuration - Multi-format support
  • βœ… Observability - Metrics, logging, tracing
  • βœ… Health Checks - Automatic discovery
  • βœ… CLI Tools - Full-featured CLI
Extensions (17 total)

Production Ready (14):

  • βœ… AI - LLM integration and agents
  • βœ… Auth - Multi-provider authentication
  • βœ… Cache - Multi-backend caching
  • βœ… Consensus - Raft consensus
  • βœ… Database - SQL and NoSQL
  • βœ… Events - Event bus and sourcing
  • βœ… GraphQL - GraphQL server
  • βœ… gRPC - gRPC services
  • βœ… HLS - HTTP Live Streaming
  • βœ… Kafka - Apache Kafka
  • βœ… MCP - Model Context Protocol
  • βœ… MQTT - MQTT broker
  • βœ… Storage - Multi-backend storage
  • βœ… Streaming - WebSocket, SSE, WebRTC

In Progress (3):

  • πŸ”„ Queue - Message queue management
  • πŸ”„ Search - Full-text search
  • πŸ”„ orpc - ORPC transport protocol

πŸ§ͺ Examples

The examples/ directory contains production-ready examples:


🀝 Contributing

We welcome contributions! Please see CONTRIBUTING.md for guidelines.

Development Workflow
# Fork and clone
git clone https://github.com/your-username/forge.git
cd forge

# Install tools
make install-tools

# Make changes
# ...

# Run tests
make test

# Check code quality
make ci

# Commit with conventional commits
git commit -m "feat: add new feature"
Conventional Commits
feat: add new feature
fix: fix bug in router
docs: update documentation
style: format code
refactor: refactor DI container
perf: optimize routing performance
test: add tests for middleware
chore: update dependencies

πŸ“„ License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.


πŸ™ Acknowledgments

Built with ❀️ by Rex Raphael

Special thanks to:

  • Bun - SQL ORM
  • Uptrace - Observability platform
  • Chi - Router inspiration
  • All contributors and maintainers


πŸ“œ License

Forge uses a dual-licensing approach:

Forge Core & Most Extensions: MIT License

The core framework and most extensions are licensed under the MIT License - one of the most permissive open source licenses.

βœ… Use freely for:

  • Commercial products and services
  • Personal projects
  • Closed-source applications
  • Modifications and distributions

See the LICENSE file for full terms.

AI Extension: Commercial Source-Available License

The AI Extension (extensions/ai/) uses a more restrictive Commercial Source-Available License.

βœ… Free for:

  • Personal projects
  • Educational purposes
  • Research and academic use
  • Internal evaluation (90 days)

❌ Commercial license required for:

  • Production deployments
  • Commercial products/services
  • Revenue-generating applications

See extensions/ai/LICENSE for full terms or LICENSING.md for the complete licensing guide.

Need a commercial license? Contact: licensing@xraph.com


πŸ“ˆ Roadmap

v2.1 (Q1 2025)
  • Complete remaining extensions (Queue, Search, orpc)
  • Enhanced AI agent orchestration
  • Real-time collaboration features
  • Advanced monitoring dashboard
v2.2 (Q2 2025)
  • Kubernetes operator
  • Helm charts and deployment automation
  • Advanced caching strategies
  • Performance optimization pass
v3.0 (Q3 2025)
  • TypeScript/Node.js runtime
  • Multi-language code generation
  • Enhanced observability platform
  • Enterprise features (SLA, auditing, compliance)

Ready to build? Get Started β†’

Directories ΒΆ

Path Synopsis
cli
examples/plugin command
examples/simple command
cmd
forge command
v2/cmd/forge/main.go
v2/cmd/forge/main.go
forge/config
v2/cmd/forge/config/loader.go
v2/cmd/forge/config/loader.go
forge/plugins
v2/cmd/forge/plugins/build.go
v2/cmd/forge/plugins/build.go
forge/plugins/infra
v2/cmd/forge/plugins/infra/generator.go
v2/cmd/forge/plugins/infra/generator.go
examples
ai-agents-demo command
ai-demo command
banner-demo command
cache-demo command
config-example command
context-example command
database-demo command
events-demo command
lifecycle-hooks command
mcp-advanced command
mcp-basic command
minimal-app command
observability command
orpc_example command
service-di command
sse-streaming command
wildcard_routes command
extensions
ai
database
Package database provides unified database access with support for SQL (Postgres, MySQL, SQLite) and NoSQL (MongoDB) databases.
Package database provides unified database access with support for SQL (Postgres, MySQL, SQLite) and NoSQL (MongoDB) databases.
database/migrate
Package migrate provides migration management for the database extension
Package migrate provides migration management for the database extension
mcp
storage
Package storage provides unified object storage with support for multiple backends including local filesystem, S3, GCS, and Azure Blob Storage.
Package storage provides unified object storage with support for multiple backends including local filesystem, S3, GCS, and Azure Blob Storage.
graphql module
grpc module
kafka module
mqtt module
Package farp provides Forge-specific integrations for the FARP protocol.
Package farp provides Forge-specific integrations for the FARP protocol.
examples/basic command
internal
di

Jump to

Keyboard shortcuts

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