Files
food-ai/backend/cmd/server/app.go
dbastrikin 39193ec13c feat: async dish recognition (Kafka/Watermill/SSE) + remove Wire + consolidate migrations
Async recognition pipeline:
- POST /ai/recognize-dish → 202 {job_id, queue_position, estimated_seconds}
- GET /ai/jobs/{id}/stream — SSE stream: queued → processing → done/failed
- Kafka topics: ai.recognize.paid (3 partitions) + ai.recognize.free (1 partition)
- 5-worker WorkerPool with priority loop (paid consumers first)
- SSEBroker via PostgreSQL LISTEN/NOTIFY
- Kafka adapter migrated from franz-go to Watermill (watermill-kafka/v2)
- Docker Compose: added Kafka + Zookeeper + kafka-init service
- Flutter: recognition_service.dart uses SSE; home_screen shows live job status

Remove google/wire (archived):
- Deleted wire.go (wireinject spec) and wire_gen.go
- Added cmd/server/init.go — plain Go manual DI, same initApp() logic
- Removed github.com/google/wire from go.mod

Consolidate migrations:
- Merged 001_initial_schema + 002_seed_data + 003_recognition_jobs into single 001_initial_schema.sql
- Deleted 002_seed_data.sql and 003_recognition_jobs.sql

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-18 16:32:06 +02:00

28 lines
825 B
Go

package main
import (
"context"
"net/http"
"github.com/food-ai/backend/internal/domain/recognition"
)
// App bundles the HTTP handler with background services that need lifecycle management.
type App struct {
handler http.Handler
workerPool *recognition.WorkerPool
sseBroker *recognition.SSEBroker
}
// ServeHTTP implements http.Handler.
func (application *App) ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) {
application.handler.ServeHTTP(responseWriter, request)
}
// Start launches the SSE broker's LISTEN loop and the worker pool goroutines.
// Call this once before the HTTP server begins accepting connections.
func (application *App) Start(applicationContext context.Context) {
application.sseBroker.Start(applicationContext)
application.workerPool.Start(applicationContext)
}