168 lines
5.8 KiB
JSON
168 lines
5.8 KiB
JSON
{
|
|
"name": "Python FastAPI",
|
|
"description": "FastAPI with SQLAlchemy, Pydantic, and modern Python development practices",
|
|
"filePatterns": ["*.py"],
|
|
"excludePatterns": ["*_test.py", "*test*.py", "__pycache__/*"],
|
|
"techStack": {
|
|
"framework": "FastAPI",
|
|
"language": "Python 3.9+",
|
|
"database": "SQLAlchemy + PostgreSQL",
|
|
"validation": "Pydantic",
|
|
"testing": "Pytest + httpx",
|
|
"documentation": "OpenAPI/Swagger (auto-generated)",
|
|
"async": "asyncio + asyncpg",
|
|
"serialization": "Pydantic models"
|
|
},
|
|
"conventions": {
|
|
"naming": {
|
|
"variables": "snake_case",
|
|
"functions": "snake_case",
|
|
"classes": "PascalCase",
|
|
"constants": "UPPER_SNAKE_CASE",
|
|
"modules": "lowercase_with_underscores",
|
|
"packages": "lowercase"
|
|
},
|
|
"fileStructure": {
|
|
"routers": "app/routers/{feature}.py",
|
|
"models": "app/models/{feature}.py",
|
|
"schemas": "app/schemas/{feature}.py",
|
|
"services": "app/services/{feature}.py",
|
|
"database": "app/database.py",
|
|
"tests": "tests/test_{feature}.py"
|
|
},
|
|
"imports": {
|
|
"style": "Absolute imports from project root",
|
|
"grouping": "Standard library, third-party, local",
|
|
"sorting": "Alphabetical within groups"
|
|
}
|
|
},
|
|
"qualityChecks": {
|
|
"lint": {
|
|
"command": "flake8 .",
|
|
"config": "PEP 8 compliance",
|
|
"autoFix": false
|
|
},
|
|
"format": {
|
|
"command": "black .",
|
|
"config": "88 character line limit",
|
|
"autoFix": true
|
|
},
|
|
"typeCheck": {
|
|
"command": "mypy .",
|
|
"config": "Strict type checking",
|
|
"autoFix": false
|
|
},
|
|
"build": {
|
|
"command": "python -m compileall .",
|
|
"checkSyntax": true,
|
|
"failOnError": true
|
|
},
|
|
"test": {
|
|
"unit": "pytest tests/",
|
|
"coverage": "pytest --cov=app tests/",
|
|
"minimumCoverage": 80
|
|
}
|
|
},
|
|
"codePatterns": {
|
|
"router": {
|
|
"structure": "Use APIRouter with proper prefixes and tags",
|
|
"endpoints": "Async functions with proper HTTP methods",
|
|
"dependencies": "Use Depends() for dependency injection",
|
|
"responses": "Type-annotated response models",
|
|
"errors": "Use HTTPException for error handling"
|
|
},
|
|
"model": {
|
|
"sqlalchemy": "Use SQLAlchemy declarative base",
|
|
"relationships": "Properly define foreign keys and relationships",
|
|
"validation": "Include proper field constraints",
|
|
"timestamps": "Include created_at, updated_at fields"
|
|
},
|
|
"schema": {
|
|
"pydantic": "Use Pydantic BaseModel for request/response schemas",
|
|
"validation": "Include proper field validation",
|
|
"serialization": "Configure proper serialization options",
|
|
"inheritance": "Use inheritance for variations (Create, Update, Response)"
|
|
},
|
|
"service": {
|
|
"async": "Use async/await for database operations",
|
|
"transactions": "Implement proper transaction handling",
|
|
"error_handling": "Comprehensive error handling with custom exceptions",
|
|
"logging": "Structured logging for debugging and monitoring"
|
|
},
|
|
"testing": {
|
|
"fixtures": "Use pytest fixtures for test setup",
|
|
"client": "Use TestClient for endpoint testing",
|
|
"database": "Use separate test database",
|
|
"mocking": "Mock external dependencies and services"
|
|
}
|
|
},
|
|
"context7Libraries": [
|
|
"fastapi",
|
|
"sqlalchemy",
|
|
"pydantic",
|
|
"pytest",
|
|
"httpx",
|
|
"asyncpg",
|
|
"uvicorn",
|
|
"alembic"
|
|
],
|
|
"commonImports": {
|
|
"router": [
|
|
"from fastapi import APIRouter, Depends, HTTPException, status",
|
|
"from sqlalchemy.orm import Session",
|
|
"from app.database import get_db"
|
|
],
|
|
"model": [
|
|
"from sqlalchemy import Column, Integer, String, DateTime, ForeignKey, Boolean",
|
|
"from sqlalchemy.ext.declarative import declarative_base",
|
|
"from sqlalchemy.orm import relationship",
|
|
"from datetime import datetime"
|
|
],
|
|
"schema": [
|
|
"from pydantic import BaseModel, EmailStr, validator",
|
|
"from typing import Optional, List",
|
|
"from datetime import datetime"
|
|
],
|
|
"service": [
|
|
"from sqlalchemy.orm import Session",
|
|
"from sqlalchemy.exc import IntegrityError",
|
|
"from fastapi import HTTPException, status"
|
|
]
|
|
},
|
|
"bestPractices": [
|
|
"Use async/await for I/O operations",
|
|
"Implement proper dependency injection with Depends()",
|
|
"Use Pydantic models for request/response validation",
|
|
"Follow PEP 8 style guidelines",
|
|
"Use type hints for all functions and variables",
|
|
"Implement proper error handling with HTTP status codes",
|
|
"Use SQLAlchemy for database operations with proper relationships",
|
|
"Write comprehensive tests with pytest",
|
|
"Use environment variables for configuration",
|
|
"Implement proper logging for debugging and monitoring"
|
|
],
|
|
"securityConsiderations": [
|
|
"Validate and sanitize all input data using Pydantic",
|
|
"Use proper authentication and authorization mechanisms",
|
|
"Hash passwords using secure algorithms (bcrypt)",
|
|
"Implement rate limiting to prevent abuse",
|
|
"Use HTTPS in production environments",
|
|
"Validate JWT tokens properly",
|
|
"Use parameterized queries to prevent SQL injection",
|
|
"Implement proper CORS configuration",
|
|
"Log security-relevant events for auditing",
|
|
"Use environment variables for sensitive configuration"
|
|
],
|
|
"asyncPatterns": [
|
|
"Use async def for route handlers that perform I/O",
|
|
"Use asyncio.gather() for concurrent operations",
|
|
"Implement proper connection pooling for database",
|
|
"Use async context managers for resource management",
|
|
"Handle exceptions properly in async functions",
|
|
"Use asyncio.create_task() for background tasks",
|
|
"Implement proper shutdown handling for async resources",
|
|
"Use async generators for streaming responses",
|
|
"Avoid blocking operations in async functions",
|
|
"Use proper async testing patterns with pytest-asyncio"
|
|
]
|
|
} |