# taffapereira/shopee-affiliate-ops architecture

> Architecture diagram of the GitHub repository taffapereira/shopee-affiliate-ops, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/taffapereira/shopee-affiliate-ops
- Repository: https://github.com/taffapereira/shopee-affiliate-ops

## Overview

Shopee Affiliate Ops automates affiliate product operations: Shopee collection and offer normalization, product ranking, channel-specific content and tracked-link generation, then video creation and multi-channel publishing, with analytics and conversion attribution. The API exposes product, content, link, and analytics workflows; persistent product, content, link, and metric records support them. The README documents the daily pipeline and optional N8N orchestration. Some branches are included from documented capabilities and the source tree; unsampled implementations and their internal call relationships are not asserted.

Main entry points: [`src/api/routes/products.py`](https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/api/routes/products.py) (Product endpoints), [`src/api/main.py`](https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/api/main.py) (FastAPI application), [`src/api/routes/content.py`](https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/api/routes/content.py) (Content endpoints), [`src/content/generator.py`](https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/content/generator.py) (Content generation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API workflows"]
  node_api_app["FastAPI application<br/>[main.py]"]
  node_product_routes["Product endpoints<br/>[products.py]"]
  node_content_routes["Content endpoints<br/>[content.py]"]
  node_link_routes["Link endpoints<br/>[links.py]"]
  node_analytics_routes["Analytics endpoints<br/>[analytics.py]"]
end

subgraph group_products["Product discovery"]
  node_collector["Offer collection<br/>[shopee_api.py]"]
  node_offer_parser["Offer normalization<br/>[offer_parser.py]"]
  node_ranking["Product ranking<br/>[scorer.py]"]
  node_selector["Product selection<br/>[selector.py]"]
  node_deepseek["DeepSeek ranking client<br/>[deepseek_client.py]"]
end

subgraph group_marketing["Content and links"]
  node_content_generator["Content generation<br/>[generator.py]"]
  node_personas["Audience personas<br/>[personas.py]"]
  node_tiktok_template["TikTok templates<br/>[tiktok.py]"]
  node_grupo_template["Telegram templates<br/>[grupo.py]"]
  node_hashtags["Hashtag utilities<br/>[hashtags.py]"]
  node_gpt["GPT copywriting client<br/>[gpt_client.py]"]
  node_link_builder["Tracked link creation<br/>[shortener.py]"]
  node_subids["SubId construction<br/>[subid_builder.py]"]
  node_llm_router["LLM routing<br/>[router.py]"]
end

subgraph group_delivery["Media and publishing"]
  node_video["Video generation<br/>[veo_generator.py]"]
  node_tts["Voice generation<br/>[nanobana_tts.py]"]
  node_video_storage["Video storage<br/>[storage.py]"]
  node_publishers["Channel publishing<br/>[buffer_client.py]"]
  node_telegram_publisher["Telegram publishing<br/>[telegram_bot.py]"]
  node_scheduler["Publishing schedule<br/>[scheduler.py]"]
end

subgraph group_insights["Analytics and state"]
  node_analytics_fetcher["Shopee report fetch<br/>[report_fetcher.py]"]
  node_attribution["Conversion attribution<br/>[attribution.py]"]
  node_metrics["Performance metrics<br/>[metrics.py]"]
  node_database[("Operational database<br/>[connection.py]")]
  node_models["Product and activity models<br/>[models.py]"]
  node_repository["Data repository<br/>[repository.py]"]
  node_logger["Structured logging<br/>[logger.py]"]
end

node_operator(("Affiliate operator"))
node_shopee{{"Shopee Affiliate API"}}

node_operator -->|"uses"| node_api_app
node_api_app -->|"routes to"| node_product_routes
node_api_app -->|"routes to"| node_content_routes
node_api_app -->|"routes to"| node_link_routes
node_api_app -->|"routes to"| node_analytics_routes
node_api_app -->|"initializes"| node_database
node_product_routes -->|"requests offers"| node_collector
node_collector -->|"fetches offers"| node_shopee
node_product_routes -->|"normalizes offers"| node_offer_parser
node_product_routes -->|"selects products"| node_selector
node_product_routes -->|"scores products"| node_ranking
node_selector -->|"uses scorer"| node_ranking
node_product_routes -->|"stores products"| node_repository
node_content_routes -->|"generates content"| node_content_generator
node_content_routes -->|"requests LLM"| node_llm_router
node_content_routes -->|"reads and saves"| node_repository
node_content_generator -->|"loads persona"| node_personas
node_content_generator -->|"renders TikTok"| node_tiktok_template
node_content_generator -->|"renders Telegram"| node_grupo_template
node_grupo_template -->|"uses hashtags"| node_hashtags
node_llm_router -->|"dispatches copy"| node_gpt
node_llm_router -->|"dispatches ranking"| node_deepseek
node_link_routes -->|"creates links"| node_link_builder
node_link_builder -->|"builds tracking IDs"| node_subids
node_link_builder -->|"requests affiliate URL"| node_shopee
node_link_routes -->|"stores link records"| node_repository
node_analytics_routes -->|"calculates metrics"| node_metrics
node_analytics_routes -->|"reads analytics"| node_repository
node_repository -->|"queries and writes"| node_database
node_database -->|"creates tables"| node_models
node_analytics_fetcher -->|"fetches reports"| node_shopee
node_analytics_fetcher -->|"uses API client"| node_collector
node_analytics_routes -.->|"supports attribution"| node_attribution
node_metrics -.->|"informs attribution"| node_attribution
node_content_generator -.->|"feeds video pipeline"| node_video
node_video -.->|"adds narration"| node_tts
node_video -.->|"stores media"| node_video_storage
node_scheduler -.->|"schedules posts"| node_telegram_publisher
node_scheduler -.->|"schedules posts"| node_publishers
node_publishers -.->|"publishes channels"| node_operator
node_telegram_publisher -.->|"publishes Telegram"| node_operator
node_product_routes -->|"logs activity"| node_logger
node_content_routes -->|"logs activity"| node_logger

click node_api_app "https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/api/main.py"
click node_product_routes "https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/api/routes/products.py"
click node_content_routes "https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/api/routes/content.py"
click node_link_routes "https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/api/routes/links.py"
click node_analytics_routes "https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/api/routes/analytics.py"
click node_collector "https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/collectors/shopee_api.py"
click node_offer_parser "https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/collectors/offer_parser.py"
click node_ranking "https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/ranking/scorer.py"
click node_selector "https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/ranking/selector.py"
click node_deepseek "https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/llm/deepseek_client.py"
click node_content_generator "https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/content/generator.py"
click node_personas "https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/content/personas.py"
click node_tiktok_template "https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/content/templates/tiktok.py"
click node_grupo_template "https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/content/templates/grupo.py"
click node_hashtags "https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/utils/hashtags.py"
click node_gpt "https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/llm/gpt_client.py"
click node_link_builder "https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/links/shortener.py"
click node_subids "https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/links/subid_builder.py"
click node_video "https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/video/veo_generator.py"
click node_tts "https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/video/nanobana_tts.py"
click node_video_storage "https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/video/storage.py"
click node_publishers "https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/publishers/buffer_client.py"
click node_telegram_publisher "https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/publishers/telegram_bot.py"
click node_scheduler "https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/scheduling/scheduler.py"
click node_analytics_fetcher "https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/analytics/report_fetcher.py"
click node_attribution "https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/analytics/attribution.py"
click node_metrics "https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/analytics/metrics.py"
click node_database "https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/database/connection.py"
click node_models "https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/database/models.py"
click node_repository "https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/database/repository.py"
click node_logger "https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/utils/logger.py"
click node_llm_router "https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/llm/router.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_api_app,node_product_routes,node_content_routes,node_link_routes,node_analytics_routes toneBlue
class node_collector,node_offer_parser,node_ranking,node_selector,node_deepseek toneAmber
class node_content_generator,node_personas,node_tiktok_template,node_grupo_template,node_hashtags,node_gpt,node_link_builder,node_subids,node_llm_router,node_shopee toneMint
class node_video,node_tts,node_video_storage,node_publishers,node_telegram_publisher,node_scheduler toneRose
class node_analytics_fetcher,node_attribution,node_metrics,node_database,node_models,node_repository,node_logger,node_operator toneIndigo
```

## Components

### API workflows

- [FastAPI application](https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/api/main.py): `src/api/main.py`
- [Product endpoints](https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/api/routes/products.py): `src/api/routes/products.py`
- [Content endpoints](https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/api/routes/content.py): `src/api/routes/content.py`
- [Link endpoints](https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/api/routes/links.py): `src/api/routes/links.py`
- [Analytics endpoints](https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/api/routes/analytics.py): `src/api/routes/analytics.py`

### Product discovery

- [Offer collection](https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/collectors/shopee_api.py): `src/collectors/shopee_api.py`
- [Offer normalization](https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/collectors/offer_parser.py): `src/collectors/offer_parser.py`
- [Product ranking](https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/ranking/scorer.py): `src/ranking/scorer.py`
- [Product selection](https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/ranking/selector.py): `src/ranking/selector.py`
- [DeepSeek ranking client](https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/llm/deepseek_client.py): `src/llm/deepseek_client.py`

### Content and links

- [Content generation](https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/content/generator.py): `src/content/generator.py`
- [Audience personas](https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/content/personas.py): `src/content/personas.py`
- [TikTok templates](https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/content/templates/tiktok.py): `src/content/templates/tiktok.py`
- [Telegram templates](https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/content/templates/grupo.py): `src/content/templates/grupo.py`
- [Hashtag utilities](https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/utils/hashtags.py): `src/utils/hashtags.py`
- [GPT copywriting client](https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/llm/gpt_client.py): `src/llm/gpt_client.py`
- [Tracked link creation](https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/links/shortener.py): `src/links/shortener.py`
- [SubId construction](https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/links/subid_builder.py): `src/links/subid_builder.py`
- [LLM routing](https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/llm/router.py): `src/llm/router.py`

### Media and publishing

- [Video generation](https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/video/veo_generator.py): `src/video/veo_generator.py`
- [Voice generation](https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/video/nanobana_tts.py): `src/video/nanobana_tts.py`
- [Video storage](https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/video/storage.py): `src/video/storage.py`
- [Channel publishing](https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/publishers/buffer_client.py): `src/publishers/buffer_client.py`
- [Telegram publishing](https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/publishers/telegram_bot.py): `src/publishers/telegram_bot.py`
- [Publishing schedule](https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/scheduling/scheduler.py): `src/scheduling/scheduler.py`

### Analytics and state

- [Shopee report fetch](https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/analytics/report_fetcher.py): `src/analytics/report_fetcher.py`
- [Conversion attribution](https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/analytics/attribution.py): `src/analytics/attribution.py`
- [Performance metrics](https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/analytics/metrics.py): `src/analytics/metrics.py`
- [Operational database](https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/database/connection.py): `src/database/connection.py`
- [Product and activity models](https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/database/models.py): `src/database/models.py`
- [Data repository](https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/database/repository.py): `src/database/repository.py`
- [Structured logging](https://github.com/taffapereira/shopee-affiliate-ops/blob/main/src/utils/logger.py): `src/utils/logger.py`

### Other components

- **Affiliate operator**
- **Shopee Affiliate API**

## Connections

- Affiliate operator → FastAPI application: uses (evidence: `README.md`)
- FastAPI application → Product endpoints: routes to (evidence: `src/api/main.py`)
- FastAPI application → Content endpoints: routes to (evidence: `src/api/main.py`)
- FastAPI application → Link endpoints: routes to (evidence: `src/api/main.py`)
- FastAPI application → Analytics endpoints: routes to (evidence: `src/api/main.py`)
- FastAPI application → Operational database: initializes (evidence: `src/api/main.py`)
- Product endpoints → Offer collection: requests offers (evidence: `src/api/routes/products.py`)
- Offer collection → Shopee Affiliate API: fetches offers (evidence: `src/collectors/shopee_api.py`)
- Product endpoints → Offer normalization: normalizes offers (evidence: `src/api/routes/products.py`)
- Product endpoints → Product selection: selects products (evidence: `src/api/routes/products.py`)
- Product endpoints → Product ranking: scores products (evidence: `src/api/routes/products.py`)
- Product selection → Product ranking: uses scorer (evidence: `src/ranking/selector.py`)
- Product endpoints → Data repository: stores products (evidence: `src/api/routes/products.py`)
- Content endpoints → Content generation: generates content (evidence: `src/api/routes/content.py`)
- Content endpoints → LLM routing: requests LLM (evidence: `src/api/routes/content.py`)
- Content endpoints → Data repository: reads and saves (evidence: `src/api/routes/content.py`)
- Content generation → Audience personas: loads persona (evidence: `src/content/generator.py`)
- Content generation → TikTok templates: renders TikTok (evidence: `src/content/generator.py`)
- Content generation → Telegram templates: renders Telegram (evidence: `src/content/generator.py`)
- Telegram templates → Hashtag utilities: uses hashtags (evidence: `src/content/templates/grupo.py`)
- LLM routing → GPT copywriting client: dispatches copy (evidence: `src/llm/router.py`)
- LLM routing → DeepSeek ranking client: dispatches ranking (evidence: `src/llm/router.py`)
- Link endpoints → Tracked link creation: creates links (evidence: `src/api/routes/links.py`)
- Tracked link creation → SubId construction: builds tracking IDs (evidence: `src/links/shortener.py`)
- Tracked link creation → Shopee Affiliate API: requests affiliate URL (evidence: `src/links/shortener.py`)
- Link endpoints → Data repository: stores link records (evidence: `src/api/routes/links.py`)
- Analytics endpoints → Performance metrics: calculates metrics (evidence: `src/api/routes/analytics.py`)
- Analytics endpoints → Data repository: reads analytics (evidence: `src/api/routes/analytics.py`)
- Data repository → Operational database: queries and writes (evidence: `src/database/repository.py`)
- Operational database → Product and activity models: creates tables (evidence: `src/database/connection.py`)
- Shopee report fetch → Shopee Affiliate API: fetches reports (evidence: `src/analytics/report_fetcher.py`)
- Shopee report fetch → Offer collection: uses API client (evidence: `src/analytics/report_fetcher.py`)
- Analytics endpoints → Conversion attribution: supports attribution
- Performance metrics → Conversion attribution: informs attribution
- Content generation → Video generation: feeds video pipeline
- Video generation → Voice generation: adds narration
- Video generation → Video storage: stores media
- Publishing schedule → Telegram publishing: schedules posts
- Publishing schedule → Channel publishing: schedules posts
- Channel publishing → Affiliate operator: publishes channels
- Telegram publishing → Affiliate operator: publishes Telegram
- Product endpoints → Structured logging: logs activity (evidence: `src/api/routes/products.py`)
- Content endpoints → Structured logging: logs activity (evidence: `src/api/routes/content.py`)
