Skip to content

Continue service layer extraction: AdapterConfigService, InventoryService, ProductService #787

@bokelley

Description

@bokelley

Context

PR #XXX implemented PolicyService as the first step in extracting business logic from Flask route handlers into testable service layers.

Current state:

  • ✅ PolicyService handles: currencies, measurement_providers, naming_templates, approval_mode, thresholds, policies
  • ❌ settings.py still directly handles: adapter config, inventory sync, product management, user management (still 1,120 lines)

Proposed Service Layer Architecture

Week 2: AdapterConfigService

Scope: "Ad Server" settings section

  • Ad server selection (GAM, Kevel, Triton, Mock)
  • OAuth flow and token management
  • Network codes and configuration
  • Connection testing
  • Adapter-specific config validation

Benefits:

  • Testable adapter configuration logic
  • Centralized OAuth token handling
  • Clear adapter validation rules

Week 3: InventoryService

Scope: "Inventory" settings section

  • Sync inventory from ad server
  • Ad unit and placement management
  • Inventory tree operations
  • GAM/Kevel/Triton inventory adapters

Benefits:

  • Testable inventory sync logic
  • Clear separation of inventory concerns
  • Reusable across different UI patterns

Week 4: ProductService

Scope: "Products" settings section

  • Product CRUD operations
  • Product validation
  • Implementation config management
  • Property tag associations

Benefits:

  • Testable product operations
  • Consistent product validation
  • Easier to add REST API later

Week 5: REST API Layer

Once services are extracted, add thin REST API wrappers:

  • GET /api/v1/tenants/{id}/policies
  • PUT /api/v1/tenants/{id}/policies
  • GET /api/v1/tenants/{id}/adapter-config
  • PUT /api/v1/tenants/{id}/adapter-config
  • etc.

Testing Requirements

Each service should have:

  • Unit tests for validation logic
  • Integration tests with real database
  • Clear error messages with field-specific feedback

Success Criteria

  • AdapterConfigService implemented with tests
  • InventoryService implemented with tests
  • ProductService implemented with tests
  • Route handlers refactored to use services
  • settings.py reduced to ~500 lines (from 1,120)
  • REST API endpoints added as thin wrappers
  • All existing functionality preserved

References

  • PR #XXX - PolicyService implementation (reference architecture)
  • src/services/policy_service.py - Service layer pattern
  • tests/unit/test_policy_service.py - Testing pattern

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions