Service Sequences as Code — generate service code from Go comment DSL.
Service logic is a series of decisions: which model to query, what to guard against, when to reject, what to return. These decisions belong to the person who understands the business — but they get buried in boilerplate, scattered across layers, and lost in rewrites.
SSaC preserves these decisions as a declarative spec. You declare what happens and in what order. The tool generates the implementation.
specs/service/*.go → ssac validate → ssac gen → artifacts/service/*.go
Core Idea
Every service function is a sequence of steps. Each step follows a binary contract: succeed → next line, fail → return. This is not an abstraction we invented — it’s how service logic already works. SSaC makes it explicit.
10 fixed sequence types cover all service-layer operations that follow this contract. If something doesn’t fit, delegate it to call. The set is closed by design.
No LLM, no inference — pure symbolic codegen from templates. The spec is the source of truth.
Example
// @sequence get
// @model Project.FindByID
// @param ProjectID request
// @result project Project
// @sequence guard nil project
// @message "project not found"
// @sequence post
// @model Session.Create
// @param ProjectID request
// @param Command request
// @result session Session
// @sequence response json
// @var session
func CreateSession(w http.ResponseWriter, r *http.Request) {}
This 10-line declaration generates the following code:
func CreateSession(w http.ResponseWriter, r *http.Request) {
projectID := r.FormValue("ProjectID")
command := r.FormValue("Command")
project, err := projectModel.FindByID(projectID)
if err != nil {
http.Error(w, "Project lookup failed", http.StatusInternalServerError)
return
}
if project == nil {
http.Error(w, "project not found", http.StatusNotFound)
return
}
session, err := sessionModel.Create(projectID, command)
if err != nil {
http.Error(w, "Session creation failed", http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(map[string]interface{}{
"session": session,
})
}
Sequence Types (10)
| Type | Role |
|---|---|
authorize | Permission check (OPA, etc.) |
get | Resource lookup |
guard nil | Exit if null |
guard exists | Exit if exists |
post | Resource creation |
put | Resource update |
delete | Resource deletion |
password | Password comparison |
call | External call (@component / @func) |
response | Return response (json) |
Codegen Features
/api/reservations:
get:
operationId: ListReservations
x-pagination:
style: offset
defaultLimit: 20
maxLimit: 100
x-sort:
allowed: [start_at, created_at]
default: start_at
direction: desc
x-filter:
allowed: [status, room_id]
x-include:
allowed: [room, user]
License
MIT — GitHub