Engineering note · Flexi-Ride
Writing the contract first
- Project
- Flexi-Ride — Internal project, Zone01 Kisumu
- Issue
- #35 CORE-001 and #38 CORE-004: Define Auth and User gRPC contracts and OpenAPI specs
- My role
- Author of PRs #99, #101 and #102
- Stack
- gRPC · Protocol Buffers · OpenAPI 3.0
- Status
- Merged 4, 10 and 13 Aug 2026
The problem
Auth and User are the first services most other Flexi-Ride services depend on. The team wanted their interfaces agreed before anyone wrote the code. Each issue asked for two files: a .proto file for the internal gRPC interface, and an OpenAPI 3.0 spec for the external REST endpoints. The issue notes said it plainly: the proto file is the contract, and implementation follows after approval.
The existing auth.proto was an early draft with Login and a ValidateToken that returned a username. The user.proto file was empty.
What I did
For Auth (PR #99), I rewrote auth.proto around the three RPCs the issue named: ValidateToken, RefreshToken and GetClaims. Every RPC has a comment listing the error codes it can return.
// RefreshToken generates a new access token using a valid refresh token.
// Possible Error Codes:
// - UNAUTHENTICATED: The refresh token is invalid or expired.
// - NOT_FOUND: The associated user session does not exist.
// - INVALID_ARGUMENT: The request is malformed.
// - INTERNAL: An unexpected server error occurred.
rpc RefreshToken(RefreshTokenRequest) returns (RefreshTokenResponse);
I then wrote Docs/specs/auth-api.yaml with matching REST paths under /api/v1/auth:
POST /validate,POST /refreshandPOST /claims, each with request and response schemas.- One shared
ErrorResponseschema with anerror_codefield. - Reusable responses that map HTTP
400,401,404and500toINVALID_ARGUMENT,UNAUTHENTICATED,NOT_FOUNDandINTERNAL.
So the same failure has the same name over gRPC and over REST.
For User (PR #101), I defined GetUser, UpdateProfile and GetPreferences, with matching REST endpoints. The issue also asked for PUT /api/v1/users/{id}/preferences and GET /api/v1/users/search, which my first PR did not cover. PR #102 added both, as UpdatePreferences and SearchUsers in the proto and as new paths in the spec. Search takes a query plus limit and offset for paging.
How I checked it
For the User contracts, I checked the proto with protoc -I=services/user/proto services/user/proto/user.proto -o /dev/null and the spec with swagger-cli validate. For Auth, the PR gave reviewers a protoc command to run, and a reviewer approved it after checking it.
The contract was then used. For CORE-003, a teammate implemented ValidateToken, RefreshToken and GetClaims in the Auth service, and added a roles claim to ValidateTokenResponse along the way.
What I learned
A contract is only as good as the code it generates in the project's real language. My protos set go_package, and in the Auth rewrite I removed the old java_package and java_multiple_files options. Flexi-Ride is a Java project. About a month later, a teammate added java_package and java_multiple_files to both files. protoc -o /dev/null only checks syntax. Next time I would run the actual Java code generation as part of checking a contract, so the generated package names are reviewed along with the messages.