A community based topic aggregation platform built on atproto
1package aggregators
2
3import (
4 "context"
5 "time"
6)
7
8// Repository defines the interface for aggregator data persistence
9// This is the AppView's indexed view of aggregators and authorizations from the firehose
10type Repository interface {
11 // Aggregator CRUD (indexed from firehose)
12 CreateAggregator(ctx context.Context, aggregator *Aggregator) error
13 GetAggregator(ctx context.Context, did string) (*Aggregator, error)
14 GetAggregatorsByDIDs(ctx context.Context, dids []string) ([]*Aggregator, error) // Bulk fetch to avoid N+1 queries
15 UpdateAggregator(ctx context.Context, aggregator *Aggregator) error
16 DeleteAggregator(ctx context.Context, did string) error
17 ListAggregators(ctx context.Context, limit, offset int) ([]*Aggregator, error)
18 IsAggregator(ctx context.Context, did string) (bool, error) // Fast check for post creation handler
19
20 // Authorization CRUD (indexed from firehose)
21 CreateAuthorization(ctx context.Context, auth *Authorization) error
22 GetAuthorization(ctx context.Context, aggregatorDID, communityDID string) (*Authorization, error)
23 GetAuthorizationByURI(ctx context.Context, recordURI string) (*Authorization, error) // For Jetstream delete operations
24 UpdateAuthorization(ctx context.Context, auth *Authorization) error
25 DeleteAuthorization(ctx context.Context, aggregatorDID, communityDID string) error
26 DeleteAuthorizationByURI(ctx context.Context, recordURI string) error // For Jetstream delete operations
27
28 // Authorization queries
29 ListAuthorizationsForAggregator(ctx context.Context, aggregatorDID string, enabledOnly bool, limit, offset int) ([]*Authorization, error)
30 ListAuthorizationsForCommunity(ctx context.Context, communityDID string, enabledOnly bool, limit, offset int) ([]*Authorization, error)
31 IsAuthorized(ctx context.Context, aggregatorDID, communityDID string) (bool, error) // Fast check: enabled=true
32
33 // Post tracking (for rate limiting and stats)
34 RecordAggregatorPost(ctx context.Context, aggregatorDID, communityDID, postURI, postCID string) error
35 CountRecentPosts(ctx context.Context, aggregatorDID, communityDID string, since time.Time) (int, error)
36 GetRecentPosts(ctx context.Context, aggregatorDID, communityDID string, since time.Time) ([]*AggregatorPost, error)
37}
38
39// Service defines the interface for aggregator business logic
40// Coordinates between Repository, communities service, and PDS for write-forward
41type Service interface {
42 // Aggregator queries (read from AppView)
43 GetAggregator(ctx context.Context, did string) (*Aggregator, error)
44 GetAggregators(ctx context.Context, dids []string) ([]*Aggregator, error)
45 ListAggregators(ctx context.Context, limit, offset int) ([]*Aggregator, error)
46
47 // Authorization queries (read from AppView)
48 GetAuthorizationsForAggregator(ctx context.Context, req GetAuthorizationsRequest) ([]*Authorization, error)
49 ListAggregatorsForCommunity(ctx context.Context, req ListForCommunityRequest) ([]*Authorization, error)
50
51 // Authorization management (write-forward: Service -> PDS -> Firehose -> Consumer -> Repository)
52 EnableAggregator(ctx context.Context, req EnableAggregatorRequest) (*Authorization, error)
53 DisableAggregator(ctx context.Context, req DisableAggregatorRequest) (*Authorization, error)
54 UpdateAggregatorConfig(ctx context.Context, req UpdateConfigRequest) (*Authorization, error)
55
56 // Validation and authorization checks (used by post creation handler)
57 ValidateAggregatorPost(ctx context.Context, aggregatorDID, communityDID string) error // Checks authorization + rate limits
58 IsAggregator(ctx context.Context, did string) (bool, error) // Check if DID is a registered aggregator
59
60 // Post tracking (called after successful post creation)
61 RecordAggregatorPost(ctx context.Context, aggregatorDID, communityDID, postURI, postCID string) error
62}