本文へ移動
cccskills
無料GitHub で公開

fastapi-pipeline-architect

Guide for building and refactoring a FastAPI + Prefect + PostgreSQL/pgvector analytics pipeline that extracts insights from chat data using LLM classification, embeddings, UMAP/HDBSCAN clustering, and narrative generation. Use this skill whenever working on this project's codebase — including adding features, refactoring, debugging, creating new endpoints, modifying pipeline stages, or reviewing architecture decisions. Also trigger when the user asks about project structure, stack decisions, async migration, or best practices for this specific system.

インストール方法を見る

含まれるファイル(1)

  • SKILL.md8.1 KB

SKILL.md(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

FastAPI Pipeline Architect

This skill guides development of an analytics backend that processes customer chat data through a multi-stage pipeline: ingestion → preprocessing → classification → embedding → clustering → labeling → narrative generation, served via FastAPI with results stored in PostgreSQL + pgvector.

Stack

LayerTechnology
APIFastAPI + asyncpg + SQLAlchemy (async) + Alembic
OrchestrationPrefect
DatabasePostgreSQL + pgvector
EmbeddingsJina AI (or configurable provider)
ClusteringUMAP + HDBSCAN
LLMAnthropic SDK (Claude)
Frontend LLMVercel AI SDK
ValidationPydantic v2 + pydantic-settings
Testingpytest + pytest-asyncio + httpx

Target Project Structure

When creating new files or refactoring, follow this layout:

.
├── Dockerfile
├── pipeline_config.yaml
├── pyproject.toml
├── alembic/
│   ├── alembic.ini
│   ├── env.py
│   └── versions/
└── src/
    ├── __init__.py
    ├── main.py                    # FastAPI app entrypoint, mounts routers
    ├── config.py                  # Pydantic BaseSettings, single source of truth
    ├── deps.py                    # FastAPI dependencies (get_db, get_llm, auth)
    ├── db.py                      # Async engine + session factory (asyncpg)
    ├── models/                    # Pydantic v2 schemas — all validation here
    │   ├── __init__.py
    │   ├── pipeline.py            # PipelineRun, StageResult, ClusterOutput...
    │   ├── chat.py                # ChatRequest, ChatResponse...
    │   ├── insights.py            # InsightQuery, InsightResponse...
    │   └── rag.py                 # RAGQuery, RAGResult...
    ├── services/                   # Shared business logic, no duplication
    │   ├── __init__.py
    │   ├── embeddings.py          # ONE embedding service (used by RAG + pipeline)
    │   ├── llm.py                 # ONE LLM client factory (used everywhere)
    │   └── cache.py               # Cache layer (Redis or PG-based)
    ├── routers/
    │   ├── __init__.py
    │   ├── chat.py
    │   ├── insights.py
    │   ├── pipeline_runs.py
    │   ├── rag_chat.py
    │   └── streaming.py
    ├── rag/
    │   ├── __init__.py
    │   ├── ingest.py
    │   ├── retriever.py
    │   └── store.py
    └── pipeline_system/
        ├── __init__.py
        ├── config.py              # Pipeline-specific config (extends base)
        ├── flows.py               # Prefect flows
        ├── tasks.py               # Prefect tasks
        ├── stages/                # One file per pipeline stage
        │   ├── __init__.py
        │   ├── preprocessor.py
        │   ├── classifier.py
        │   ├── embedder.py        # Calls services/embeddings.py
        │   ├── clusterer.py       # UMAP + HDBSCAN logic
        │   ├── labeler.py
        │   ├── narrator.py
        │   └── dashboard_generator.py
        ├── prompts.py
        ├── utils.py
        ├── db/
        │   ├── __init__.py
        │   ├── fetcher.py
        │   ├── service.py
        │   └── writer.py
        └── spanish_preprocessor/
            ├── __init__.py
            ├── preprocess.py
            ├── chat_abbreviations.py
            ├── emo_unicode.py
            ├── inclusive_words.py
            └── stopwords.py

Key structural rules:

  • No duplicate services. services/embeddings.py is the ONE place embeddings are created. Both rag/ and pipeline_system/stages/embedder.py import from it.
  • No duplicate LLM clients. services/llm.py is the ONE place LLM clients are initialized. Everything else imports from it.
  • All Pydantic schemas live in models/. Routers, pipeline stages, and services import from there.
  • Config flows down. src/config.py holds all env vars. pipeline_system/config.py extends it for pipeline-specific settings. Nothing else reads env vars directly.

Architecture Rules

Read references/architecture.md for detailed implementation patterns covering:

  • Async SQLAlchemy setup
  • Config with Pydantic BaseSettings
  • Dependency injection
  • Pipeline run isolation
  • Embedding versioning
  • Auth patterns
  • Error handling
  • Testing patterns

Refactoring Checklist

When refactoring the existing codebase toward this target structure, follow this order. Each step is safe to do independently without breaking functionality.

Phase 1: Foundation (no behavior changes)

  1. Create src/config.py with BaseSettings — move all env var reads here
  2. Create src/models/ and extract all Pydantic schemas into it
  3. Create src/services/embeddings.py — unify the two embedders
  4. Create src/services/llm.py — unify the two LLM providers
  5. Create src/deps.py — centralize FastAPI dependencies
  6. Ensure src/db.py is the only place that creates engine/sessions

Phase 2: Async + safety

  1. Migrate src/db.py to async engine + sessions (asyncpg)
  2. Add pipeline_run_id to all derived/output tables
  3. Add model_version column to embedding tables
  4. Add basic API key auth via deps.py

Phase 3: Operational

  1. Add /health and /ready endpoints
  2. Add structured logging (structlog) for LLM calls
  3. Lock down CORS to real domains
  4. Add LLM response fixtures for deterministic tests

Phase 4: Scale (when needed)

  1. Cursor-based pagination on insight endpoints
  2. Cache layer for expensive computations
  3. Semaphore-based concurrency limiter per external API
  4. HDBSCAN parameter auto-tuning based on data volume
  5. PgBouncer for connection pooling

When Creating New Pipeline Stages

Every pipeline stage must:

  1. Accept and return Pydantic models (defined in src/models/pipeline.py)
  2. Be a Prefect @task with retries and result caching
  3. Accept a pipeline_run_id parameter and tag all outputs with it
  4. Use the shared embedding/LLM services (never instantiate clients directly)
  5. Be idempotent — safe to re-run without side effects
  6. Log structured metadata: stage name, input count, output count, duration, tokens used

When Creating New Endpoints

Every FastAPI endpoint must:

  1. Use Pydantic models for request/response (from src/models/)
  2. Get DB session via Depends(get_db) from deps.py
  3. Get auth via Depends(get_api_key) from deps.py
  4. Never run pipeline logic synchronously — trigger via Prefect, serve results from DB
  5. Use cursor-based pagination for list endpoints
  6. Return consistent error responses using a shared exception handler

When Modifying Database Schema

  1. Always create an Alembic migration — never modify tables manually
  2. Include pipeline_run_id on any table that stores pipeline outputs
  3. Include model_version on any table that stores embeddings
  4. Include created_at and updated_at timestamps on all tables
  5. Use pgvector's vector type for embedding columns with appropriate HNSW index

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

同じリポジトリのスキル

概要と使いどころ

Aplica el branding de Vambe a PPTX, DOCX, XLSX y HTML. Usa al crear presentaciones, Word, Excel o páginas con identidad visual de Vambe, o si pide "hacerlo bonito" / "estilo Vambe".

日本語の概要は準備中です。原文の説明を表示しています。

sebastianbreguel/dotfiles32026年10月8日 更新

Read this skill before the first step that uses the built-in browser, the browser pane inside the Claude desktop app (also called the in-app browser, the browser pane, Claude's browser, or "your own browser"), whose tools are named mcp__Claude_Browser__* when the session runs in the desktop app and mcp__remote-devices__Claude_Browser__* when a cloud session is linked to the person's computer; before those tools are turned on there may be a single enable__mcp__remote-devices__Claude_Browser tool instead. It covers the pane's persistent sign-ins, tabs and preview_start, reading pages as text, site approvals, what the pane cannot open, and what to do when it cannot be reached. It is not for Claude in Chrome (mcp__claude-in-chrome__* tools), which has its own skill, and it does not decide which browser to use.

日本語の概要は準備中です。原文の説明を表示しています。

sebastianbreguel/dotfiles32026年10月8日 更新

Read this skill before the first step that uses Claude in Chrome, the browser extension whose tools are named mcp__claude-in-chrome__* (also called Chrome, the browser extension, or the external browser) and which acts in the person's real Chrome with their own sign-ins; before those tools are turned on there may be a single enable__mcp__claude-in-chrome tool instead. It covers loading the tools in one ToolSearch call, checking the person's open tabs and working in a new tab, site permissions, GIF recordings, console logs, dialogs to avoid, and when to stop and ask. It is not for the built-in browser (mcp__Claude_Browser__* or mcp__remote-devices__Claude_Browser__* tools), which has its own skill, and it does not decide which browser to use.

日本語の概要は準備中です。原文の説明を表示しています。

sebastianbreguel/dotfiles32026年10月8日 更新

Shared vocabulary for designing deep modules. Use when the user wants to design or improve a module's interface, find deepening opportunities, decide where a seam goes, make code more testable or AI-navigable, or when another skill needs the deep-module vocabulary.

日本語の概要は準備中です。原文の説明を表示しています。

sebastianbreguel/dotfiles32026年10月8日 更新

Read this skill before the first step of any request to do something in an app on the person's own computer (Notes, Finder, System Settings, any desktop app), to look at their screen, or for "computer use". Computer use (desktop control) lets Claude take screenshots of the person's desktop and control it with clicks, typing and scrolling through the Claude desktop app; its tools are named mcp__computer-use__* when the session runs in the desktop app and mcp__remote-devices__computer_* when a cloud session is linked to the person's computer; before computer use is turned on for a conversation there may be no such tools, only an enable__mcp__remote-devices__computer tool, which turns it on. It covers turning it on, picking the right tool, the access flow, and the safety rules for tiered apps, links and financial actions. It is not for websites, which go through Claude in Chrome or the built-in browser and their own skills.

日本語の概要は準備中です。原文の説明を表示しています。

sebastianbreguel/dotfiles32026年10月8日 更新

Use this skill when the user's prompt requires (1) researching a topic across multiple sources, comparing options or alternatives, analyzing trends or history, understanding markets or industries, or reviewing literature or studies and (2) synthesizing that research into a comprehensive, narrative report. If you're planning to search the web or internal knowledge bases, consider using this skill. This skill coordinates research subagents, so use it only when you have a tool for spawning subagents (the Agent or Task tool); otherwise, research the question directly.

日本語の概要は準備中です。原文の説明を表示しています。

sebastianbreguel/dotfiles32026年10月8日 更新

sebastianbreguel のスキルをすべて見る

このスキルの問題を報告する