Skip to Content
ContributeCoding Standards

Coding Standards

Coding standards for the Rhesis project: quality, consistency, and easier reviews.

Code quality Shared conventions reduce bugs and make changes easier to review. Follow these guidelines for all contributions.

Python Standards

Code Style

We follow PEP 8  and use Ruff  for formatting and linting.

Basic rules:

  • Indentation: 4 spaces (no tabs)
  • Line length: 100 characters maximum
  • Naming: snake_case for variables, functions, and modules
  • Classes: PascalCase
  • Constants: UPPER_CASE

Type hints

Use type hints on new and updated functions and methods.

Docstrings

Use Google-style docstrings for public functions and classes:

docstring_example.py
def average(nums: list[float]) -> float:
    """Arithmetic mean of ``nums``.

    Args:
        nums: Values to average; must be non-empty.

    Returns:
        Mean value.

    Raises:
        ValueError: If ``nums`` is empty.
    """
    if not nums:
        raise ValueError("nums must not be empty")
    return sum(nums) / len(nums)

Error handling

Prefer specific exceptions, avoid bare except:, and use raise ... from err when chaining:

errors_example.py
def get_item(item_id: int, db: Session) -> Item:
    row = db.get(Item, item_id)
    if row is None:
        raise ItemNotFoundError(item_id)
    return row

Testing

  • Use pytest; put tests under the paths each package documents (e.g. tests/backend, tests/sdk).
  • Cover new behavior and regressions; mock external I/O where appropriate.
  • Run checks with each app’s Makefile (make test, make lint, etc.) from apps/backend, sdk, or apps/frontend as applicable.

JavaScript/TypeScript Standards

Code style

ESLint and Prettier enforce formatting.

Basic rules:

  • Indentation: 2 spaces
  • Line length: 100 characters maximum
  • Naming: camelCase for values and functions; PascalCase for components
  • Constants: UPPER_SNAKE_CASE

TypeScript

Use strict typing for new code:

api.ts
type User = { id: string; name: string };

async function getUser(id: string): Promise<User> {
const res = await fetch(`/api/users/${id}`);
if (!res.ok) throw new Error(String(res.status));
return res.json();
}

React components

Prefer function components, typed props, and hooks; keep components small:

Badge.tsx
type BadgeProps = { label: string };

export function Badge({ label }: BadgeProps) {
return <span className="rounded px-2 py-0.5 text-sm">{label}</span>;
}

Custom hooks

Encapsulate data fetching and shared state in hooks (e.g. React Query for server state):

useItem.ts
import { useQuery } from '@tanstack/react-query';

export function useItem(id: string) {
return useQuery({
    queryKey: ['item', id],
    queryFn: () => fetchItem(id),
    enabled: Boolean(id),
});
}

Error handling

Use error boundaries for UI trees; log or report unexpected errors in one place:

ErrorBoundary.tsx
import React from 'react';

export class ErrorBoundary extends React.Component<
{ children: React.ReactNode },
{ error?: Error }
> {
state: { error?: Error } = {};

static getDerivedStateFromError(error: Error) {
    return { error };
}

render() {
    if (this.state.error) return <p>Something went wrong.</p>;
    return this.props.children;
}
}