{"id":36473660,"url":"https://github.com/aatuh/api-svc","last_synced_at":"2026-01-15T02:36:04.393Z","repository":{"id":331992115,"uuid":"1131024817","full_name":"aatuh/api-svc","owner":"aatuh","description":"Go domain services for SaaS APIs: billing, identity, payments, credits/tokens, and contact—built with ports/adapters, Postgres migrations, and optional HTTP handlers.","archived":false,"fork":false,"pushed_at":"2026-01-09T11:09:29.000Z","size":50,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-01-12T02:44:08.635Z","etag":null,"topics":["api","backend","billing","chi","clean-architecture","credits","ddd","email","go","golang","hexagonal-architecture","identity","migrations","payments","ports-and-adapters","postgresql","saas","stripe","tokens","webhooks"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aatuh.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":"2026-01-09T11:07:09.000Z","updated_at":"2026-01-09T11:09:14.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/aatuh/api-svc","commit_stats":null,"previous_names":["aatuh/api-svc"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/aatuh/api-svc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aatuh%2Fapi-svc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aatuh%2Fapi-svc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aatuh%2Fapi-svc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aatuh%2Fapi-svc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aatuh","download_url":"https://codeload.github.com/aatuh/api-svc/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aatuh%2Fapi-svc/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28441331,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-15T00:55:22.719Z","status":"online","status_checked_at":"2026-01-15T02:00:08.019Z","response_time":62,"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":["api","backend","billing","chi","clean-architecture","credits","ddd","email","go","golang","hexagonal-architecture","identity","migrations","payments","ports-and-adapters","postgresql","saas","stripe","tokens","webhooks"],"created_at":"2026-01-12T00:44:31.250Z","updated_at":"2026-01-15T02:36:04.387Z","avatar_url":"https://github.com/aatuh.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# api-svc\n\n## Overview\n\n`api-svc` is a collection of reusable domain services for Go HTTP APIs:\nbilling, credits/tokens, identity, payments, and contact. Each service is\npackaged as plain Go with clear ports (interfaces) for persistence and\nthird‑party providers. Some services include optional HTTP handlers\n(chi-based via `api-toolkit`) and Postgres adapters + embedded migrations.\n\nThis repository is intentionally both human- and agent-friendly:\npredictable folder layout, small packages, explicit wiring, and minimal\nhidden magic.\n\n## Design goals\n\n- Domain logic in `Service` types; adapters stay thin.\n- Depend on stable interfaces at boundaries (`github.com/aatuh/api-toolkit/ports`).\n- Make persistence/provider swaps straightforward.\n- Keep wiring explicit and test-friendly (fakes over ports).\n\n## Services (package map)\n\n- `billingsvc` — billing profiles, invoices, “outstanding” invoicing, and\n  webhook processing.\n  - HTTP: `billingsvc/http`\n  - Postgres: `billingsvc/postgres`\n  - Migrations: `billingsvc/migrations` (embedded `embed.FS`)\n- `creditsvc` — token/credit accounts + transaction ledger.\n  - Postgres: `creditsvc/postgres`\n  - Migrations: `creditsvc/migrations` (embedded `embed.FS`)\n- `identity` — external identity → local user, role management.\n  - HTTP: `identity/http` (ensure middleware + profile endpoints)\n  - Postgres: `identity/postgres` (configurable table names)\n  - Migrations: `identity.MustMigrationsFS()` (embedded `fs.FS`)\n- `paymentsvc` — token pack catalog + checkout + webhook handling.\n  - HTTP: `paymentsvc/http` (Stripe webhook handler)\n- `contact` — contact form message delivery via an email `Sender`.\n  - HTTP: `contact/http` (endpoint wrapper; you provide decode/validation)\n\n## Installation\n\n```bash\ngo get github.com/aatuh/api-svc@latest\n```\n\n## Quickstart (wiring example)\n\nThis repo is a library, not a runnable server. Your application wires\nservices with adapters (for Postgres, Stripe, email, etc.) and mounts the\nHTTP handlers onto your router.\n\n### Identity + profile endpoints\n\n```go\npackage main\n\nimport (\n  \"log\"\n  \"net/http\"\n\n  \"github.com/aatuh/api-svc/identity\"\n  identityhttp \"github.com/aatuh/api-svc/identity/http\"\n  identitypg \"github.com/aatuh/api-svc/identity/postgres\"\n  \"github.com/aatuh/api-toolkit/adapters/chi\"\n  \"github.com/aatuh/api-toolkit/adapters/clock\"\n  \"github.com/aatuh/api-toolkit/adapters/logzap\"\n  \"github.com/aatuh/api-toolkit/adapters/pgxpool\"\n  \"github.com/aatuh/api-toolkit/adapters/txpostgres\"\n  \"github.com/aatuh/api-toolkit/adapters/uuid\"\n)\n\nfunc main() {\n  pool, err := pgxpool.New(\"postgres://user:pass@localhost:5432/app?sslmode=disable\")\n  if err != nil {\n    log.Fatal(err)\n  }\n  defer pool.Close()\n\n  tx := txpostgres.New(pool)\n  logr := logzap.NewProduction()\n  clk := clock.NewSystemClock()\n  ids := uuid.NewUUIDGen()\n\n  repo := identitypg.NewRepo(pool, identitypg.DefaultConfig())\n  svc := identity.NewDefault(repo, tx, logr, clk, ids)\n\n  r := chi.New()\n  r.Mount(\"/me\", identityhttp.NewProfileHandler(identityhttp.ProfileConfig{\n    Service: svc,\n  }).Routes())\n\n  log.Fatal(http.ListenAndServe(\":8080\", r))\n}\n```\n\n## Configuration\n\nConfiguration is expressed as plain structs. Some services include helper\nloaders that read environment variables via `api-toolkit/config.Loader`.\n\n## Postgres adapters and migrations\n\nSome services include Postgres adapters and embedded SQL migrations.\nMigrations are designed to be run via `api-toolkit/migrator` (or its\n`adapters/migrate` wrapper) without requiring a migrations directory on\ndisk.\n\n```go\npackage main\n\nimport (\n  \"context\"\n  \"io/fs\"\n\n  billingmigrations \"github.com/aatuh/api-svc/billingsvc/migrations\"\n  creditsmigrations \"github.com/aatuh/api-svc/creditsvc/migrations\"\n  \"github.com/aatuh/api-svc/identity\"\n  \"github.com/aatuh/api-toolkit/adapters/migrate\"\n  \"github.com/aatuh/api-toolkit/adapters/logzap\"\n)\n\nfunc migrateDB(ctx context.Context, dsn string) error {\n  log := logzap.NewProduction()\n  m, err := migrate.New(migrate.Options{\n    DSN: dsn,\n    Log: log,\n    EmbeddedFSs: []fs.FS{\n      identity.MustMigrationsFS(),\n      billingmigrations.Migrations,\n      creditsmigrations.Migrations,\n    },\n  })\n  if err != nil {\n    return err\n  }\n  defer m.Close()\n  return m.Up(ctx, \"\")\n}\n```\n\n## HTTP handlers\n\nServices that ship HTTP handlers expose reusable routers/handlers that\nfollow a consistent flow: decode → validate → service call → encode.\nDefaults use RFC‑7807 Problem+JSON via `api-toolkit/httpx`, and most\nhandlers allow overriding the encoding/problem writers.\n\nStarting points:\n\n- Billing routes: `billingsvc/http/handler.go`\n- Contact endpoint wrapper: `contact/http/handler.go`\n- Identity middleware and profile endpoints: `identity/http/middleware.go`,\n  `identity/http/profile_handler.go`\n- Stripe webhook fan-out: `paymentsvc/http/stripe_webhook.go`\n\n## Development\n\n- Run: `go test ./...` (if you’re inside a larger repo with a parent\n  `go.work` that doesn’t include this module, use `GOWORK=off go test ./...`)\n- Format: `gofmt -w .`\n\n## License\n\nApache-2.0. See `LICENSE`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faatuh%2Fapi-svc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faatuh%2Fapi-svc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faatuh%2Fapi-svc/lists"}