@@ -10,21 +10,35 @@ This is Phoenix.SessionProcess, an Elixir library that creates a process for eac
1010
1111### Development Commands
1212- ` mix deps.get ` - Install dependencies
13+ - ` mix compile ` - Compile the project
14+ - ` mix compile --warnings-as-errors ` - Compile with strict warnings (CI requirement)
1315- ` mix test ` - Run all tests
1416- ` mix test test/path/to/specific_test.exs ` - Run a specific test file
15- - ` mix compile ` - Compile the project
16- - ` mix docs ` - Generate documentation
17+ - ` mix test test/phoenix/session_process/ ` - Run all tests in a directory
1718- ` mix format ` - Format code
19+ - ` mix format --check-formatted ` - Check formatting without modifying files (CI requirement)
20+ - ` mix credo --strict ` - Run static code analysis with strict mode (CI requirement)
21+ - ` mix dialyzer ` - Run type checking (first run builds PLT cache)
22+ - ` mix dialyzer --halt-exit-status ` - Run type checking and exit with error code on issues (CI requirement)
23+ - ` mix lint ` - Run both Credo and Dialyzer (defined in mix.exs aliases)
24+ - ` mix docs ` - Generate documentation
1825- ` mix hex.publish ` - Publish to Hex.pm (requires authentication)
1926
27+ ### Code Quality Requirements
28+ Before committing, ensure code passes all CI checks:
29+ 1 . Compiles without warnings: ` mix compile --warnings-as-errors `
30+ 2 . Properly formatted: ` mix format --check-formatted `
31+ 3 . Passes Credo: ` mix credo --strict `
32+ 4 . Passes Dialyzer: ` mix dialyzer --halt-exit-status `
33+
2034### Testing
21- The test suite uses ExUnit. Tests are located in the ` test/ ` directory. The test helper (test/test_helper.exs:3) automatically starts the supervisor.
35+ The test suite uses ExUnit. Tests are located in the ` test/ ` directory. The test helper (test/test_helper.exs:3) automatically starts the supervisor and configures the default TestProcess module .
2236
2337### Development Environment
24- The project uses ` devenv ` for development environment setup with Nix. Key configuration:
25- - Uses Elixir/BEAM 27
26- - Runs ` hello ` script on shell entry for greeting
38+ The project uses ` devenv ` for development environment setup with Nix:
39+ - Elixir 1.18+ with OTP 28+ (minimum: Elixir 1.14, OTP 24)
2740- Includes git, figlet, and lolcat tools
41+ - Run ` devenv shell ` to enter the development environment
2842
2943### Benchmarking
3044Performance testing available via:
@@ -38,37 +52,76 @@ Expected performance:
3852
3953## Architecture
4054
55+ ### Module Organization
56+
57+ The library is organized into several logical groups:
58+
59+ ** Core API** (primary interface for users):
60+ - ` Phoenix.SessionProcess ` - Main public API
61+ - ` Phoenix.SessionProcess.SessionId ` - Plug for session ID generation
62+
63+ ** Internals** (supervision and lifecycle management):
64+ - ` Phoenix.SessionProcess.Supervisor ` - Top-level supervisor (Note: filename is ` superviser.ex ` )
65+ - ` Phoenix.SessionProcess.ProcessSupervisor ` - Dynamic supervisor for sessions (Note: filename is ` process_superviser.ex ` )
66+ - ` Phoenix.SessionProcess.Cleanup ` - TTL-based cleanup
67+ - ` Phoenix.SessionProcess.DefaultSessionProcess ` - Default session implementation
68+
69+ ** State Management Utilities** :
70+ - ` Phoenix.SessionProcess.Redux ` - Optional Redux-style state with actions/reducers, subscriptions, and selectors (advanced use cases)
71+ - ` Phoenix.SessionProcess.Redux.Selector ` - Memoized selectors for efficient derived state
72+ - ` Phoenix.SessionProcess.Redux.Subscription ` - Subscription management for reactive state changes
73+ - ` Phoenix.SessionProcess.Redux.LiveView ` - LiveView integration helpers
74+ - ` Phoenix.SessionProcess.MigrationExamples ` - Migration examples for Redux
75+ - ` Phoenix.SessionProcess.ReduxExamples ` - Comprehensive Redux usage examples
76+
77+ ** Configuration & Error Handling** :
78+ - ` Phoenix.SessionProcess.Config ` - Configuration management
79+ - ` Phoenix.SessionProcess.Error ` - Error types and messages
80+
81+ ** Observability** :
82+ - ` Phoenix.SessionProcess.Telemetry ` - Telemetry event emission
83+ - ` Phoenix.SessionProcess.TelemetryLogger ` - Logging integration
84+ - ` Phoenix.SessionProcess.Helpers ` - General utilities
85+
4186### Core Components
4287
43881 . ** Phoenix.SessionProcess** (lib/phoenix/session_process.ex:1)
4489 - Main module providing the public API
4590 - Delegates to ProcessSupervisor for actual process management
4691 - Provides two macros: ` :process ` (basic) and ` :process_link ` (with LiveView monitoring)
92+ - Key functions: ` start/1-3 ` , ` call/2-3 ` , ` cast/2 ` , ` terminate/1 ` , ` started?/1 ` , ` list_session/0 `
4793
48942 . ** Phoenix.SessionProcess.Supervisor** (lib/phoenix/session_process/superviser.ex:1)
4995 - Top-level supervisor that manages the Registry, ProcessSupervisor, and Cleanup
5096 - Must be added to the application's supervision tree
97+ - Supervises: Registry, ProcessSupervisor, and Cleanup GenServer
5198
52993 . ** Phoenix.SessionProcess.ProcessSupervisor** (lib/phoenix/session_process/process_superviser.ex:1)
53100 - DynamicSupervisor that manages individual session processes
54101 - Handles starting, terminating, and communicating with session processes
55- - Performs session validation and limit checks
102+ - Performs session validation and limit checks (max sessions, rate limiting)
103+ - Emits telemetry events for all operations
56104
571054 . ** Phoenix.SessionProcess.SessionId** (lib/phoenix/session_process/session_id.ex)
58106 - Plug that generates unique session IDs
59- - Must be placed after ` :fetch_session ` plug
107+ - Must be placed after ` :fetch_session ` plug in router pipeline
108+ - Assigns session_id to conn.assigns for use in controllers/LiveViews
60109
611105 . ** Phoenix.SessionProcess.Cleanup** (lib/phoenix/session_process/cleanup.ex:1)
62- - Automatic TTL-based session cleanup
111+ - GenServer for automatic TTL-based session cleanup
63112 - Schedules session expiration on creation
113+ - Runs cleanup tasks periodically
64114
651156 . ** Phoenix.SessionProcess.Redux** (lib/phoenix/session_process/redux.ex:1)
66- - Redux-style state management with actions and reducers
116+ - Optional Redux-style state management with actions, reducers, subscriptions, and selectors
67117 - Provides time-travel debugging, middleware support, and action history
68-
69- 7 . ** Phoenix.SessionProcess.State** (lib/phoenix/session_process/state.ex:1)
70- - Agent-based state storage with Redux-style dispatch support
71- - Used for simpler state management scenarios
118+ - ** Redux.Selector** : Memoized selectors with reselect-style composition for efficient derived state
119+ - ** Redux.Subscription** : Subscribe to state changes with optional selectors (only notifies when selected values change)
120+ - ** Redux.LiveView** : Helper module for LiveView integration with automatic assign updates
121+ - ** Phoenix.PubSub integration** : Broadcast state changes across nodes for distributed applications
122+ - ** Comprehensive telemetry** : Monitor Redux operations (dispatch, subscribe, selector cache hits/misses, PubSub broadcasts)
123+ - Best for complex applications requiring reactive UIs, predictable state updates, audit trails, or distributed state
124+ - Note: Most applications don't need this - standard GenServer state is sufficient
72125
73126### Process Management Flow
74127
@@ -118,11 +171,16 @@ Configuration options:
118171
119172## State Management Options
120173
121- The library provides three state management approaches:
174+ The library provides two state management approaches:
175+
176+ 1 . ** Standard GenServer State** (Recommended) - Full control with standard GenServer callbacks
177+ - Use ` handle_call ` , ` handle_cast ` , and ` handle_info ` to manage state
178+ - Simple, idiomatic Elixir - this is what you should use for 95% of cases
122179
123- 1 . ** Basic GenServer** - Full control with standard GenServer callbacks
124- 2 . ** Phoenix.SessionProcess.State** - Agent-based with simple get/put and Redux dispatch
125- 3 . ** Phoenix.SessionProcess.Redux** - Full Redux pattern with actions, reducers, middleware, time-travel debugging
180+ 2 . ** Phoenix.SessionProcess.Redux** (Optional, Advanced) - Redux pattern for complex state machines
181+ - Actions, reducers, middleware, time-travel debugging
182+ - Only use if you need audit trails or complex state machine logic
183+ - Adds complexity - most applications don't need this
126184
127185## Telemetry and Error Handling
128186
0 commit comments