5.8 KiB
5.8 KiB
Planner Overview
Purpose
Explain how the planner module manages keywords, clusters, and content ideas, including tenancy, validation, and API behaviors.
Code Locations (exact paths)
- Models:
backend/igny8_core/business/planning/models.py - Serializers:
backend/igny8_core/modules/planner/serializers.py - Views:
backend/igny8_core/modules/planner/views.py - URLs:
backend/igny8_core/modules/planner/urls.py - Services:
backend/igny8_core/business/planning/services/clustering_service.py,ideas_service.py
High-Level Responsibilities
- Store site/sector-scoped keywords, clusters, and content ideas linked to global seed keywords.
- Provide CRUD and bulk operations for keywords/clusters/ideas with search, filter, and ordering.
- Validate industry/sector alignment between seed keywords and site/sector.
- Feed downstream writer/automation stages with structured ideas and clusters.
Detailed Behavior
- Models (site/sector scoped via
SiteSectorBaseModeland soft-delete):Keywords: references globalSeedKeyword; optional volume/difficulty overrides; optional cluster; statusnew/mapped; disabled flag; validation ensures seed keyword industry/sector match the site/sector.Clusters: topic groups with counts, volume, mapped_pages, statusnew/mapped; unique per site/sector by name.ContentIdeas: ideas tied to clusters and optional keyword objects; statusnew/queued/completed; content_type/structure and estimated_word_count; disabled flag.
- Serializers:
KeywordSerializerenforcesseed_keyword_idon create; exposes seed keyword-derived fields (keyword/volume/difficulty/intent) read-only; optional overrides; includes site_id/sector_id write-only; provides cluster/sector names via getters; optionalattribute_valueswhenUSE_SITE_BUILDER_REFACTORflag is enabled.ClusterSerializerexposes site/sector IDs, sector name, read-only counts/volume/mapped_pages.ContentIdeasSerializerexposes cluster/sector names, content type/structure, keyword/target fields, site/sector write-only.
- Views (
KeywordViewSet,ClusterViewSet,ContentIdeasViewSet):- Inherit
SiteSectorModelViewSetfor tenant/site/sector filtering and unified responses. - Permissions:
IsAuthenticatedAndActive+ viewer-or-above (search/list CRUD). - Pagination:
CustomPageNumberPagination; throttle scopeplanner. - Filters/Search/Ordering: keywords searchable by seed_keyword.keyword; filter by status, cluster_id, seed intent; ordering by created_at, volume, difficulty; custom range filters for difficulty/volume; clusters filter by status; ideas filter by status/cluster.
- Creation requires explicit
site_idandsector_id; viewsets validate site/sector existence and alignment; setaccount/site/sectorexplicitly on save. - Bulk endpoints:
- Keywords:
bulk_delete, two definitions ofbulk_update(status update) present;bulk_add_from_seedto create Keywords from SeedKeywords with site/sector validation. - Clusters: bulk update endpoints in view (not shown above) adjust status.
- Ideas: creation and status updates follow standard CRUD; not shown as bulk endpoints in code snippet.
- Keywords:
- Error handling: viewsets wrap errors into unified responses; return 400/404/500 as appropriate.
- Inherit
- Services:
ClusteringServiceandIdeasService(not detailed here) provide additional business logic for clustering/idea generation when invoked by automation or endpoints.
Data Structures / Models Involved (no code)
Keywords,Clusters,ContentIdeas; globalSeedKeyword.- Tenancy entities:
Account,Site,Sector.
Execution Flow
- Requests → DRF auth →
SiteSectorModelViewSetfilters by account/site/sector → serializers validate seed/site/sector alignment → models persisted → responses returned via unified helpers; bulk actions operate on filtered querysets.
Cross-Module Interactions
- Automation stages 1–3 consume planner data (keywords → clusters → ideas → tasks).
- Writer tasks reference clusters/ideas produced here.
- Billing credits may be checked upstream for AI clustering/idea generation (via services invoked in automation or planner actions).
State Transitions
- Keywords:
new→mapped; Clusters:new→mapped; ContentIdeas:new→queued→completed. - Disabled flag can exclude records from processes.
Error Handling
- Validation enforces seed/site/sector industry alignment; missing site/sector on create raises validation errors.
- Bulk operations return 400 on missing IDs/status; general errors return unified 500 responses.
Tenancy Rules
- All planner models inherit
SiteSectorBaseModel; queries are filtered by account/site/sector; admin/developer/system roles can bypass filtering via base viewset logic. - Create requires explicit site and sector; viewsets fetch and set account from site/user/middleware.
Billing Rules
- None directly in the planner endpoints; credit costs for clustering/idea generation are enforced where those services are called (automation or planner service usage).
Background Tasks / Schedulers
- Planner endpoints run synchronously; automation may batch planner data into AI tasks via Celery (documented in automation).
Key Design Considerations
- Strict site/sector validation prevents cross-tenant or cross-site leaks.
- Seed keyword linkage centralizes keyword metadata; overrides allow per-site tuning.
- Pagination/filtering/search are optimized for large keyword sets.
How Developers Should Work With This Module
- Use provided viewsets and serializers; ensure site_id/sector_id are supplied on create.
- When adding fields, extend serializers with read-only/write-only behavior consistent with current patterns.
- For new bulk operations, follow existing patterns: validate IDs, operate on filtered queryset, return unified responses.