server-skills

Server-specific best practices for FastAPI, Celery, and Pydantic. Extends python-skills with framework-specific patterns.

830 stars

Best use case

server-skills is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Server-specific best practices for FastAPI, Celery, and Pydantic. Extends python-skills with framework-specific patterns.

Teams using server-skills should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/server-skills/SKILL.md --create-dirs "https://raw.githubusercontent.com/llama-farm/llamafarm/main/.claude/skills/server-skills/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/server-skills/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How server-skills Compares

Feature / Agentserver-skillsStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Server-specific best practices for FastAPI, Celery, and Pydantic. Extends python-skills with framework-specific patterns.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# Server Skills for LlamaFarm

Framework-specific patterns and code review checklists for the LlamaFarm Server component.

## Overview

| Property | Value |
|----------|-------|
| Path | `server/` |
| Python | 3.12+ |
| Framework | FastAPI 0.116+ |
| Task Queue | Celery 5.5+ |
| Validation | Pydantic 2.x, pydantic-settings |
| Logging | structlog with FastAPIStructLogger |

## Links to Shared Skills

This skill extends the shared Python skills. See:

- [Python Patterns](../python-skills/patterns.md) - Dataclasses, comprehensions, imports
- [Async Patterns](../python-skills/async.md) - async/await, asyncio, concurrency
- [Typing Patterns](../python-skills/typing.md) - Type hints, generics, Pydantic
- [Testing Patterns](../python-skills/testing.md) - Pytest, fixtures, mocking
- [Error Handling](../python-skills/error-handling.md) - Exceptions, logging, context managers
- [Security Patterns](../python-skills/security.md) - Path traversal, injection, secrets

## Server-Specific Checklists

| Topic | File | Key Points |
|-------|------|------------|
| FastAPI | [fastapi.md](fastapi.md) | Routes, dependencies, middleware, exception handlers |
| Celery | [celery.md](celery.md) | Task patterns, error handling, retries, signatures |
| Pydantic | [pydantic.md](pydantic.md) | Pydantic v2 models, validation, serialization |
| Performance | [performance.md](performance.md) | Async patterns, caching, connection pooling |

## Architecture Overview

```
server/
├── main.py                 # Uvicorn entry point, MCP mount
├── api/
│   ├── main.py             # FastAPI app factory, middleware setup
│   ├── errors.py           # Custom exceptions + exception handlers
│   ├── middleware/         # ASGI middleware (structlog, errors)
│   └── routers/            # API route modules
│       ├── projects/       # Project CRUD endpoints
│       ├── datasets/       # Dataset management
│       ├── rag/            # RAG query endpoints
│       └── ...
├── core/
│   ├── settings.py         # pydantic-settings configuration
│   ├── logging.py          # structlog setup, FastAPIStructLogger
│   └── celery/             # Celery app configuration
│       ├── celery.py       # Celery app instance
│       └── rag_client.py   # RAG task signatures and helpers
├── services/               # Business logic layer
│   ├── project_service.py  # Project CRUD operations
│   ├── dataset_service.py  # Dataset management
│   └── ...
├── agents/                 # AI agent implementations
└── tests/                  # Pytest test suite
```

## Quick Reference

### Settings Pattern (pydantic-settings)

```python
from pydantic_settings import BaseSettings

class Settings(BaseSettings, env_file=".env"):
    HOST: str = "0.0.0.0"
    PORT: int = 14345
    LOG_LEVEL: str = "INFO"

settings = Settings()  # Module-level singleton
```

### Structured Logging

```python
from core.logging import FastAPIStructLogger

logger = FastAPIStructLogger(__name__)
logger.info("Operation completed", extra={"count": 10, "duration_ms": 150})
logger.bind(namespace=namespace, project=project_id)  # Add context
```

### Custom Exceptions

```python
# Define exception hierarchy
class NotFoundError(Exception): ...
class ProjectNotFoundError(NotFoundError):
    def __init__(self, namespace: str, project_id: str):
        self.namespace = namespace
        self.project_id = project_id
        super().__init__(f"Project {namespace}/{project_id} not found")

# Register handler in api/errors.py
async def _handle_project_not_found(request: Request, exc: Exception) -> Response:
    payload = ErrorResponse(error="ProjectNotFound", message=str(exc))
    return JSONResponse(status_code=404, content=payload.model_dump())

def register_exception_handlers(app: FastAPI) -> None:
    app.add_exception_handler(ProjectNotFoundError, _handle_project_not_found)
```

### Service Layer Pattern

```python
class ProjectService:
    @classmethod
    def get_project(cls, namespace: str, project_id: str) -> Project:
        project_dir = cls.get_project_dir(namespace, project_id)
        if not os.path.isdir(project_dir):
            raise ProjectNotFoundError(namespace, project_id)
        # ... load and validate
```

## Review Checklist Summary

1. **FastAPI Routes** (High priority)
   - Proper async/sync function choice
   - Response model defined with `response_model=`
   - OpenAPI metadata (operation_id, tags, summary)
   - HTTPException with proper status codes

2. **Celery Tasks** (High priority)
   - Use signatures for cross-service calls
   - Implement proper timeout and polling
   - Handle task failures gracefully
   - Store group metadata for parallel tasks

3. **Pydantic Models** (Medium priority)
   - Use Pydantic v2 patterns (model_config, Field)
   - Proper validation with field constraints
   - Serialization with model_dump()

4. **Performance** (Medium priority)
   - Avoid blocking calls in async functions
   - Use proper connection pooling for external services
   - Implement caching where appropriate

See individual topic files for detailed checklists with grep patterns.

Related Skills

typescript-skills

830
from llama-farm/llamafarm

Shared TypeScript best practices for Designer and Electron subsystems.

runtime-skills

830
from llama-farm/llamafarm

Universal Runtime best practices for PyTorch inference, Transformers models, and FastAPI serving. Covers device management, model loading, memory optimization, and performance tuning.

react-skills

830
from llama-farm/llamafarm

React 18 patterns for LlamaFarm Designer. Covers components, hooks, TanStack Query, and testing.

rag-skills

830
from llama-farm/llamafarm

RAG-specific best practices for LlamaIndex, ChromaDB, and Celery workers. Covers ingestion, retrieval, embeddings, and performance.

python-skills

830
from llama-farm/llamafarm

Shared Python best practices for LlamaFarm. Covers patterns, async, typing, testing, error handling, and security.

go-skills

830
from llama-farm/llamafarm

Shared Go best practices for LlamaFarm CLI. Covers idiomatic patterns, error handling, and testing.

generate-subsystem-skills

830
from llama-farm/llamafarm

Generate specialized skills for each subsystem in the monorepo. Creates shared language skills and subsystem-specific checklists for high-quality AI code generation.

config-skills

830
from llama-farm/llamafarm

Configuration module patterns for LlamaFarm. Covers Pydantic v2 models, JSONSchema generation, YAML processing, and validation.

common-skills

830
from llama-farm/llamafarm

Best practices for the Common utilities package in LlamaFarm. Covers HuggingFace Hub integration, GGUF model management, and shared utilities.

cli-skills

830
from llama-farm/llamafarm

CLI best practices for LlamaFarm. Covers Cobra, Bubbletea, Lipgloss patterns for Go CLI development.

electron-skills

830
from llama-farm/llamafarm

Electron patterns for LlamaFarm Desktop. Covers main/renderer processes, IPC, security, and packaging.

designer-skills

830
from llama-farm/llamafarm

Designer subsystem patterns for LlamaFarm. Covers React 18, TanStack Query, TailwindCSS, and Radix UI.