Skip to content

refactor(api): extract domain types to internal/types#1412

Open
Moustafa-Moustafa wants to merge 1 commit into
flatcar:mainfrom
Moustafa-Moustafa:refactor/api-internal-types
Open

refactor(api): extract domain types to internal/types#1412
Moustafa-Moustafa wants to merge 1 commit into
flatcar:mainfrom
Moustafa-Moustafa:refactor/api-internal-types

Conversation

@Moustafa-Moustafa

Copy link
Copy Markdown
Contributor

refactor(api): extract domain types to pkg/api/internal/types

Groundwork for the sub-package split described in RFC #1375 (Rollout PR 3: extract pkg/api/dbreads/). See also the design doc in #1405.

Move pkg/api data types and their methods into a new internal package pkg/api/internal/types. pkg/api keeps re-exports (type X = types.X, const/var re-exports) so callers stay unchanged. The re-exports let us minimize the size of the change and avoid updating any tests in this commit. Eventually, after splitting into the 3 packages (dbreads, admin, runtime), we will drop the re-exports in the api package and callers can reference the types package directly.

Prerequisite for extracting the read layer into pkg/api/internal/dbreads, which is itself a step towards later splitting the admin and runtime writer packages. dbreads cannot import pkg/api without an import cycle, so shared types have to live in a neutral internal package first.

This commit is purely refactoring and shouldn't change any behavior.

After the follow-up dbreads-extraction PR

flowchart TD
    handler[pkg/handler]
    omaha[pkg/omaha]
    syncer[pkg/syncer]
    api[pkg/api<br/>writers + shims]
    dbreads[pkg/api/internal/dbreads<br/>read queries]
    types[pkg/api/internal/types<br/>domain types]

    handler --> api
    omaha --> api
    syncer --> api
    api --> dbreads
    api --> types
    dbreads --> types
Loading

How to use

  • This PR is intended to be purely refactoring. To validate, we should ensure that there's no behavior change at all.

Testing done

$ cd backend
$ make code-checks
go build ./...
./tools/check_pkg_test.sh
NEBRASKA_SKIP_TESTS=1 go test ./... >/dev/null
./tools/golangci-lint run --fix
0 issues.
go mod tidy

$ make check-backend-with-container
# ... spins up postgres via docker-compose.test.yaml, runs full backend suite
# with NEBRASKA_RUN_SERVER_TESTS=1, then tears down.
ok  github.com/flatcar/nebraska/backend/pkg/api                44.746s
ok  github.com/flatcar/nebraska/backend/pkg/auth               0.006s
ok  github.com/flatcar/nebraska/backend/pkg/middleware         0.010s
ok  github.com/flatcar/nebraska/backend/pkg/omaha              6.745s
ok  github.com/flatcar/nebraska/backend/pkg/random             0.005s
ok  github.com/flatcar/nebraska/backend/pkg/sessions           0.007s
ok  github.com/flatcar/nebraska/backend/pkg/sessions/memcache  0.017s
ok  github.com/flatcar/nebraska/backend/pkg/sessions/memcache/gob  0.007s
ok  github.com/flatcar/nebraska/backend/pkg/syncer             8.253s
ok  github.com/flatcar/nebraska/backend/test/api               33.606s
ok  github.com/flatcar/nebraska/backend/test/auth/oidc         6.755s

Additionally, a manual end-to-end scenario suite was run against the local container.

  • Changelog entries added in the respective changelog/ directory (user-facing change, bug fix, security fix, update)
  • Inspected CI output for image differences: /boot and /usr size, packages, list files for any missing binaries, kernel modules, config files, kernel modules, etc.

Copilot AI review requested due to automatic review settings July 2, 2026 10:35
@Moustafa-Moustafa Moustafa-Moustafa requested a review from a team as a code owner July 2, 2026 10:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors backend/pkg/api by extracting shared domain structs/constants into the new internal package backend/pkg/api/internal/types, while keeping pkg/api as a compatibility layer via type/const re-exports so external callers don’t need to change yet.

