refactor(server): decouple services and improve architecture
All checks were successful
Build Backend / build (push) Successful in 4m55s
Build Backend / build-docker (push) Successful in 10m34s

- Introduce interfaces for all major services (JWT, PostAI, Comment, Message, Notification, QRCodeLogin, Upload, Vote, etc.) to support dependency inversion.
- Move query parameters from `internal/dto` to a new `internal/query` package to separate request payloads from data transfer objects.
- Refactor `internal/router` to use embedded `RouterDeps` for cleaner dependency management.
- Decouple handlers from repositories by injecting services instead of direct repository access, ensuring proper layering.
- Improve database initialization by moving it from `internal/model` to `internal/database`.
- Optimize message decryption by implementing a more efficient `BatchDecrypt` method in `MessageEncryptor` using a worker pool.
- Enhance error handling and security by implementing fail-fast checks for encryption key length during startup.
- Clean up unused code, including the `avatar` package and several unused DTOs.
This commit is contained in:
2026-06-15 03:41:59 +08:00
parent 9951043034
commit d9aa4b46c3
78 changed files with 2156 additions and 1640 deletions

View File

@@ -1,10 +1,9 @@
package wire
package wire
import (
"with_you/internal/config"
"with_you/internal/handler"
"with_you/internal/pkg/ws"
"with_you/internal/repository"
"with_you/internal/service"
"github.com/google/wire"
@@ -66,7 +65,7 @@ func ProvideUserHandler(
func ProvideMessageHandler(
chatService service.ChatService,
messageService *service.MessageService,
messageService service.MessageService,
userService service.UserService,
groupService service.GroupService,
publisher ws.MessagePublisher,
@@ -102,11 +101,11 @@ func ProvideWSHandler(
publisher ws.MessagePublisher,
chatService service.ChatService,
groupService service.GroupService,
jwtService *service.JWTService,
jwtService service.JWTService,
callService service.CallService,
userRepo repository.UserRepository,
userService service.UserService,
) *handler.WSHandler {
return handler.NewWSHandler(publisher, chatService, groupService, jwtService, callService, userRepo)
return handler.NewWSHandler(publisher, chatService, groupService, jwtService, callService, userService)
}
// ProvideLiveKitHandler 提供 LiveKit 处理器
@@ -122,9 +121,9 @@ func ProvideLiveKitHandler(
// ProvideAdminVerificationHandler 提供管理端身份认证处理器
func ProvideAdminVerificationHandler(
adminVerificationService service.AdminVerificationService,
userRepo repository.UserRepository,
userService service.UserService,
) *handler.AdminVerificationHandler {
return handler.NewAdminVerificationHandler(adminVerificationService, userRepo)
return handler.NewAdminVerificationHandler(adminVerificationService, userService)
}
func ProvideSetupHandler(