# kid0317/crewai_mas_demo_m2l7 architecture

> Architecture diagram of the GitHub repository kid0317/crewai_mas_demo_m2l7, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kid0317/crewai_mas_demo_m2l7
- Repository: https://github.com/kid0317/crewai_mas_demo_m2l7

## Overview

This is a FastAPI service that accepts a creative brief and multiple images, then returns a structured Xiaohongshu note report. Its main workflow validates the request, saves and compresses images, runs image analysis and editing followed by strategy, copywriting, and SEO stages, and formats the result. The graph also shows the documented API security and observability capabilities, plus persistence components present in the tree. Some links rely on README or SOURCE INDEX references; unsampled implementation details are not inferred.

Main entry points: [`src/app/crews/xhs_note/flows.py`](https://github.com/kid0317/crewai_mas_demo_m2l7/blob/main/src/app/crews/xhs_note/flows.py) (Flow orchestration), [`src/app/api/v1/xhs_note.py`](https://github.com/kid0317/crewai_mas_demo_m2l7/blob/main/src/app/api/v1/xhs_note.py) (Report endpoint), [`src/app/main.py`](https://github.com/kid0317/crewai_mas_demo_m2l7/blob/main/src/app/main.py) (FastAPI app), [`src/app/services/xhs_note_service.py`](https://github.com/kid0317/crewai_mas_demo_m2l7/blob/main/src/app/services/xhs_note_service.py) (Note service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["HTTP API"]
  node_endpoint["Report endpoint<br/>[xhs_note.py]"]
  node_auth["API key checks<br/>[security.py]"]
  node_requestdeps["Request dependencies<br/>[dependencies.py]"]
  node_response["Response schemas<br/>[common.py]"]
end

subgraph group_content["Note Generation"]
  node_models["Note data models<br/>[xhs_note.py]"]
  node_service["Note service"]
  node_images["Image processing<br/>[image_utils.py]"]
  node_flow["Flow orchestration<br/>[flows.py]"]
  node_visual["Visual analysis<br/>[flows.py]"]
  node_editing["Image editing<br/>[flows.py]"]
  node_strategy["Content strategy<br/>[flows.py]"]
  node_copy["Copywriting<br/>[flows.py]"]
  node_seo["SEO optimization<br/>[flows.py]"]
  node_agents["Agent factory<br/>[agents.py]"]
  node_tasks["Task factory<br/>[tasks.py]"]
  node_tools["Crew tools"]
  node_llm["Aliyun LLM adapter<br/>[aliyun_llm.py]"]
end

subgraph group_platform["Application Platform"]
  node_app["FastAPI app<br/>[main.py]"]
  node_health["Health endpoints<br/>[health.py]"]
  node_config["Application settings<br/>[config.py]"]
  node_trace["HTTP tracing<br/>[http_trace.py]"]
  node_logging["Structured logging<br/>[logging.py]"]
  node_metrics["Prometheus metrics<br/>[metrics.py]"]
end

subgraph group_data["Persistence"]
  node_oceanbase["OceanBase client"]
  node_dbmodel["Database base model<br/>[base.py]"]
  node_fileclient["Local file client<br/>[file_client.py]"]
end

node_user(("API caller"))
node_aliyun{{"Aliyun model service"}}

node_user -->|"submits images"| node_endpoint
node_app -->|"mounts router"| node_endpoint
node_app -->|"mounts routes"| node_health
node_endpoint -->|"checks API key"| node_auth
node_endpoint -->|"gets request ID"| node_requestdeps
node_endpoint -->|"calls"| node_service
node_endpoint -->|"returns envelope"| node_response
node_service -->|"compresses images"| node_images
node_service -->|"builds request"| node_models
node_service -->|"runs flow"| node_flow
node_flow -->|"runs phase"| node_visual
node_flow -->|"runs phase"| node_editing
node_flow -->|"runs phase"| node_strategy
node_flow -->|"runs phase"| node_copy
node_flow -->|"runs phase"| node_seo
node_flow -->|"builds tasks"| node_tasks
node_tasks -->|"creates agents"| node_agents
node_agents -->|"gets model"| node_llm
node_agents -->|"registers tools"| node_tools
node_llm -->|"sends requests"| node_aliyun
node_app -->|"loads settings"| node_config
node_app -->|"installs middleware"| node_trace
node_trace -->|"records context"| node_logging
node_app -->|"exposes metrics"| node_metrics
node_oceanbase -->|"reads settings"| node_config
node_oceanbase -->|"uses model base"| node_dbmodel

click node_app "https://github.com/kid0317/crewai_mas_demo_m2l7/blob/main/src/app/main.py"
click node_health "https://github.com/kid0317/crewai_mas_demo_m2l7/blob/main/src/app/api/v1/health.py"
click node_endpoint "https://github.com/kid0317/crewai_mas_demo_m2l7/blob/main/src/app/api/v1/xhs_note.py"
click node_auth "https://github.com/kid0317/crewai_mas_demo_m2l7/blob/main/src/app/core/security.py"
click node_requestdeps "https://github.com/kid0317/crewai_mas_demo_m2l7/blob/main/src/app/api/dependencies.py"
click node_response "https://github.com/kid0317/crewai_mas_demo_m2l7/blob/main/src/app/schemas/common.py"
click node_models "https://github.com/kid0317/crewai_mas_demo_m2l7/blob/main/src/app/schemas/xhs_note.py"
click node_service "https://github.com/kid0317/crewai_mas_demo_m2l7/blob/main/src/app/services/xhs_note_service.py"
click node_images "https://github.com/kid0317/crewai_mas_demo_m2l7/blob/main/src/app/core/image_utils.py"
click node_flow "https://github.com/kid0317/crewai_mas_demo_m2l7/blob/main/src/app/crews/xhs_note/flows.py"
click node_visual "https://github.com/kid0317/crewai_mas_demo_m2l7/blob/main/src/app/crews/xhs_note/flows.py"
click node_editing "https://github.com/kid0317/crewai_mas_demo_m2l7/blob/main/src/app/crews/xhs_note/flows.py"
click node_strategy "https://github.com/kid0317/crewai_mas_demo_m2l7/blob/main/src/app/crews/xhs_note/flows.py"
click node_copy "https://github.com/kid0317/crewai_mas_demo_m2l7/blob/main/src/app/crews/xhs_note/flows.py"
click node_seo "https://github.com/kid0317/crewai_mas_demo_m2l7/blob/main/src/app/crews/xhs_note/flows.py"
click node_agents "https://github.com/kid0317/crewai_mas_demo_m2l7/blob/main/src/app/crews/xhs_note/agents.py"
click node_tasks "https://github.com/kid0317/crewai_mas_demo_m2l7/blob/main/src/app/crews/xhs_note/tasks.py"
click node_tools "https://github.com/kid0317/crewai_mas_demo_m2l7/blob/main/src/app/crews/tools/add_image_tool_local.py"
click node_llm "https://github.com/kid0317/crewai_mas_demo_m2l7/blob/main/src/app/crews/llm/aliyun_llm.py"
click node_config "https://github.com/kid0317/crewai_mas_demo_m2l7/blob/main/src/app/core/config.py"
click node_trace "https://github.com/kid0317/crewai_mas_demo_m2l7/blob/main/src/app/observability/http_trace.py"
click node_logging "https://github.com/kid0317/crewai_mas_demo_m2l7/blob/main/src/app/observability/logging.py"
click node_metrics "https://github.com/kid0317/crewai_mas_demo_m2l7/blob/main/src/app/observability/metrics.py"
click node_oceanbase "https://github.com/kid0317/crewai_mas_demo_m2l7/blob/main/src/app/db/clients/oceanbase_client.py"
click node_dbmodel "https://github.com/kid0317/crewai_mas_demo_m2l7/blob/main/src/app/db/models/base.py"
click node_fileclient "https://github.com/kid0317/crewai_mas_demo_m2l7/blob/main/src/app/db/clients/file_client.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_endpoint,node_auth,node_requestdeps,node_response toneBlue
class node_models,node_service,node_images,node_flow,node_visual,node_editing,node_strategy,node_copy,node_seo,node_agents,node_tasks,node_tools,node_llm toneAmber
class node_app,node_health,node_config,node_trace,node_logging,node_metrics,node_user toneMint
class node_oceanbase,node_dbmodel,node_fileclient toneRose
class node_aliyun toneIndigo
```

## Components

### HTTP API

- [Report endpoint](https://github.com/kid0317/crewai_mas_demo_m2l7/blob/main/src/app/api/v1/xhs_note.py): `src/app/api/v1/xhs_note.py`
- [API key checks](https://github.com/kid0317/crewai_mas_demo_m2l7/blob/main/src/app/core/security.py): `src/app/core/security.py`
- [Request dependencies](https://github.com/kid0317/crewai_mas_demo_m2l7/blob/main/src/app/api/dependencies.py): `src/app/api/dependencies.py`
- [Response schemas](https://github.com/kid0317/crewai_mas_demo_m2l7/blob/main/src/app/schemas/common.py): `src/app/schemas/common.py`

### Note Generation

- [Note data models](https://github.com/kid0317/crewai_mas_demo_m2l7/blob/main/src/app/schemas/xhs_note.py): `src/app/schemas/xhs_note.py`
- [Note service](https://github.com/kid0317/crewai_mas_demo_m2l7/blob/main/src/app/services/xhs_note_service.py): `src/app/services/xhs_note_service.py`
- [Image processing](https://github.com/kid0317/crewai_mas_demo_m2l7/blob/main/src/app/core/image_utils.py): `src/app/core/image_utils.py`
- [Flow orchestration](https://github.com/kid0317/crewai_mas_demo_m2l7/blob/main/src/app/crews/xhs_note/flows.py): `src/app/crews/xhs_note/flows.py`
- [Visual analysis](https://github.com/kid0317/crewai_mas_demo_m2l7/blob/main/src/app/crews/xhs_note/flows.py): `src/app/crews/xhs_note/flows.py`
- [Image editing](https://github.com/kid0317/crewai_mas_demo_m2l7/blob/main/src/app/crews/xhs_note/flows.py): `src/app/crews/xhs_note/flows.py`
- [Content strategy](https://github.com/kid0317/crewai_mas_demo_m2l7/blob/main/src/app/crews/xhs_note/flows.py): `src/app/crews/xhs_note/flows.py`
- [Copywriting](https://github.com/kid0317/crewai_mas_demo_m2l7/blob/main/src/app/crews/xhs_note/flows.py): `src/app/crews/xhs_note/flows.py`
- [SEO optimization](https://github.com/kid0317/crewai_mas_demo_m2l7/blob/main/src/app/crews/xhs_note/flows.py): `src/app/crews/xhs_note/flows.py`
- [Agent factory](https://github.com/kid0317/crewai_mas_demo_m2l7/blob/main/src/app/crews/xhs_note/agents.py): `src/app/crews/xhs_note/agents.py`
- [Task factory](https://github.com/kid0317/crewai_mas_demo_m2l7/blob/main/src/app/crews/xhs_note/tasks.py): `src/app/crews/xhs_note/tasks.py`
- [Crew tools](https://github.com/kid0317/crewai_mas_demo_m2l7/blob/main/src/app/crews/tools/add_image_tool_local.py): `src/app/crews/tools/add_image_tool_local.py`
- [Aliyun LLM adapter](https://github.com/kid0317/crewai_mas_demo_m2l7/blob/main/src/app/crews/llm/aliyun_llm.py): `src/app/crews/llm/aliyun_llm.py`

### Application Platform

- [FastAPI app](https://github.com/kid0317/crewai_mas_demo_m2l7/blob/main/src/app/main.py): `src/app/main.py`
- [Health endpoints](https://github.com/kid0317/crewai_mas_demo_m2l7/blob/main/src/app/api/v1/health.py): `src/app/api/v1/health.py`
- [Application settings](https://github.com/kid0317/crewai_mas_demo_m2l7/blob/main/src/app/core/config.py): `src/app/core/config.py`
- [HTTP tracing](https://github.com/kid0317/crewai_mas_demo_m2l7/blob/main/src/app/observability/http_trace.py): `src/app/observability/http_trace.py`
- [Structured logging](https://github.com/kid0317/crewai_mas_demo_m2l7/blob/main/src/app/observability/logging.py): `src/app/observability/logging.py`
- [Prometheus metrics](https://github.com/kid0317/crewai_mas_demo_m2l7/blob/main/src/app/observability/metrics.py): `src/app/observability/metrics.py`

### Persistence

- [OceanBase client](https://github.com/kid0317/crewai_mas_demo_m2l7/blob/main/src/app/db/clients/oceanbase_client.py): `src/app/db/clients/oceanbase_client.py`
- [Database base model](https://github.com/kid0317/crewai_mas_demo_m2l7/blob/main/src/app/db/models/base.py): `src/app/db/models/base.py`
- [Local file client](https://github.com/kid0317/crewai_mas_demo_m2l7/blob/main/src/app/db/clients/file_client.py): `src/app/db/clients/file_client.py`

### Other components

- **API caller**
- **Aliyun model service**

## Connections

- API caller → Report endpoint: submits images (evidence: `README.md`)
- FastAPI app → Report endpoint: mounts router (evidence: `src/app/main.py`)
- FastAPI app → Health endpoints: mounts routes (evidence: `src/app/main.py`)
- Report endpoint → API key checks: checks API key
- Report endpoint → Request dependencies: gets request ID (evidence: `src/app/api/v1/xhs_note.py`)
- Report endpoint → Note service: calls (evidence: `src/app/api/v1/xhs_note.py`)
- Report endpoint → Response schemas: returns envelope (evidence: `src/app/api/v1/xhs_note.py`)
- Note service → Image processing: compresses images (evidence: `src/app/services/xhs_note_service.py`)
- Note service → Note data models: builds request (evidence: `src/app/services/xhs_note_service.py`)
- Note service → Flow orchestration: runs flow (evidence: `src/app/services/xhs_note_service.py`)
- Flow orchestration → Visual analysis: runs phase (evidence: `README.md`)
- Flow orchestration → Image editing: runs phase (evidence: `README.md`)
- Flow orchestration → Content strategy: runs phase (evidence: `README.md`)
- Flow orchestration → Copywriting: runs phase (evidence: `README.md`)
- Flow orchestration → SEO optimization: runs phase (evidence: `README.md`)
- Flow orchestration → Task factory: builds tasks (evidence: `src/app/crews/xhs_note/flows.py`)
- Task factory → Agent factory: creates agents (evidence: `src/app/crews/xhs_note/tasks.py`)
- Agent factory → Aliyun LLM adapter: gets model (evidence: `src/app/crews/xhs_note/agents.py`)
- Agent factory → Crew tools: registers tools (evidence: `src/app/crews/xhs_note/agents.py`)
- Aliyun LLM adapter → Aliyun model service: sends requests (evidence: `src/app/crews/llm/aliyun_llm.py`)
- FastAPI app → Application settings: loads settings (evidence: `src/app/main.py`)
- FastAPI app → HTTP tracing: installs middleware (evidence: `src/app/main.py`)
- HTTP tracing → Structured logging: records context (evidence: `src/app/observability/http_trace.py`)
- FastAPI app → Prometheus metrics: exposes metrics (evidence: `README.md`)
- OceanBase client → Application settings: reads settings (evidence: `src/app/db/clients/oceanbase_client.py`)
- OceanBase client → Database base model: uses model base (evidence: `src/app/db/clients/oceanbase_client.py`)
