This repository was archived by the owner on Jun 23, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathphoenix.mdc
More file actions
39 lines (32 loc) · 1.95 KB
/
phoenix.mdc
File metadata and controls
39 lines (32 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
---
description: Use when working with Phoenix framework, LiveView, contexts, schemas, generators, PubSub, or database operations
globs:
alwaysApply: false
---
# Phoenix Framework Development Guide
## Generators and Resources
- When creating new resources (schemas, contexts, LiveViews) use Phoenix generators (`mix phx.gen.*`; e.g. `mix phx.gen.context`).
- To see all available generators, run `mix help`.
- To see all available generator options, run `mix help phx.gen.*` (e.g. `mix help phx.gen.context`).
## Code Organization
- When referring to schemas from other contexts, alias the context (e.g. `alias MyApp.Accounts`) and prefix the schema name with context (e.g. `Accounts.User`).
- Sort component attributes alphabetically.
## PubSub and Real-time Features
- When working with PubSub, we can use `Endpoint.broadcast/3` and `Endpoint.subscribe/2`.
## Database and Testing
- Run `MIX_ENV=test mix ecto.drop` when trying to reset the test database.
- There is no need to run `mix ecto.create` and `mix ecto.migrate` for test database because `mix test` does it automatically.
- Components and live components are tested through the parent LiveViews, not in isolation.
## LiveView Development
- Event names should be snake cased.
- After each code change, the LiveView page reloads automatically, letting you inspect runtime logs and catch errors.
- Sort component attributes alphabetically.
## Server
- Assume the server is running.
- Don't assume the port is 4000. Get the correct port from Endpoint configuration.
- Don't restart the server - it support hot reloading.
- Only after updating config files, adding/updating Oban workers, or any GenServer/Supervisor, you need to restart the server.
## Configuration
- Use Tidewave MCP tools to get access the runtime configuration as it's different from what's in dev.exs.
- Use `Application.get_env(:app_name, Module)` to access runtime configuration.
- To inspect current configuration: `Application.get_all_env(:app_name)`.