tercul-backend/internal/app/app.go
google-labs-jules[bot] f66936bc4b feat: Implement event-driven analytics features
This commit implements a robust, production-ready analytics system using an event-driven architecture with Redis and `asynq`.

Key changes:
- Event-Driven Architecture: Instead of synchronous database updates, analytics events (e.g., views, likes, comments) are now published to a Redis queue. This improves API response times and decouples the analytics system from the main application flow.
- Background Worker: A new worker process (`cmd/worker`) has been created to consume events from the queue and update the analytics counters in the database.
- View Counting: Implemented the missing view counting feature for both works and translations.
- New Analytics Query: Added a `popularTranslations` GraphQL query to demonstrate how to use the collected analytics data.
- Testing: Added unit tests for the new event publisher and integration tests for the analytics worker.

Known Issue:
The integration tests for the analytics worker (`AnalyticsWorkerSuite`) and the GraphQL API (`GraphQLIntegrationSuite`) are currently failing due to the lack of a Redis service in the test environment. The tests are written and are expected to pass in an environment where Redis is available on `localhost:6379`, as configured in the CI pipeline.
2025-09-07 22:30:23 +00:00

46 lines
1.6 KiB
Go

package app
import (
"tercul/internal/app/analytics"
"tercul/internal/app/auth"
"tercul/internal/app/copyright"
"tercul/internal/app/localization"
"tercul/internal/app/monetization"
"tercul/internal/app/search"
"tercul/internal/app/work"
"tercul/internal/domain"
)
// Application is a container for all the application-layer services.
// It's used for dependency injection into the presentation layer (e.g., GraphQL resolvers).
type Application struct {
AnalyticsService analytics.Service
AnalyticsPublisher analytics.EventPublisher
AuthCommands *auth.AuthCommands
AuthQueries *auth.AuthQueries
CopyrightCommands *copyright.CopyrightCommands
CopyrightQueries *copyright.CopyrightQueries
Localization localization.Service
Search search.IndexService
WorkCommands *work.WorkCommands
WorkQueries *work.WorkQueries
// Repositories - to be refactored into app services
AuthorRepo domain.AuthorRepository
UserRepo domain.UserRepository
TagRepo domain.TagRepository
CategoryRepo domain.CategoryRepository
BookRepo domain.BookRepository
PublisherRepo domain.PublisherRepository
SourceRepo domain.SourceRepository
MonetizationQueries *monetization.MonetizationQueries
MonetizationCommands *monetization.MonetizationCommands
TranslationRepo domain.TranslationRepository
CopyrightRepo domain.CopyrightRepository
MonetizationRepo domain.MonetizationRepository
CommentRepo domain.CommentRepository
LikeRepo domain.LikeRepository
BookmarkRepo domain.BookmarkRepository
CollectionRepo domain.CollectionRepository
}