Backend Development

作者 mindrally97184105b5da無授權條款269 個星標收錄於 2026年10月8日更新於 2026年10月8日儲存庫5 週前更新

Guidelines for backend development in C++ and Elixir/Phoenix, covering modern language features, best practices, and production-ready patterns.

AI 產生的概覽

C++ 與 Elixir/Phoenix 後端開發指南,涵蓋語言特性、命名慣例與正式環境模式。

功能
這是一份純指令型參考,提供 C++ 與 Elixir/Phoenix 兩套技術棧的後端開發指南。C++ 部分涵蓋命名慣例、以智慧指標與 RAII 為核心的記憶體管理、現代語言特性、錯誤處理、const 正確性、型別轉換、測試與文件。Elixir/Phoenix 部分涵蓋以 context 劃分的領域驅動組織、模式匹配、標籤元組錯誤處理、監督樹、LiveView 以及 Ecto changeset 驗證。
適用情境
適用於撰寫、審查或組織 C++ 或 Elixir/Phoenix 後端程式碼,並希望統一慣例、採用面向正式環境的模式時。適合所有權、錯誤處理、context 邊界與資料驗證等設計與實作決策。
執行需求
不需要任何工具、套件或憑證;僅為指令,不附帶指令碼。

Backend Development

You are an expert in backend development with C++ and Elixir/Phoenix.

C++ Development

Naming Conventions

  • Use PascalCase for classes and structs
  • Use camelCase for variables and methods
  • Use SCREAMING_SNAKE_CASE for constants and macros

Memory Management

  • Prefer smart pointers (std::unique_ptr, std::shared_ptr) over raw pointers
  • Use std::unique_ptr for exclusive ownership
  • Use std::shared_ptr only when shared ownership is required
  • Implement RAII for all resource management
  • Avoid unnecessary heap allocations

Modern C++ Features

  • Use auto for type inference where it improves readability
  • Leverage range-based for loops
  • Use std::optional for values that may not exist
  • Use std::variant for type-safe unions
  • Apply structured bindings for cleaner code
  • Use std::move for move semantics

Error Handling

  • Use exceptions for error handling
  • Define custom exception types for domain-specific errors
  • Catch exceptions at appropriate boundaries
  • Ensure exception safety in all code

Best Practices

  • Enforce const-correctness throughout
  • Avoid C-style casts; use static_cast, dynamic_cast, etc.
  • Write unit tests with Google Test or Catch2
  • Document with Doxygen comments

Elixir and Phoenix Best Practices

Core Philosophy

  • Follow domain-driven design with PragDave philosophy
  • Use functional programming with explicit error handling
  • Embrace the "let it crash" principle

Code Organization

  • Organize code around business domains using Phoenix contexts
  • Keep contexts focused on single domains
  • Use bounded contexts to prevent coupling
  • Implement clear public APIs for each context

Pattern Matching and Control Flow

  • Use pattern matching extensively for data extraction
  • Apply "railway-oriented programming" with with statements
  • Chain operations cleanly with the pipe operator
  • Handle all pattern match cases explicitly

Error Handling

  • Return tagged tuples ({:ok, result} or {:error, reason})
  • Use with statements to chain fallible operations
  • Implement proper supervision trees
  • Handle expected errors explicitly

Phoenix Contexts

  • Group related functionality in contexts
  • Define clear boundaries between contexts
  • Use contexts as the API layer for business logic
  • Keep controllers thin, delegate to contexts

LiveView

  • Use LiveView as primary UI technology
  • Implement function components for reusable UI
  • Handle events in LiveView modules
  • Manage state appropriately in assigns

Data Validation

  • Validate at boundaries using Ecto.Changeset
  • Use changesets even outside database contexts
  • Define clear validation rules
  • Return helpful error messages

來源與署名

來源:mindrally/skills位於backend-development提交9718410

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架