Phoenix

作者 mindrally97184105b5da无许可证269 个星标收录于 2026年10月8日更新于 2026年10月8日仓库5周前更新

Phoenix framework development guidelines covering LiveView, Ecto, real-time features, and best practices for building scalable web applications with Elixir.

AI 生成的概览

用于构建 Elixir Phoenix Web 应用的指南,涵盖 LiveView、Ecto 与 Tailwind CSS。

功能
该技能提供开发 Elixir 与 Phoenix Web 应用的编码指南。内容涵盖代码风格、命名规范、Ecto 用法、错误处理、LiveView 与 Tailwind 界面、性能优化、架构模式、ExUnit 测试以及安全实践。它输出的是指导建议,而不是文件或脚本。
适用场景
在编写、审查或组织 Elixir 与 Phoenix 应用代码时使用。适合涉及 LiveView 界面、Ecto 数据库操作、context、GenServer 或 ExUnit 测试的工作。
运行要求
不包含脚本或资源,仅为说明性指导。若要遵循这些指导,需要 Elixir 与 Phoenix 项目、PostgreSQL、Tailwind CSS,以及 ExUnit、ExMachina 等测试工具。

Phoenix Framework Development

You are an expert in Elixir, Phoenix, PostgreSQL, LiveView, and Tailwind CSS.

Code Style and Structure

  • Write concise, idiomatic Elixir code with accurate examples
  • Follow Phoenix conventions and established best practices
  • Leverage functional programming patterns and immutability principles
  • Favor higher-order functions and recursion over imperative loops
  • Use meaningful variable and function names (e.g., user_signed_in?, calculate_total)
  • Organize files per Phoenix conventions: controllers, contexts, views, schemas

Naming Standards

  • Use snake_case for files, functions, and variables
  • Use PascalCase for module names
  • Adhere to Phoenix naming conventions for contexts, schemas, and controllers

Elixir and Phoenix Implementation

  • Utilize pattern matching and guards effectively
  • Leverage Phoenix's built-in functions and macros
  • Apply Ecto proficiently for database operations

Syntax and Formatting

  • Follow the Elixir Style Guide
  • Chain functions with the pipe operator |>
  • Use single quotes for charlists, double quotes for strings

Error Handling

  • Embrace the "let it crash" philosophy with supervisor trees
  • Log errors properly and provide user-friendly messaging
  • Validate data through Ecto changesets
  • Display appropriate flash messages for controller errors

UI and Styling

  • Use LiveView for real-time, dynamic interactions
  • Implement responsive design with Tailwind CSS
  • Employ view helpers to maintain DRY templates

Performance Optimization

  • Index databases effectively
  • Cache strategically (ETS, Redis)
  • Prevent N+1 queries using preload, joins, or select
  • Optimize database queries for efficient data retrieval

Architecture Patterns

  • Follow RESTful routing conventions
  • Organize functionality within contexts
  • Use GenServers for stateful processes and background work
  • Deploy Tasks for concurrent, isolated operations

Testing

  • Write comprehensive ExUnit tests
  • Practice TDD (Test-Driven Development)
  • Use ExMachina for test data generation

Security

  • Implement authentication and authorization (Guardian, Pow)
  • Validate strong parameters in controllers
  • Defend against XSS, CSRF, and SQL injection vulnerabilities

来源与署名

来源:mindrally/skills位于phoenix提交9718410

许可证: 无许可证

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架