{"id":31727419,"url":"https://github.com/richgod93/bffgen","last_synced_at":"2025-10-09T06:22:04.004Z","repository":{"id":315477909,"uuid":"1058966377","full_name":"RichGod93/bffgen","owner":"RichGod93","description":"CLI tool for generating secure Backend-for-Frontend (BFF) services with Go","archived":false,"fork":false,"pushed_at":"2025-09-28T22:45:19.000Z","size":19646,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-29T00:19:12.703Z","etag":null,"topics":["backend-for-frontend","cli","cli-tool","code-generator","developer-experience","developer-productivity","golang"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RichGod93.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-09-17T19:50:10.000Z","updated_at":"2025-09-28T22:45:14.000Z","dependencies_parsed_at":"2025-09-18T22:07:45.311Z","dependency_job_id":"5fea9672-fd0f-4ae1-922a-c2a3a2c4948b","html_url":"https://github.com/RichGod93/bffgen","commit_stats":null,"previous_names":["richgod93/bffgen"],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/RichGod93/bffgen","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RichGod93%2Fbffgen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RichGod93%2Fbffgen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RichGod93%2Fbffgen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RichGod93%2Fbffgen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RichGod93","download_url":"https://codeload.github.com/RichGod93/bffgen/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RichGod93%2Fbffgen/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279000849,"owners_count":26082950,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-09T02:00:07.460Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["backend-for-frontend","cli","cli-tool","code-generator","developer-experience","developer-productivity","golang"],"created_at":"2025-10-09T06:22:00.130Z","updated_at":"2025-10-09T06:22:03.996Z","avatar_url":"https://github.com/RichGod93.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# bffgen\n\n**Backend-for-Frontend (BFF) generator** - Scaffold secure, production-ready BFF services in Go with enhanced backend architecture support, JWT auth, rate limiting, and comprehensive logging.\n\n[![Go Version](https://img.shields.io/badge/Go-1.21+-blue.svg)](https://golang.org/)\n[![License](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)\n[![Latest Release](https://img.shields.io/badge/Latest-v1.0.1-brightgreen.svg)](https://github.com/RichGod93/bffgen/releases/v1.0.1)\n\n---\n\n## ⚡ Quick Start\n\n```bash\n# Install latest version with enhanced backend architecture support\ngo install github.com/RichGod93/bffgen/cmd/bffgen@v1.0.1\n\n# Create BFF with your preferred backend architecture\nbffgen init my-bff\n# Choose: 1) Microservices, 2) Monolithic, 3) Hybrid\ncd my-bff\n\n# Start backend services (configurable URLs from init)\n# Then run the BFF server\ngo run main.go\n```\n\n**Example Output:**\n\n```text\n✅ BFF project 'my-bff' initialized successfully!\n\n📋 Backend Configuration Summary:\n   Architecture: Monolithic\n   - Backend: http://localhost:3000/api\n   - Services: users, products, orders, cart, auth\n\n🔧 Setup Instructions:\n   1. Start your monolithic backend: http://localhost:3000/api\n   2. Run the BFF server: cd my-bff \u0026\u0026 go run main.go\n   3. Test endpoints: curl http://localhost:8080/health\n\n📁 Navigate to the project: cd my-bff\n🚀 Start development server: go run main.go\n\n🔐 Secure Authentication Setup:\n   1. Set encryption key: export ENCRYPTION_KEY=\u003ckey\u003e\n   2. Set JWT secret: export JWT_SECRET=\u003ckey\u003e\n   3. Features: Encrypted JWT tokens, secure sessions, CSRF protection\n   4. Auth endpoints: /api/auth/login, /api/auth/refresh, /api/auth/logout\n```\n\n---\n\n## 🛠️ Commands\n\n| Command        | Description                          |\n| -------------- | ------------------------------------ |\n| `init`         | Scaffold new BFF project             |\n| `add-route`    | Add backend endpoint interactively   |\n| `add-template` | Add auth/ecommerce/content templates |\n| `generate`     | Generate Go code from config         |\n| `postman`      | Create Postman collection            |\n| `dev`          | Run development server               |\n| `config`       | Manage global configuration          |\n\n---\n\n## ✨ Features\n\n### 🏗️ **Enhanced Backend Architecture Support**\n\n- **Microservices**: Different ports/URLs for each service\n- **Monolithic**: Single port/URL for all services\n- **Hybrid**: Services on same port with different paths\n- **Smart Configuration**: Auto-generates tailored bff.config.yaml\n- **Intelligent Defaults**: Smart port numbering and URL suggestions\n\n### 🔒 Security Features\n\n- **JWT Authentication** - Token validation with user context injection\n- **Rate Limiting** - Fiber built-in, Chi/Echo with Redis\n- **Security Headers** - XSS, CSRF, Content-Type protection\n- **CORS Configuration** - Restrictive origins, credentials support\n- **Request Validation** - Size limits, content-type validation\n\n---\n\n## 📦 Installation\n\n**Quick Install (Latest v1.0.1):**\n\n```bash\ngo install github.com/RichGod93/bffgen/cmd/bffgen@v1.0.1\n```\n\n**Latest Stable:**\n\n```bash\ngo install github.com/RichGod93/bffgen/cmd/bffgen@latest\n```\n\n**From Source:**\n\n```bash\ngit clone https://github.com/RichGod93/bffgen\ncd bffgen \u0026\u0026 go build -o bffgen ./cmd/bffgen\nsudo mv bffgen /usr/local/bin/\n```\n\n---\n\n## 🚀 Usage Examples\n\n### Initialize Project with Backend Architecture\n\n```bash\nbffgen init my-bff\n✔ Which framework? (chi/echo/fiber) [chi]: fiber\n✔ Frontend URLs (comma-separated) [localhost:3000,localhost:3001]: localhost:5173\n✔ What's your backend architecture?\n  1) Microservices (different ports/URLs)\n  2) Monolithic (single port/URL)\n  3) Hybrid (some services on same port)\n✔ Select option (1-3) [1]: 2\n✔ Backend base URL (e.g., 'http://localhost:3000/api'): http://localhost:3000/api\n✔ Configure routes now or later?\n  1) Define manually\n  2) Use a template\n  3) Skip for now\n✔ Select option (1-3) [3]: 3\n```\n\n### Example: Microservices Architecture\n\n```bash\nbffgen init my-microservices-bff\n✔ Which framework? (chi/echo/fiber) [chi]: chi\n✔ Frontend URLs (comma-separated) [localhost:3000,localhost:3001]: localhost:5173\n✔ What's your backend architecture?\n  1) Microservices (different ports/URLs)\n  2) Monolithic (single port/URL)\n  3) Hybrid (some services on same port)\n✔ Select option (1-3) [1]: 1\n🔧 Configuring Microservices Backend\n✔ Service name (e.g., 'users', 'products', 'orders'): users\n✔ Base URL for users (e.g., 'http://localhost:4000/api'): http://localhost:4000/api\n✅ Added users service on http://localhost:4000/api\n✔ Service name (e.g., 'users', 'products', 'orders'): products\n✔ Base URL for products (e.g., 'http://localhost:4000/api'): http://localhost:5000/api\n✅ Added products service on http://localhost:5000/api\n✔ Service name (e.g., 'users', 'products', 'orders'):\n✔ Configure routes now or later?\n  1) Define manually\n  2) Use a template\n  3) Skip for now\n✔ Select option (1-3): 3\n\n✅ BFF project 'my-microservices-bff' initialized successfully!\n\n📋 Backend Configuration Summary:\n   Architecture: Microservices\n   - users: http://localhost:4000/api\n   - products: http://localhost:5000/api\n\n🔧 Setup Instructions:\n   1. Start your microservices on the configured ports:\n      - users: http://localhost:4000/api\n      - products: http://localhost:5000/api\n   2. Run the BFF server:\n      cd my-microservices-bff\n      go run main.go\n   3. Test the endpoints:\n      curl http://localhost:8080/health\n\n📁 Navigate to the project: cd my-microservices-bff\n🚀 Start development server: go run main.go\n```\n\n### Working with Templates (Optional Routes)\n\n```bash\n# Add routes using templates\nbffgen add-template auth\n# 📁 Template added: internal/templates/auth.yaml\n\n# Add manual routes\nbffgen add-route\n# ✔ Service name: payments\n# ✔ Endpoint path: /api/payments\n# ✔ HTTP method [GET]:\n\n# Generate routes in main.go when ready\nbffgen generate\n# ✅ Code generation completed!\n# 📁 Updated: main.go (with proxy routes)\n```\n\n### Run Development Server\n\n```bash\n# Your project structure is ready! No generation needed.\nls -la my-microservices-bff/\n# bff.config.yaml  go.mod  main.go  README.md  internal/\n\n# Start your backend services first\n# Users API: http://localhost:4000/api\n# Products API: http://localhost:5000/api\n\n# Then run the BFF server\ncd my-microservices-bff\ngo run main.go\n# 🚀 BFF server starting on :8080\n```\n\n### Create Postman Collection\n\n```bash\nbffgen postman\n# 📮 Generating Postman collection from bff.config.yaml\n# ✅ Postman collection generated successfully!\n# 📁 Created file: bff-postman-collection.json\n```\n\n---\n\n## ⚙️ Configuration\n\nbffgen saves your preferences in `~/.bffgen/bffgen.yaml` for re-runs:\n\n### View Configuration\n\n```bash\nbffgen config show\n```\n\n### Set Defaults\n\n```bash\nbffgen config set framework fiber\nbffgen config set cors_origins localhost:5173,myapp.com\nbffgen config set jwt_secret my-super-secret-key\nbffgen config set redis_url redis://localhost:6379\nbffgen config set port 3000\nbffgen config set route_option 2\n```\n\n### Reset Configuration\n\n```bash\nbffgen config reset\n```\n\n**Configuration File Location:** `~/.bffgen/bffgen.yaml`\n\n---\n\n## 🔴 Redis Setup (Chi/Echo Only)\n\n```bash\n# macOS\nbrew install redis \u0026\u0026 brew services start redis\n\n# Ubuntu\nsudo apt install redis-server \u0026\u0026 sudo systemctl start redis-server\n\n# Docker\ndocker run -d -p 6379:6379 redis:alpine\n\n# Verify\nredis-cli ping  # Should return: PONG\n```\n\n**Note:** Fiber includes built-in rate limiting, no Redis needed.\n\n---\n\n## 🔐 JWT Authentication\n\n### Environment Setup\n\n```bash\nexport JWT_SECRET=your-super-secure-secret-key-change-in-production\n```\n\n### Token Generation\n\n```go\nimport \"github.com/golang-jwt/jwt/v5\"\n\nclaims := jwt.MapClaims{\n    \"user_id\": \"123\",\n    \"email\": \"user@example.com\",\n    \"exp\": time.Now().Add(time.Hour * 24).Unix(),\n}\n\ntoken := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)\ntokenString, err := token.SignedString([]byte(os.Getenv(\"JWT_SECRET\")))\n```\n\n### Usage\n\n```bash\ncurl -H \"Authorization: Bearer \u003cyour-jwt-token\u003e\" http://localhost:8080/api/protected\n```\n\n---\n\n## 📂 Project Structure\n\n```text\nmy-bff/\n├── main.go                 # Generated server with routes\n├── bff.config.yaml         # Service configuration\n├── go.mod                  # Dependencies\n├── README.md               # Project docs\n└── internal/\n    ├── routes/             # Route definitions\n    ├── aggregators/        # Data aggregation\n    └── templates/          # Template files\n```\n\n---\n\n## 🤝 Contributing\n\n1. Fork the repository\n2. Create feature branch (`git checkout -b feature/amazing-feature`)\n3. Commit changes (`git commit -m 'Add amazing feature'`)\n4. Push to branch (`git push origin feature/amazing-feature`)\n5. Open Pull Request\n\n---\n\n## 📄 License\n\nMIT License - see [LICENSE](LICENSE) file for details.\n\n---\n\n## 🙏 Acknowledgments\n\n- [Chi Router](https://github.com/go-chi/chi) - Lightweight HTTP router\n- [Cobra](https://github.com/spf13/cobra) - CLI framework\n- [JWT](https://github.com/golang-jwt/jwt) - JSON Web Tokens\n- Inspired by [Backend-for-Frontend pattern](https://martinfowler.com/articles/bff.html) by Martin Fowler\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frichgod93%2Fbffgen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frichgod93%2Fbffgen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frichgod93%2Fbffgen/lists"}