Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Repository files navigation

schema-first

DDD todo-list API in Go. Schema-first with oapi-codegen + kin-openapi, GORM + SQLite, JWT auth.

Structure

api/
  openapi.yaml            # root spec — paths, security, inline schemas (Author, Board, TokenResponse)
domain/
  author/                 # Author aggregate, events, repository interface
  board/                  # Board aggregate, Note entity, events, repository interface
eventbus/                 # In-memory event bus
application/              # AuthorService, BoardService
infrastructure/
  persistence/            # GORM + SQLite repositories
middleware/
  jwt.go                  # JWT auth (skips /auth/*)
  validation.go           # kin-openapi request validation
handler/                  # StrictServerInterface implementation
gen/                      # Generated — do not edit by hand
  models.gen.go
  server.gen.go
cmd/main.go               # Entrypoint
generate.go               # go:generate directives (run from project root)
static/index.html         # Frontend (HTML + Tailwind + vanilla JS)

Generate

After editing anything under api/:

go generate .

Run

go run ./cmd/main.go

Environment variables (all optional):

Variable Default
ADDR :8080
DB_DSN todo.db
JWT_SECRET change-me-in-production

Frontend available at http://localhost:8080.

Request validation

Handled automatically by middleware/validation.go using kin-openapi before requests reach handlers. Validation errors return HTTP 400:

{
  "errors": [
    { "field": "content", "validator": "minLength", "message": "minimum string length is 10" }
  ]
}

Schema rules

Schemas that need to be named Go types must be defined inline in openapi.yaml (not as external $ref), because oapi-codegen only generates a named struct for schemas directly referenced in paths. Leaf schemas with no cross-references can live in api/schemas/.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages