Convert Figma logo to code with AI

kasper logophoenix

A lightweight macOS window and app manager scriptable with JavaScript

4,361
128
4,361
48

Top Related Projects

21,321

Peace of mind from prototype to production

24,386

Elixir is a dynamic, functional language for building scalable and maintainable applications

The GraphQL toolkit for Elixir

6,132

A toolkit for data mapping and language integrated query.

2,230

Craft and deploy bulletproof embedded software in Elixir

2,858

Compose web applications with functions

Quick Overview

Phoenix is a web development framework written in Elixir. It implements the server-side MVC pattern and is designed to build scalable, real-time applications with high productivity and low latency.

Pros

  • Built-in support for real-time features with WebSockets
  • High performance and scalability due to Elixir's concurrent nature
  • Strong conventions and structure, promoting maintainable code
  • Excellent developer experience with live reloading and a powerful command-line interface

Cons

  • Steeper learning curve for developers unfamiliar with Elixir or functional programming
  • Smaller ecosystem compared to more established frameworks like Ruby on Rails or Django
  • Limited hosting options compared to more mainstream languages and frameworks
  • Potential overkill for simple, small-scale applications

Code Examples

Creating a new Phoenix project:

mix phx.new my_app
cd my_app
mix ecto.create
mix phx.server

Defining a route in lib/my_app_web/router.ex:

scope "/", MyAppWeb do
  pipe_through :browser

  get "/", PageController, :index
  get "/hello", HelloController, :index
end

Creating a controller in lib/my_app_web/controllers/hello_controller.ex:

defmodule MyAppWeb.HelloController do
  use MyAppWeb, :controller

  def index(conn, _params) do
    render(conn, "index.html")
  end
end

Getting Started

  1. Install Elixir and Phoenix:

    brew install elixir
    mix local.hex
    mix archive.install hex phx_new
    
  2. Create a new Phoenix project:

    mix phx.new my_app
    cd my_app
    
  3. Configure the database in config/dev.exs

  4. Create and migrate the database:

    mix ecto.create
    mix ecto.migrate
    
  5. Start the Phoenix server:

    mix phx.server
    
  6. Visit http://localhost:4000 in your browser to see the default Phoenix page.

Competitor Comparisons

21,321

Peace of mind from prototype to production

Pros of Phoenix

  • Significantly more active development and larger community support
  • Comprehensive documentation and extensive learning resources
  • Built-in features like channels for real-time communication and LiveView for interactive UIs

Cons of Phoenix

  • Steeper learning curve for developers new to Elixir or functional programming
  • Potentially overkill for small, simple projects
  • Less mature ecosystem compared to some other web frameworks

Code Comparison

Phoenix (phoenixframework/phoenix):

defmodule MyApp.Router do
  use MyApp, :router
  
  pipeline :browser do
    plug :accepts, ["html"]
    plug :fetch_session
    plug :fetch_flash
  end

Phoenix (kasper/phoenix):

class ApplicationController < ActionController::Base
  protect_from_forgery
  
  def current_user
    @current_user ||= User.find(session[:user_id]) if session[:user_id]
  end

The phoenixframework/phoenix repository is the official Phoenix web framework for Elixir, while kasper/phoenix appears to be a Ruby on Rails-based project. The code snippets reflect this fundamental difference, with the official Phoenix using Elixir syntax and the other using Ruby. The official Phoenix framework offers a more comprehensive and modern web development experience, particularly for Elixir developers, while the kasper/phoenix project may be more suitable for Ruby developers or specific use cases within the Ruby ecosystem.

24,386

Elixir is a dynamic, functional language for building scalable and maintainable applications

Pros of Elixir

  • Core language implementation with broader scope and applicability
  • More extensive standard library and built-in functionality
  • Larger community and ecosystem for general-purpose programming

Cons of Elixir

  • Steeper learning curve for beginners due to functional programming paradigm
  • Less focused on web development specifically compared to Phoenix
  • Requires additional frameworks or libraries for web-specific features

Code Comparison

Elixir (basic HTTP server):

defmodule SimpleServer do
  def start(port) do
    {:ok, socket} = :gen_tcp.listen(port, [:binary, packet: :line, active: false, reuseaddr: true])
    accept_loop(socket)
  end

  defp accept_loop(socket) do
    {:ok, client} = :gen_tcp.accept(socket)
    spawn(fn -> handle_client(client) end)
    accept_loop(socket)
  end
end

Phoenix (basic router):

defmodule MyApp.Router do
  use Phoenix.Router

  get "/", PageController, :index
  get "/users", UserController, :index
  post "/users", UserController, :create
end

The Elixir example shows a basic TCP server implementation, while the Phoenix example demonstrates a simple router configuration, highlighting the web-specific focus of Phoenix compared to the more general-purpose nature of Elixir.

The GraphQL toolkit for Elixir

Pros of Absinthe

  • Specialized for GraphQL: Absinthe is purpose-built for GraphQL APIs in Elixir, offering a more focused and optimized solution for GraphQL implementations.
  • Rich GraphQL features: Provides comprehensive support for GraphQL subscriptions, custom directives, and schema stitching out of the box.
  • Performance: Designed to handle complex GraphQL queries efficiently, leveraging Elixir's concurrency model.

Cons of Absinthe

  • Limited scope: Unlike Phoenix, Absinthe is not a full-featured web framework, focusing solely on GraphQL functionality.
  • Learning curve: Requires understanding of both GraphQL and Elixir concepts, which may be challenging for developers new to either technology.
  • Integration complexity: May require additional setup and configuration when integrating with other web frameworks or services.

Code Comparison

Absinthe (GraphQL schema definition):

defmodule MyAppWeb.Schema do
  use Absinthe.Schema

  query do
    field :hello, :string do
      resolve fn _, _, _ -> {:ok, "Hello, world!"} end
    end
  end
end

Phoenix (Router definition):

defmodule MyAppWeb.Router do
  use MyAppWeb, :router

  get "/", PageController, :index
end
6,132

A toolkit for data mapping and language integrated query.

Pros of Ecto

  • More focused on database interactions and ORM functionality
  • Offers greater flexibility in database schema design and migrations
  • Can be used independently of Phoenix for database operations in any Elixir project

Cons of Ecto

  • Steeper learning curve for beginners due to its more specialized nature
  • Requires additional setup and configuration when used outside of Phoenix
  • Less integrated with web-specific features compared to Phoenix's built-in functionality

Code Comparison

Ecto query example:

query = from u in User,
  where: u.age > 18,
  select: u.name

Repo.all(query)

Phoenix router example:

scope "/", MyApp do
  pipe_through :browser

  get "/", PageController, :index
  resources "/users", UserController
end

While Ecto focuses on database interactions, Phoenix provides a full-stack web framework that includes routing, controllers, and views. Ecto is often used within Phoenix applications but can also be used independently. Phoenix offers a more comprehensive solution for web development, while Ecto specializes in database operations and ORM functionality.

2,230

Craft and deploy bulletproof embedded software in Elixir

Pros of Nerves

  • Specialized for embedded systems and IoT devices
  • Provides a complete firmware creation and deployment ecosystem
  • Offers better hardware abstraction and cross-compilation support

Cons of Nerves

  • Steeper learning curve for developers not familiar with embedded systems
  • More limited in general-purpose web application development
  • Smaller community and ecosystem compared to Phoenix

Code Comparison

Nerves (creating a firmware project):

mix nerves.new my_project
cd my_project
export MIX_TARGET=rpi3
mix deps.get
mix firmware
mix firmware.burn

Phoenix (creating a web project):

mix phx.new my_app
cd my_app
mix deps.get
mix ecto.create
mix phx.server

Summary

Nerves is tailored for embedded systems and IoT applications, offering a comprehensive solution for firmware development and deployment. It excels in hardware abstraction and cross-compilation but has a steeper learning curve.

