{"id":16589926,"url":"https://github.com/rlch/implgen","last_synced_at":"2025-10-25T21:45:23.157Z","repository":{"id":254378500,"uuid":"838173744","full_name":"rlch/implgen","owner":"rlch","description":"Code generator for the Repository design pattern in Golang","archived":false,"fork":false,"pushed_at":"2025-02-27T13:38:10.000Z","size":118,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-27T19:21:47.364Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rlch.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2024-08-05T05:20:35.000Z","updated_at":"2025-02-27T13:38:13.000Z","dependencies_parsed_at":null,"dependency_job_id":"be0941b6-5284-46e4-8174-73ae88114d10","html_url":"https://github.com/rlch/implgen","commit_stats":null,"previous_names":["rlch/implgen"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rlch%2Fimplgen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rlch%2Fimplgen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rlch%2Fimplgen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rlch%2Fimplgen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rlch","download_url":"https://codeload.github.com/rlch/implgen/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242208310,"owners_count":20089718,"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","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":[],"created_at":"2024-10-11T23:10:28.109Z","updated_at":"2025-10-25T21:45:23.150Z","avatar_url":"https://github.com/rlch.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# implgen\n\nA flexible Go code generator that automatically creates implementation boilerplate for Go interfaces with configurable patterns.\n\n## Overview\n\n`implgen` streamlines the development of Go applications by automatically generating implementation files for interfaces. It parses interface definitions with configurable suffixes (Repository, Service, Handler, etc.) from an API directory and creates corresponding implementation files with proper dependency injection, observability, and error handling.\n\n## Features\n\n- 🎯 **Configurable Patterns**: Support for any interface suffix (Repository, Service, Handler, etc.)\n- 🏗️ **Dependency Injection**: Supports both fx and dig frameworks\n- 📊 **Observability**: Automatic OpenTelemetry tracing for context methods\n- 🔄 **Incremental Updates**: Preserves existing implementations, adds missing methods\n\n## Installation\n\n```bash\ngo install github.com/rlch/implgen@latest\n```\n\n## Quick Start\n\n### 1. Project Structure\n\nOrganize your Go project with API interfaces and implementation directories:\n\n```\nyour-project/\n├── api/\n│   └── user/\n│       ├── repository.go      # Repository interfaces\n│       └── service.go         # Service interfaces\n├── repository/                # Repository implementations\n│   ├── repository.go         # fx.Options for repositories\n│   └── user/\n│       └── user_repository_impl.go\n├── service/                   # Service implementations\n│   ├── service.go            # fx.Options for services\n│   └── user/\n│       └── user_service_impl.go\n└── main.go\n```\n\n### 2. Define Your Interfaces\n\nCreate interfaces with configurable suffixes in your API directory:\n\n```go\n// api/user/repository.go\npackage user\n\nimport \"context\"\n\ntype UserRepository interface {\n    Create(ctx context.Context, user User) error\n    GetByID(ctx context.Context, id string) (User, error)\n    Update(ctx context.Context, user User) error\n    Delete(ctx context.Context, id string) error\n}\n```\n\n```go\n// api/user/service.go\npackage user\n\nimport \"context\"\n\ntype UserService interface {\n    Register(ctx context.Context, user User) error\n    Authenticate(ctx context.Context, email, password string) (User, error)\n    SendWelcomeEmail(ctx context.Context, userID string) error\n}\n```\n\n### 3. Generate Implementations\n\n```bash\n# Generate repository implementations\n./implgen generate --suffix Repository --api api --impl repository\n\n# Generate service implementations  \n./implgen generate --suffix Service --api api --impl service\n```\n\nThis creates separate implementation directories with:\n\n- Proper package structure and imports\n- Dependency injection setup\n- Method stubs with TODO comments\n- OpenTelemetry tracing for context-aware methods\n- Error wrapping for methods returning errors\n\n### 4. Generated Output\n\n```go\n// repository/user/user_repository_impl.go\npackage userimpl\n\nimport (\n    \"context\"\n    \"example/api/user\"\n    \"github.com/Southclaws/fault\"\n    \"github.com/Southclaws/fault/fmsg\"\n    \"go.opentelemetry.io/otel\"\n    \"go.opentelemetry.io/otel/codes\"\n    \"go.uber.org/fx\"\n)\n\ntype UserDependencies struct {\n    fx.In\n    // Add dependencies here\n}\n\nvar UserOptions = fx.Options(fx.Provide(NewUserRepository))\n\nfunc NewUserRepository(deps UserDependencies) user.UserRepository {\n    return \u0026userRepositoryImpl{UserDependencies: deps}\n}\n\ntype userRepositoryImpl struct {\n    UserDependencies\n}\n\nfunc (r *userRepositoryImpl) Create(ctx context.Context, user user.User) (err error) {\n    ctx, span := otel.GetTracerProvider().Tracer(\"user\").Start(ctx, \"User.Create\")\n    defer func() {\n        if err != nil {\n            err = fault.Wrap(err, fmsg.With(\"user.UserRepository.Create\"))\n            span.SetStatus(codes.Error, \"\")\n            span.RecordError(err)\n        }\n        span.End()\n    }()\n    panic(\"TODO: implement user.UserRepository.Create\")\n}\n```\n\n### 5. Recommended Setup with gen.go\n\nCreate a `gen.go` file for easy generation:\n\n```go\npackage main\n\n//go:generate go run github.com/rlch/implgen generate --suffix Repository --api api --impl repository\n//go:generate go run github.com/rlch/implgen generate --suffix Service --api api --impl service\n```\n\nThen run:\n\n```bash\ngo generate\n```\n\n## CLI Usage\n\n### Basic Commands\n\n```bash\n# Generate repository implementations (default behavior)\n./implgen generate\n\n# Generate with specific suffix and directory\n./implgen generate --suffix Repository --api api --impl repository\n\n# Generate service implementations\n./implgen generate --suffix Service --api api --impl service\n\n# Generate handler implementations\n./implgen generate --suffix Handler --api api --impl handler\n\n# Use custom directories\n./implgen generate --suffix Repository --root . --api services --impl implementations\n\n# Focus on specific packages\n./implgen generate --suffix Repository --impl repository --focus \"user/**\"\n./implgen generate --suffix Service --impl service --focus \"user/**\" --focus \"order/**\"\n\n# Use dig instead of fx for dependency injection\n./implgen generate --suffix Repository --impl repository --dig\n\n# Enable verbose logging\n./implgen --verbose generate --suffix Service --impl service\n```\n\n### Command Reference\n\n| Flag        | Description                                    | Default        |\n| ----------- | ---------------------------------------------- | -------------- |\n| `--root`    | Root directory for the project                 | `.`            |\n| `--api`     | API directory relative to root                 | `api`          |\n| `--impl`    | Implementation directory relative to root      | `internal`     |\n| `--suffix`  | Interface suffix to detect (Repository, Service, etc.) | `Repository` |\n| `--focus`   | Target specific packages with glob patterns    | (all packages) |\n| `--dig`     | Use dig instead of fx for dependency injection | `false`        |\n| `--verbose` | Enable verbose logging                         | `false`        |\n\n## Examples\n\nSee the `example/fx/` directory for a complete working example demonstrating:\n\n- Repository and Service patterns in separate directories\n- Multiple interfaces per package\n- Proper fx dependency injection setup\n- Generated implementations with tracing and error handling\n\n## Troubleshooting\n\n### Common Issues\n\n**Interface not detected**\n\n- Ensure interface name ends with the specified suffix (default: \"Repository\")\n- Check that the file is in the correct API directory\n- Verify Go syntax is valid\n- Use `--verbose` to see what files are being processed\n\n**Build errors with tree-sitter**\n\n- Ensure you have a C compiler installed\n- Use `GOFLAGS=-mod=mod` when building (required for tree-sitter)\n- Tree-sitter dependencies are vendored in the project\n\n**Generated code has import issues**\n\n- Run `go mod tidy` after generation\n- Ensure your module path is correctly set in go.mod\n- Check that API interfaces are in proper Go packages\n\n### Debug Mode\n\nEnable verbose logging to see what implgen is doing:\n\n```bash\n./implgen --verbose generate --suffix Repository --impl repository\n```\n\n## Development\n\n### Running Tests\n\n```bash\ngo test ./...\n```\n\n### Linting\n\n```bash\ngolangci-lint run --config .golangci.yaml ./...\n```\n\n### Building\n\n```bash\ngo build -o implgen .\n```\n\n## Contributing\n\n1. Fork the repository\n2. Create a feature branch\n3. Make your changes\n4. Add tests for new functionality\n5. Ensure all tests pass and code is linted\n6. Submit a pull request\n   j\n\n## License\n\nThis project is licensed under the MIT License - see the LICENSE file for details.\n\n## Roadmap\n\n- [ ] Generate test boilerplate\n- [ ] Support for additional interface patterns\n- [ ] Integration with popular Go frameworks\n- [ ] IDE plugins for seamless development\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frlch%2Fimplgen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frlch%2Fimplgen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frlch%2Fimplgen/lists"}