An open API service indexing awesome lists of open source software.

https://github.com/xraph/forge

A very opionated distributed backend framework with everything in between.
https://github.com/xraph/forge

Last synced: 10 days ago
JSON representation

A very opionated distributed backend framework with everything in between.

Awesome Lists containing this project

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](https://img.shields.io/badge/Go-1.24+-00ADD8?style=flat&logo=go)](https://golang.org/)
[![Go Report Card](https://goreportcard.com/badge/github.com/xraph/forge)](https://goreportcard.com/report/github.com/xraph/forge)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
[![GitHub Stars](https://img.shields.io/github/stars/xraph/forge)](https://github.com/xraph/forge)
[![CI](https://github.com/xraph/forge/actions/workflows/go.yml/badge.svg)](https://github.com/xraph/forge/actions/workflows/go.yml)

---

## πŸš€ Quick Start

### Installation

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

# Verify installation
forge --version
```

### Forge Your First App

```bash
# Initialize a new project
forge init my-app

# Start the development server
forge dev
```

### Minimal Example

```go
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!",
})
})

// 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

- [**Installation Guide**](docs/content/docs/getting-started/installation.mdx)
- [**Quick Start**](docs/content/docs/getting-started/quick-start.mdx)
- [**Architecture**](docs/content/docs/architecture/index.mdx)
- [**Examples**](examples/)

### Core Concepts

- [**Application Lifecycle**](docs/content/docs/core/lifecycle.mdx)
- [**Dependency Injection**](docs/content/docs/core/dependency-injection.mdx)
- [**Routing**](docs/content/docs/core/routing.mdx)
- [**Middleware**](docs/content/docs/core/middleware.mdx)
- [**Configuration**](docs/content/docs/core/configuration.mdx)
- [**Observability**](docs/content/docs/core/observability.mdx)

### Extensions

- [**AI Extension**](extensions/ai/README.md) - LLM integration and AI agents
- [**Auth Extension**](extensions/auth/README.md) - Authentication providers
- [**Database Extension**](extensions/database/) - SQL and NoSQL databases
- [**GraphQL Extension**](extensions/graphql/README.md) - GraphQL server
- [**gRPC Extension**](extensions/grpc/README.md) - gRPC services
- [**Streaming Extension**](extensions/streaming/) - WebSocket and SSE

### CLI Reference

- [**CLI Documentation**](cli/README.md)
- [**Commands Reference**](cmd/forge/COMMANDS.md)

---

## 🌟 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

```go
// 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

```go
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

```bash
# Build the CLI
make build

# Build with debug symbols
make build-debug

# Build for all platforms
make release
```

### Run Tests

```bash
# Run all tests
make test

# Run with coverage
make test-coverage

# Run specific package
go test ./extensions/ai/...
```

### Code Quality

```bash
# 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

```bash
# 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:

- **[Minimal App](examples/minimal-app/)** - Hello World
- **[Configuration](examples/config-example/)** - Config management
- **[Database](examples/database-demo/)** - Database integration
- **[Auth](extensions/auth/examples/auth_example/)** - Authentication
- **[GraphQL](extensions/graphql/examples/graphql-basic/)** - GraphQL server
- **[gRPC](examples/grpc-basic/)** - gRPC services
- **[WebRTC](examples/webrtc/)** - Real-time communication
- **[MCP](examples/mcp-basic/)** - Model Context Protocol
- **[AI Agents](examples/ai-agents-demo/)** - AI agent system

---

## 🀝 Contributing

We welcome contributions! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.

### Development Workflow

```bash
# 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

```bash
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
```

### Releasing

Releases are managed by [Release Please](https://github.com/googleapis/release-please) and a unified GitHub Actions workflow.

**Automated releases** β€” Push to `main` with conventional commits. Release Please opens a PR with version bumps and changelogs. Merging the PR creates a tag, which triggers the release pipeline.

**Manual releases** β€” Go to [Actions > Release](../../actions/workflows/release.yml), click **Run workflow**, select the module and version, and optionally enable dry-run mode.

The release workflow supports:
- **Main module + CLI**: Builds cross-platform binaries, Docker images, and publishes to Homebrew/Scoop/NFPM via GoReleaser.
- **Extension modules**: Creates a GitHub release and notifies the Go module proxy.
- **Dry run**: Validates the full pipeline without publishing.
- **Skip tests**: For hotfixes when tests have already passed on CI.

---

## πŸ“„ License
This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details.

---

## πŸ™ Acknowledgments

Built with ❀️ by [Rex Raphael](https://github.com/juicycleff)

**Special thanks to:**
- [Bun](https://github.com/uptrace/bun) - SQL ORM
- [Uptrace](https://github.com/uptrace/uptrace) - Observability platform
- [Chi](https://github.com/go-chi/chi) - Router inspiration
- All contributors and maintainers

---

## πŸ”— Links

- **[Documentation](https://forge.dev)** - Comprehensive docs
- **[GitHub](https://github.com/xraph/forge)** - Source code
- **[Issues](https://github.com/xraph/forge/issues)** - Bug reports
- **[Discussions](https://github.com/xraph/forge/discussions)** - Questions and ideas
- **[Examples](examples/)** - Code examples
- **[CLI Reference](cli/README.md)** - CLI documentation

---

## πŸ“œ 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](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](extensions/ai/LICENSE) for full terms or [LICENSING.md](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 β†’](docs/content/docs/getting-started/quick-start.mdx)