Files
flvx/go-backend/internal/http/handler/AGENTS.md
T
Antigravity 66be07750f refactor(backend): migrate to modular repository pattern with separated concerns
- Extract database layer into model and repo packages
- Split repository into focused modules (control, federation, flow, groups, mutations)
- Remove monolithic db.go and sqlite/repository.go
- Update handlers to use new repository structure
- Migrate contract tests to new patterns
- Add migration plan documentation
2026-02-17 04:47:11 +00:00

1.8 KiB

BACKEND HTTP HANDLER KNOWLEDGE BASE

Generated: Sun Feb 15 2026

OVERVIEW

HTTP request handlers for FLVX Admin API. Core business logic layer. Stack: Go 1.23, net/http, GORM via Repository pattern.

STRUCTURE

handler/
├── handler.go        # Main Handler struct, login/captcha, job scheduling
├── control_plane.go  # Node control plane API (add/delete/list)
├── federation.go     # Federation/cluster sync API
├── flow_policy.go    # Traffic policy API
├── jobs.go           # Background job management (sync, cleanup)
├── mutations.go      # CRUD for users, tunnels, forwards (largest: 100k+ LOC)
└── upgrade.go        # System upgrade API

WHERE TO LOOK

Task Location Notes
User/Tunnel CRUD mutations.go Largest file; all create/update/delete ops
Login/Captcha handler.go Login flow, captcha verification
Federation Sync federation.go Panel-to-panel sync
Traffic Policies flow_policy.go Flow limiting, quota management
Background Jobs jobs.go Scheduled sync/cleanup tasks

CONVENTIONS

  • Inherits from parent: GORM via Repository pattern, JWT in Authorization header.
  • Large files expected (mutations.go 3716 LOC - central mutation hub).
  • Uses repo.Repository for DB access via h.repo.XXX() methods.
  • Handlers never call repo.DB() directly — all queries go through Repository methods.
  • Domain-driven file split: one file per functional area (federation, jobs, etc.).

ANTI-PATTERNS

  • Do NOT let handlers call repo.DB() directly — add a Repository method instead.
  • Do NOT change handler signatures without updating router.go.

COMMANDS

cd go-backend
go test ./internal/http/handler/...