Phoenix, on the other hand, is a general-purpose web framework that's easier to get started with and has a larger ecosystem. It's better suited for traditional web applications but lacks the specialized features for embedded systems that Nerves provides.

The choice between Nerves and Phoenix depends on the specific project requirements, with Nerves being the go-to for embedded systems and Phoenix for web applications.

2,858

Compose web applications with functions

Pros of Plug

  • Lightweight and modular, allowing for more flexibility in building web applications
  • Faster performance for simpler applications due to less overhead
  • Easier to understand and implement for developers new to Elixir web development

Cons of Plug

  • Less feature-rich compared to Phoenix, requiring more manual setup for complex applications
  • Smaller ecosystem and community support
  • Lacks built-in generators and conveniences provided by Phoenix

Code Comparison

Phoenix:

defmodule MyApp.Router do
  use MyApp.Web, :router

  pipeline :browser do
    plug :accepts, ["html"]
    plug :fetch_session
    plug :fetch_flash
    plug :protect_from_forgery
    plug :put_secure_browser_headers
  end

  scope "/", MyApp do
    pipe_through :browser
    get "/", PageController, :index
  end
end

Plug:

defmodule MyApp.Router do
  use Plug.Router

  plug :match
  plug :dispatch

  get "/" do
    send_resp(conn, 200, "Welcome")
  end

  match _ do
    send_resp(conn, 404, "Not Found")
  end
end

The code comparison shows that Phoenix provides a more structured and feature-rich routing system out of the box, while Plug offers a simpler and more direct approach to handling requests. Phoenix includes built-in pipelines and scopes, whereas Plug requires manual setup for similar functionality.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Phoenix

Build Status

Phoenix

A lightweight macOS window and app manager scriptable with JavaScript. You can also easily use languages which compile to JavaScript such as TypeScript. Phoenix aims for efficiency and a very small footprint. If you like the idea of scripting your own window or app management toolkit with JavaScript, Phoenix is probably going to give you the things you want. With Phoenix you can bind keyboard shortcuts and system events, and use these to interact with macOS.

  • Current version: 4.0.1 (Changelog)
  • Requires: macOS 10.14 or higher

Note: the default master branch will always be stable.

Key Features

  • highly customisable, write your own configuration
  • bind keyboard shortcuts and system events to your callback functions
  • control and interact with your screens, spaces, mouse, apps and windows
  • log messages, deliver notifications, display content or ask input with modals
  • run external commands like you would in the command line

Install

To install, extract the downloaded archive and just drag-and-drop Phoenix to your Applications folder. When you run Phoenix for the first time, you will be asked to allow it to control your UI. macOS will ask you to open Privacy & Security in System Settings. Once open, go to the Accessibility section and enable with the toggle next to Phoenix. An admin account is required to accomplish this.

Alternatively, if you have Homebrew installed, you can simply run brew install --cask phoenix.

Uninstall

To uninstall Phoenix, delete the app from your Applications folder. The configuration file created by Phoenix itself is located in your home folder. Delete ~/.phoenix.js and any related configurations if desired. For developers, you may also need to delete ~/.phoenix.debug.js.

Application preferences are stored in ~/Library/Preferences/org.khirviko.Phoenix.plist. For developers, in ~/Library/Preferences/org.khirviko.Phoenix.debug.plist.

If you have used the storage, also delete the file ~/Library/Application Support/Phoenix/storage.json. Again for developers, you may also need to delete ~/Library/Application Support/Phoenix/storage.debug.json.

For uninstalling additional support files, see the following folders:

~/Library/Application Scripts/org.khirviko.Phoenix.Launcher
~/Library/Caches/org.khirviko.Phoenix
~/Library/Containers/org.khirviko.Phoenix.Launcher
~/Library/HTTPStorages/org.khirviko.Phoenix
~/Library/WebKit/org.khirviko.Phoenix

# For developers
~/Library/Application Scripts/org.khirviko.Phoenix.Launcher.debug
~/Library/Caches/org.khirviko.Phoenix.debug
~/Library/Containers/org.khirviko.Phoenix.Launcher.debug
~/Library/HTTPStorages/org.khirviko.Phoenix.debug
~/Library/WebKit/org.khirviko.Phoenix.debug

Usage

Phoenix lives on your status bar (or as a background daemon) and can be scripted in JavaScript (or languages which compile to JavaScript such as TypeScript).

Screenshot of Phoenix

See the documentation to get started with your script. Your script should reside in ~/.phoenix.js — the file will be created when you launch Phoenix for the first time. Alternatively — if you prefer — you may also have your script in ~/Library/Application Support/Phoenix/phoenix.js or ~/.config/phoenix/phoenix.js. For ideas, see what other people have built in their configurations in the Wiki. Feel free to add your own configuration to the Wiki to show other people the nice things you can do. Previous configurations (<= 1.5) are not compatible with 2.0, see Changelog for what changes are needed.

Development

You will need some basic knowledge about installing the required languages and tools. If you need help, do not hesitate to ask! To get started, you will need:

  1. Git
  2. Xcode 15 or higher
  3. Xcode command line tools

First clone the repository from a terminal:

git clone https://github.com/kasper/phoenix.git
cd phoenix

To develop Phoenix, open Phoenix.xcworkspace in Xcode. Install Xcode from the App Store, if you do not already have it installed. You will also need Xcode command line tools — you will be prompted for this. Everything else should work as is — you can develop, debug, test, build and run Phoenix straight from Xcode.

For code formatting, Phoenix uses ClangFormat. You will need to have it in your path to be able to make sure any code changes align with the formatting rules. If you do not have ClangFormat installed, the build process will simply skip linting.

To install Phoenix from the source, you will need to build the workspace from a terminal:

xcodebuild -workspace Phoenix.xcworkspace \
           -scheme Phoenix \
           -configuration Release \
           SYMROOT="$PWD/build/" \
           clean build

Once complete, you will find a newly built Phoenix app in build/Release/. After this, you can follow the normal install guide.

For a debug build, change the -configuration flag to Debug in the above command. This will place a debug build of the app in build/Debug.

Phoenix manages dependencies with CocoaPods. Note that you do not need CocoaPods for basic development. However, if you want to install new pods or update existing ones, you will also need:

  1. Ruby (3.3.3 or higher), it is recommended that you manage Ruby versions with for instance rbenv
  2. Bundler
  3. CocoaPods

Install Bundler, if you do not already have it installed. To install CocoaPods and its dependencies, use Bundler inside the phoenix directory to install the required Ruby gems according to the Gemfile. Once complete, you can install the pods listed in the Podfile with CocoaPods.

gem install bundler
bundle install
pod install

In addition to the Objective-C core, Phoenix also uses a JavaScript-based (5.1) library to implement additional features to the API. The minified library is included in the repository in Phoenix/phoenix-min.js so that everything works as is. However, if you want to develop features for this library, you will also need:

  1. Node.js (22.2.0 or higher), it is recommended that you manage Node.js versions with for instance NVM

Install the development packages listed in package.json.

npm install

To build phoenix-min.js from the source, run the command npm run build in the root directory. NPM will then build the source from library/src/ and install the new library to Phoenix/phoenix-min.js. For convenience, this is also handled automatically by Xcode when you build Phoenix.

Documentation

The documentation for Phoenix is built from the docs/ directory using Docusaurus. To develop the documentation locally, navigate to the directory and run the following:

npm install
npm start

Contributing

Feel free to contribute to this project by creating issues, pull requests and editing the Wiki. See the guidelines.

Contact

If you have any questions, feedback or just want to say hi, you can open an issue, start a discussion, email or message on Threads.

Thanks

Phoenix is currently being developed by Kasper Hirvikoski (@kasper) with the generous help of contributions made by many individuals. It was originally authored by Steven Degutis (@sdegutis). As it stands now, it has been rewritten from the ground up by Kasper Hirvikoski.

License

Released under the MIT License. See license.