droboticflow/internal/api/routes_system.go
d-robotics 994fa59982 ♻️ Split API route registration into per-domain routes_*.go files
routes.go keeps only the global middleware chain, the shared business-role
sets, and one mount call per domain: system, dashboard, acceptance, human
loop, annotation, projects, organization, workflows, runs, delivery, data
platform, and object sync. Role-only groups become withRoles/With on the
routes they guard, so each route's permission sits next to it instead of in
a role-shaped group far from the rest of its domain.

No route, handler, or access change: testdata/routes.golden (generated from
the pre-split router) is byte-identical, the Go known-failure gate passes,
and a live API smoke against a throwaway DB matched the access matrix for
every parameter-free GET route across six identities.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 18:50:40 +08:00

52 lines
2.4 KiB
Go

package api
import (
"github.com/go-chi/chi/v5"
"droboticflow/internal/domain"
)
// mountSystemRoutes registers health probes, authentication, super-admin
// tenant management, worker API proxies, platform settings and plugin
// configuration.
func (server *server) mountSystemRoutes(router chi.Router) {
router.Get("/api/health", server.handleHealth)
router.Get("/api/ready", server.handleReady)
router.Get("/api/auth/bootstrap-status", server.handleAuthBootstrapStatus)
router.Post("/api/auth/bootstrap-super-admin", server.handleAuthBootstrapSuperAdmin)
router.Post("/api/auth/login", server.handleAuthLogin)
router.Post("/api/auth/logout", server.handleAuthLogout)
router.Get("/api/auth/me", server.handleAuthMe)
router.Post("/api/client/movi-stats", server.handleClientMoviStats)
router.Route("/api/admin", func(router chi.Router) {
router.Use(server.requireSuperAdmin)
router.Get("/organizations", server.handleAdminOrganizationsList)
router.Post("/organizations", server.handleAdminOrganizationsCreate)
router.Put("/organizations/{id}", server.handleAdminOrganizationsUpdate)
router.Delete("/organizations/{id}", server.handleAdminOrganizationsDelete)
router.Get("/organizations/{id}/users", server.handleAdminOrganizationUsersList)
router.Post("/organizations/{id}/users", server.handleAdminOrganizationUsersCreate)
router.Put("/users/{id}", server.handleAdminUserUpdate)
router.Delete("/users/{id}", server.handleAdminUserDelete)
router.Post("/users/{id}/reset-password", server.handleAdminUserResetPassword)
})
router.Get("/worker-api/health", server.handleWorkerAPIHealth)
router.Get("/worker-api/ready", server.handleWorkerAPIReady)
worker := router.With(server.requireWorkerAPIRole(domain.UserRoleAdmin))
worker.Get("/worker-api/stats", server.handleWorkerAPIStats)
worker.Get("/worker-api/metrics", server.handleWorkerAPIMetrics)
worker.Get("/worker-api/capacity", server.handleWorkerAPICapacity)
worker.Post("/worker-api/process-once", server.handleWorkerAPIProcessOnce)
router.Get("/api/public/settings", server.handlePublicSettingsGet)
admin := server.withRoles(router, rolesAdmin...)
admin.Get("/api/settings", server.handleSettingsGet)
admin.Put("/api/settings", server.handleSettingsUpdate)
router.Get("/api/plugins", server.handlePluginsList)
router.Get("/api/organizations/{id}/plugins/{pluginId}", server.handleOrganizationPluginGet)
admin.Put("/api/organizations/{id}/plugins/{pluginId}", server.handleOrganizationPluginUpdate)
}