Code Style¶
Coding standards and style guidelines for NextSight AI.
Python (Backend)¶
Formatting¶
We use Black for code formatting:
Import Sorting¶
We use isort for import sorting:
Linting¶
We use Ruff for linting:
Type Hints¶
Use type hints for all function signatures:
Docstrings¶
Use Google-style docstrings:
async def scale_deployment(name: str, replicas: int) -> dict:
"""Scale a deployment to the specified replica count.
Args:
name: The deployment name.
replicas: Target replica count.
Returns:
Dictionary with scaling result.
Raises:
HTTPException: If deployment not found.
"""
TypeScript (Frontend)¶
Formatting¶
We use Prettier for formatting:
Linting¶
We use ESLint for linting:
Type Definitions¶
Always define proper types:
interface Pod {
name: string;
namespace: string;
status: PodStatus;
containers: Container[];
}
const getPods = async (namespace?: string): Promise<Pod[]> => {
...
};
Component Structure¶
// Imports
import { useState, useEffect } from 'react';
import { Pod } from '../types';
// Types
interface PodListProps {
namespace?: string;
}
// Component
export function PodList({ namespace }: PodListProps) {
const [pods, setPods] = useState<Pod[]>([]);
useEffect(() => {
// Effect logic
}, [namespace]);
return (
<div>
{pods.map((pod) => (
<PodCard key={pod.name} pod={pod} />
))}
</div>
);
}
Git Commit Messages¶
Follow conventional commits:
Types¶
feat- New featurefix- Bug fixdocs- Documentationstyle- Formattingrefactor- Code refactoringtest- Adding testschore- Maintenance
Examples¶
feat(security): add vulnerability scanning
fix(kubernetes): handle missing container status
docs(api): update endpoint documentation
File Naming¶
Python¶
- Snake case:
kubernetes_service.py - Classes: PascalCase
TypeScript¶
- PascalCase for components:
PodList.tsx - camelCase for utilities:
apiClient.ts
Testing¶
Python Tests¶
import pytest
@pytest.mark.asyncio
async def test_get_pods():
pods = await kubernetes_service.get_pods()
assert isinstance(pods, list)