How arizona-framework/arizona works
Based on our analysis, Arizona is a web framework for Erlang. It provides a full-stack solution to serve dynamic HTML (with dynamic Erlang code embedded) via views, templates, and layouts, while also handling client interactions (e.g., via WebSocket and HTTP routes) and serving static assets. The project structure indicates that it is not only the framework itself (with many Erlang modules in the src folder, test suites, and configuration files) but also an example application (with assets, client-side JS, and specific view/component modules) that shows how to use the framework.
Main components
– arizona_config, arizona_diff, arizona_parser, arizona_renderer, etc.
– View and layout modules (e.g., arizona_view, arizona_layout, arizona_view_handler) indicate a rendering mechanism for HTML templates.
– Specialized modules to handle static assets, JavaScript communication (arizona_js), and WebSocket (arizona_websocket).
• Template Engine & Templating System:
– Shows how HTML-level templates include embedded Erlang code (using curly braces). This is central to how the framework dynamically constructs views.
• Web Server & HTTP Routes:
– Arizona integrates with Cowboy for HTTP serving. In the generated config (sys.config) routes are defined:
• Static file routes for assets, such as “/assets/[...]” served as static content.
• Dynamic routes – for views via arizona_view_handler.
• WebSocket & Real-time Updates:
– Interaction letting client events (e.g., button click) to be handled in modules like arizona_example_counter and arizona:handle_event/4.
– Use of morphdom for efficient DOM patching is a key runtime process.
• Client-side Assets and JS:
– The assets folder (and its subdirectories in both assets and priv/static) contains JavaScript modules that include connection initialization (arizona.connect()) and patches for dynamic behaviors.
• Build and Development Infrastructure:
– Files like rebar.config, rebar.lock, and various configuration files (esbuild, babel, eslint, prettier) show the integration of build tools ensuring the project is maintainable and standards-compliant.
• Testing Infrastructure:
– Test suites written in Erlang (in test/) to validate view logic, parsing, rendering, etc.
Relationships and Interactions
– A client HTTP request hitting a Cowboy route (defined in the sys.config) which dispatches the request to a specific view handler.
– The view handler processing the request using Arizona’s rendering modules, eventually producing rendered HTML (using the layout and view templates).
– If dynamic interactions occur (e.g., a button triggers an event), the client JavaScript sends a WebSocket event to modules like arizona_example_counter, which in turn trigger arizona:handle_event/4 to update state and produce a small payload that is sent back to the client.
• An additional pathway shows how static assets (such as JS files) are served by the server from the priv/ directory.
Architectural Patterns and Design Principles
• MVC-like Separation of Concerns:
– Although not explicitly labeled MVC, the separation between view templates, layout files, and the business logic (in the Erlang backend) mimics that pattern.
• Component-Based Rendering:
– Modules like arizona_example_components show a component setup where small reusable UI elements (in this case, a button) are defined and dynamically embedded.
• Event-driven and Real-time Data Flow:
– Use of WebSocket and event-driven functions (handle_event/4 in various modules) emphasize reactive design.
• Development Pipelines and Automation:
– GitHub workflows and build configurations (e.g., esbuild, babel, eslint, rebar) indicate standard CI/CD practices.
Relevant Technologies, Frameworks, or Libraries
• Erlang for back-end processing.
• rebar/rebar3 as build/dependency management tools.
• Cowboy as the HTTP/WebSocket server.
• morphdom (via included JS library) for efficient DOM patching.
• JavaScript modules (ESM) for client-side behavior and asset management.
• Config files (e.g., babel, eslint, prettier) indicate adherence to modern JavaScript development practices.