إنتقل إلى المحتوى الرئيسي

💻 Coding Standards

BayanCore enforces consistent coding standards across Python (backend), TypeScript/React (frontend), and SQL (database) to guarantee code readability, performance, and security.


1. Python (Execution & Compliance Layers)

Python is the core language for our microservices and ERPNext extensions.

  • Style Guide: Adhere strictly to PEP 8.
  • Formatter & Linter: We use Ruff for linting and code formatting. Run the checks before committing:
    ruff check .
    ruff format .
  • Type Hints: Type annotations are required on all new function signatures:
    def calculate_vat(gross_amount: float, vat_rate: float = 0.15) -> float:
    return round(gross_amount * vat_rate, 2)
  • Docstrings: Write docstrings in Google Style for all public modules, classes, and methods.

2. TypeScript & React (Experience Layer)

Our user interfaces are built with Next.js and TypeScript.

  • Style Guide: Align with standard React and TypeScript guidelines.
  • Formatting: Enforced using ESLint combined with Prettier.
  • Strong Typing: Avoid the use of any types. Utilize type definitions and interfaces for API request/response contracts:
    interface InvoiceSummaryCardProps {
    invoiceId: string;
    customerName: string;
    grossAmount: number;
    zatcaStatus: 'Cleared' | 'Failed' | 'Pending';
    }
  • Component Structure: Prefer functional components with hooks. Keep UI components focused on visual presentation, offloading business logic to custom hooks or helper utilities.

3. SQL & Database Standards (MariaDB)

Database queries and migrations must execute efficiently.

  • Keywords: Write SQL keywords in uppercase (e.g. SELECT, INSERT, JOIN, WHERE).
  • Identifiers: Table and column names must be lowercase using snake_case (e.g. tenant_consent_log).
  • Query Optimization:
    • Avoid using SELECT * in production code; retrieve only columns needed.
    • Verify queries against indexes using the EXPLAIN statement.
    • Prevent SQL injection by utilizing parameterized queries or ORM abstractions (Frappe DB API) exclusively.