Changes:

  • Introduces backend/pkg/api/internal/types containing API domain types (e.g., User/Team/Package/Group/Instance/Arch/etc.).
  • Replaces in-package struct definitions with type X = types.X aliases and re-exports some constants.
  • Moves architecture parsing/formatting logic into the internal types package and re-exports it from pkg/api.

Reviewed changes

Copilot reviewed 26 out of 26 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
backend/pkg/api/api.go Removes ErrInvalidArch from this file as arch concerns move to the extracted types layer.
backend/pkg/api/activity.go Re-exports Activity and ActivityQueryParams from internal/types.
backend/pkg/api/actions.go Re-exports FlatcarAction from internal/types.
backend/pkg/api/applications.go Re-exports Application from internal/types.
backend/pkg/api/arch.go Re-exports Arch, arch constants, and arch helpers from internal/types.
backend/pkg/api/channels.go Re-exports Channel from internal/types.
backend/pkg/api/groups.go Re-exports group-related domain types from internal/types.
backend/pkg/api/instances.go Re-exports instance domain types and status constants from internal/types.
backend/pkg/api/metrics.go Re-exports metric result structs from internal/types.
backend/pkg/api/packages.go Re-exports package-related types (Package/File/etc.) from internal/types.
backend/pkg/api/packages_floors.go Re-exports ChannelFloorInfo from internal/types.
backend/pkg/api/teams.go Re-exports Team from internal/types.
backend/pkg/api/users.go Re-exports User from internal/types.
backend/pkg/api/internal/types/action.go Adds FlatcarAction definition to the internal types package.
backend/pkg/api/internal/types/activity.go Adds Activity and ActivityQueryParams definitions to the internal types package.
backend/pkg/api/internal/types/application.go Adds Application definition to the internal types package.
backend/pkg/api/internal/types/arch.go Adds Arch type, constants, and parsing/formatting helpers to the internal types package.
backend/pkg/api/internal/types/channel.go Adds Channel definition to the internal types package.
backend/pkg/api/internal/types/channel_floor.go Adds ChannelFloorInfo definition to the internal types package.
backend/pkg/api/internal/types/group.go Adds Group and related group domain types to the internal types package.
backend/pkg/api/internal/types/instance.go Adds Instance and related instance domain types/status constants to the internal types package.
backend/pkg/api/internal/types/metrics.go Adds metric result structs to the internal types package.
backend/pkg/api/internal/types/package.go Adds Package, File, and ChannelPackageFloor definitions to the internal types package.
backend/pkg/api/internal/types/string_array.go Moves StringArray implementation into the internal types package.
backend/pkg/api/internal/types/team.go Adds Team definition to the internal types package.
backend/pkg/api/internal/types/user.go Adds User definition to the internal types package.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread backend/pkg/api/users.go Outdated
Comment thread backend/pkg/api/internal/types/group.go Outdated
Comment thread backend/pkg/api/arch.go Outdated
@Moustafa-Moustafa Moustafa-Moustafa force-pushed the refactor/api-internal-types branch from e4ca6ce to ba11ba2 Compare July 2, 2026 11:06
Move pkg/api data types and their methods into a new internal package
pkg/api/internal/types. pkg/api keeps re-exports (type X = types.X,
const/var re-exports) so callers stay unchanged. The re-exports let us
minimize the size of the change and avoid updating any tests in this
commit. Eventually, after splitting into the 3 packages (dbreads, admin,
runtime), we will drop the re-exports in the api package and callers
can reference the types package directly.

Prerequisite for extracting the read layer into pkg/api/internal/dbreads,
which is itself a step towards later splitting the admin and runtime
writer packages. dbreads cannot import pkg/api without an import cycle,
so shared types have to live in a neutral internal package first.

This commit is purely refactoring and shouldn't change any behavior.

Refs: flatcar#1375
Signed-off-by: Moustafa Moustafa <momousta@microsoft.com>
@Moustafa-Moustafa Moustafa-Moustafa force-pushed the refactor/api-internal-types branch from ba11ba2 to 0575f0b Compare July 2, 2026 11:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants