{"id":34139817,"url":"https://github.com/abiiranathan/apigen","last_synced_at":"2026-03-09T22:02:53.979Z","repository":{"id":163666227,"uuid":"639129454","full_name":"abiiranathan/apigen","owner":"abiiranathan","description":"apigen is a tool written in go that parses go structs and generates complete REST APIs based on GORM (https://gorm.io) ORM.","archived":false,"fork":false,"pushed_at":"2025-08-30T13:58:30.000Z","size":7475,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-17T15:08:46.677Z","etag":null,"topics":["code-generation","database","go","golang","orm","restful-api","tools"],"latest_commit_sha":null,"homepage":"https://github.com/abiiranathan/apigen","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/abiiranathan.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":"2023-05-10T20:29:02.000Z","updated_at":"2025-08-30T13:56:47.000Z","dependencies_parsed_at":"2024-04-21T12:28:29.734Z","dependency_job_id":"596bf05c-0905-4011-9473-a4451793af6f","html_url":"https://github.com/abiiranathan/apigen","commit_stats":null,"previous_names":[],"tags_count":50,"template":false,"template_full_name":null,"purl":"pkg:github/abiiranathan/apigen","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abiiranathan%2Fapigen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abiiranathan%2Fapigen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abiiranathan%2Fapigen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abiiranathan%2Fapigen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/abiiranathan","download_url":"https://codeload.github.com/abiiranathan/apigen/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abiiranathan%2Fapigen/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30314388,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-09T20:05:46.299Z","status":"ssl_error","status_checked_at":"2026-03-09T19:57:04.425Z","response_time":61,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["code-generation","database","go","golang","orm","restful-api","tools"],"created_at":"2025-12-15T02:29:43.094Z","updated_at":"2026-03-09T22:02:53.969Z","avatar_url":"https://github.com/abiiranathan.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# apigen\n\n`apigen` is a tool written in go that parses go structs and generates code for querying the database based on [GORM](https://gorm.io) ORM.\n\n## Features\n\n- generates services for all structs in your models unless skipped in the configuration file(`apigen.toml`)\n- Created database connection helper with sane defaults.\n- Optionally Preloads all relationships(even nested relationships) by default. Because the parser knows foreign keys and tree, we are able to do that for all `foreignKey` and `many2many` fields.\n- Allows for customizing all queries by specifying optional Where, ordering, grouping, select `options ...services.Options` These options are passed to the callable handlers that are designed with the decorator pattern.\n- Generates typescript interfaces for your models.\n\n## Installation\n\n### As a CLI tool\n\n```console\ngo install github.com/abiiranathan/apigen@latest\n```\n\n### As a library\n\n```console\ngo get -u github.com/abiiranathan/apigen\n```\n\n#### Initialize project and create a configuration file `apigen.toml`\n\n```console\napigen init\n```\n\nThe configuration file has the following format:\n\n```toml\n# apigen configuration file.\n# Strings should use single quotes\n\n# PreloadAll all relationships with gorm.Preload\nPreloadAll = false\n\n# PreloadDepth is the depth of the relationships to preload\n# e.g Patient.Visit.Doctor will be preloaded if PreloadDepth is 3\nPreloadDepth = 3\n\n# Output preload.json\nOutputJson = true\n\n[Models]\n# ModelPkg is the package name for the models to look for struct definitions\nPkgs = [\n  'github.com/abiiranathan/apigen/models',\n]\n\n# Skip is a list of models to skip. Names are case sensitive\nSkip = []\n\n# ReadOnly is a list of models that should not be generated with CRUD operations\n# Only Get methods will be generated for these models.\nReadOnly = []\n\n[Output]\n\n# OutDir is the directory to write the generated files to\nOutDir = 'gen'\n\n# ServiceName is the name of the service to generate\nServiceName = 'services'\n\n[overrides]\n# Overrides for types and fields. Forexample, here we are overriding the type\n# as would appear in typescript for Sex to be an enum.\n[overrides.types]\nSex = '\"Male\" | \"Female\"'\n\n# Here we are overriding gener to of type Sex. Sex is a go type.\n[overrides.fields]\ngender = 'Sex'\n```\n\n## Generate code\n\nIf apigen.toml is the root of your project.\n\n```bash\napigen generate\n```\n\nOr\n\n```bash\napigen --config config.toml generate\n```\n\nto specify the custom path to the configuration file.\n\n### Using the generated code\n\n```go\n\nimport(\n    // These will point to the generated code\n    \"github.com/yourname/cool-api/gen/handlers\"\n\t\"github.com/yourname/cool-api/gen/services\"\n\n\t\"gorm.io/gorm/logger\"\n)\n\nfunc main() {\n\tdb, err := services.PostgresConnection(dsn, \"Africa/kampala\", logger.Silent, os.Stdout)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\terr = db.AutoMigrate(\u0026models.User{})\n\tif err != nil {\n\t\tlog.Fatalf(\"Error performing database migrations: %v\\n\", err)\n\t}\n\n\tsvc := services.NewService(db)\n    users, err := svc.Users.GetAll()\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabiiranathan%2Fapigen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fabiiranathan%2Fapigen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabiiranathan%2Fapigen/lists"}