MI

Mix

testing vBuilt-in

Mix

Version: Built-in

Overview

Mix is Elixir's built-in build tool and the command-line interface through which all Prismatic Platform development operations are executed. It handles project compilation, dependency management, test execution, release building, and custom task execution -- serving as the unified entry point for the platform's entire development workflow. Every developer interaction with the platform starts with a mix command, making it the most frequently used tool in the development process.

The Prismatic Platform extends Mix with dozens of custom tasks that power its quality enforcement, evolution, and operational systems: mix quality.gates, mix autoheal.cycle, mix autoevolve.mega, mix git_trees, mix promo.enhance, and many more. These custom tasks integrate deeply with the platform's NO MERCY quality doctrine, blocking operations that would degrade code quality. The custom task library represents a significant investment in tooling -- each task enforces a specific aspect of the platform's quality standards.

Mix's umbrella project support is essential for the platform's 90-application architecture, managing inter-application dependencies, coordinated compilation, and unified test execution across the entire umbrella. A single mix test command runs tests across all 90 applications, and mix compile --warnings-as-errors ensures zero compilation warnings across the entire codebase.

Key Features

  • Dependency Management: Hex package resolution with lock file and dependency tree visualization
  • Compilation: Incremental compilation with dependency tracking, detecting when only affected modules need recompilation
  • Testing: Parallel test execution with coverage reporting, tag-based filtering, and failure tracing
  • Release Building: Production release assembly with runtime configuration and boot scripts
  • Custom Tasks: Extensible task system for project-specific workflows with argument parsing and documentation
  • Umbrella Projects: Multi-application project management with dependency ordering and selective compilation
  • Aliases: Command composition for frequently used multi-step workflows
  • Environment Separation: dev, test, and prod environments with independent configurations

Platform Integration

Mix custom tasks power the platform's quality and evolution systems. The following example shows the quality gates task that enforces the NO MERCY doctrine.

defmodule Mix.Tasks.Quality.Gates do
  @moduledoc """
  Run all quality gates: compilation, formatting, Credo, Dialyzer, and tests.
  Fails immediately if any gate does not pass.
  """
  use Mix.Task

  @shortdoc "Run all quality gates"
  def run(_args) do
    gates = [
      {"Compilation", fn -> Mix.Task.run("compile", ["--warnings-as-errors", "--force"]) end},
      {"Formatting", fn -> Mix.Task.run("format", ["--check-formatted"]) end},
      {"Credo", fn -> Mix.Task.run("credo", ["--strict"]) end},
      {"Dialyzer", fn -> Mix.Task.run("dialyzer") end},
      {"Tests", fn -> Mix.Task.run("test", ["--cover"]) end}
    ]

    results = Enum.map(gates, fn {name, gate_fn} ->
      Mix.shell().info("Running #{name}...")
      try do
        gate_fn.()
        {name, :passed}
      rescue
        _ -> {name, :failed}
      end
    end)

    failed = Enum.filter(results, fn {_, status} -> status == :failed end)

    if failed != [] do
      failed_names = Enum.map(failed, &elem(&1, 0))
      Mix.raise("Quality gates failed: #{Enum.join(failed_names, ", ")}")
    else
      Mix.shell().info("All quality gates passed.")
    end
  end
end

Architecture

Mix serves as the orchestration layer for all development operations, invoking Elixir compiler, test runner, and custom tasks.

Mix ComponentRolePlatform Usage
CompilerIncremental compilation with dependency trackingmix compile --warnings-as-errors
Dependency ManagerHex package resolution and fetchingmix deps.get, mix deps.update
Test RunnerParallel execution with coveragemix test --cover
Release BuilderProduction binary creationmix release
Task SystemCustom task executionmix quality.gates, mix git_trees
Umbrella ManagerMulti-app coordinationmix cmd --app prismatic_web mix test
Alias SystemWorkflow compositionmix setup, mix quality

The custom task library is organized by domain within the platform's codebase.

Task CategoryLocationKey Tasks
Qualityapps/prismatic/lib/mix/tasks/quality/quality.gates, quality.enforce_standard
Evolutionapps/prismatic/lib/mix/tasks/autoheal.cycle, autoevolve.mega
Codebaseapps/prismatic/lib/mix/tasks/git_trees, git_trees.find
Promoapps/prismatic/lib/mix/tasks/promo.enhance
Supervisorapps/prismatic_supervisor/lib/mix/tasks/supervisor, supervisor.discover
APIapps/prismatic_api/lib/mix/tasks/API endpoint scanning

Custom Task Catalog

The platform's custom Mix tasks represent the programmatic interface to its quality and operational systems.

TaskPurposeUsage
mix quality.gatesRun all quality gatesmix quality.gates
mix quality.enforce_standardCheck app compliancemix quality.enforce_standard --fix
mix quality.standardize_mixStandardize mix.exs filesmix quality.standardize_mix --apply
mix autoheal.baselineEstablish quality baselinemix autoheal.baseline
mix autoheal.cycleRun healing cyclemix autoheal.cycle
mix autoevolve.megaFull evolution sweepmix autoevolve.mega
mix autoevolve statusEvolution statusmix autoevolve status --brief
mix git_treesRepository statisticsmix git_trees
mix git_trees findFind files by patternmix git_trees find "\.ex$"
mix git_trees appsList apps with countsmix git_trees apps
mix promo.enhanceEnhance promo contentmix promo.enhance --section agents
mix supervisorSupervisor statusmix supervisor
mix supervisor.discoverAuto-discover appsmix supervisor.discover

Performance Characteristics

Mix compilation and task execution performance directly impacts development velocity.

OperationTimeNotes
Clean compilation (full)~120sAll 90 apps from scratch
Incremental compilation~5-15sTypical change in 1-3 modules
mix test (full suite)~180sAll tests across umbrella
mix test (single app)~10-30sTargeted app testing
mix credo --strict~30sFull codebase analysis
mix dialyzer (cached PLT)~120sWith pre-built PLT
mix dialyzer (fresh PLT)~600sFirst run, building PLT
mix format --check-formatted~10sFull codebase format check
mix deps.get~15sDependency resolution
mix quality.gates (full)~480sAll gates sequential

The platform uses Mix's incremental compilation to keep the development feedback loop under 15 seconds for typical changes. Only modules whose source files or dependencies have changed are recompiled.

Configuration

The root mix.exs configures the umbrella project with shared settings, aliases, and dependencies.

# mix.exs - Umbrella root configuration
defmodule Prismatic.MixProject do
  use Mix.Project

  def project do
    [
      apps_path: "apps",
      version: "7.5.0",
      start_permanent: Mix.env() == :prod,
      deps: deps(),
      aliases: aliases(),
      preferred_cli_env: [
        "quality.gates": :test,
        "test": :test,
        dialyzer: :dev
      ],
      dialyzer: [
        plt_file: {:no_warn, "priv/plts/dialyzer.plt"},
        plt_add_apps: [:mix, :ex_unit]
      ]
    ]
  end

  defp aliases do
    [
      setup: ["deps.get", "ecto.setup"],
      "ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
      "ecto.reset": ["ecto.drop", "ecto.setup"],
      test: ["ecto.create --quiet", "ecto.migrate --quiet", "test"],
      quality: ["compile --warnings-as-errors", "format --check-formatted",
                "credo --strict", "test --cover"]
    ]
  end

  defp deps do
    [
      {:credo, "~> 1.7", only: [:dev, :test], runtime: false},
      {:dialyxir, "~> 1.4", only: [:dev], runtime: false},
      {:ex_doc, "~> 0.31", only: :dev, runtime: false}
    ]
  end
end

Individual app mix.exs files follow a standardized format enforced by mix quality.standardize_mix.

# Standard app mix.exs (enforced by quality.standardize_mix)
defmodule PrismaticPerimeter.MixProject do
  use Mix.Project

  def project do
    [
      app: :prismatic_perimeter,
      version: "0.1.0",
      build_path: "../../_build",
      config_path: "../../config/config.exs",
      deps_path: "../../deps",
      lockfile: "../../mix.lock",
      elixir: "~> 1.19",
      elixirc_paths: elixirc_paths(Mix.env()),
      start_permanent: Mix.env() == :prod,
      deps: deps(),
      test_coverage: [threshold: 80],
      dialyzer: [plt_add_apps: [:mix]]
    ]
  end

  defp elixirc_paths(:test), do: ["lib", "test/support"]
  defp elixirc_paths(_), do: ["lib"]
end

Best Practices

  • Use aliases for common workflows -- define mix quality and mix setup aliases to standardize multi-step operations
  • Set preferred_cli_env -- ensure tasks run in the correct environment; quality.gates and test should default to :test
  • Write custom tasks with @shortdoc -- the @shortdoc attribute makes tasks visible in mix help output
  • Use --warnings-as-errors on compilation -- this is mandatory in the platform; any compilation warning is a blocking error
  • Run mix dialyzer with cached PLT -- cache the PLT file to avoid rebuilding on every run; the platform stores PLTs in priv/plts/
  • Test individual apps during development -- use mix cmd --app <app_name> mix test to run tests for a single app instead of the full suite
  • Keep mix.exs standardized -- run mix quality.standardize_mix --apply to ensure all 90 app configurations follow the platform standard
  • Never run mix in production -- use compiled releases (mix release) for production deployment

Comparison with Alternatives

FeatureMixMakenpm/yarnCargoGradle
LanguageElixir-nativeLanguage-agnosticJavaScriptRust-nativeJVM
Dependency ManagerHex (built-in)Externalnpm registrycrates.ioMaven Central
Test RunnerBuilt-inExternalExternal (Jest/Mocha)Built-inBuilt-in
Custom TasksFirst-classTargetsnpm scriptsBuild scriptsGradle tasks
Umbrella SupportBuilt-inManualWorkspacesWorkspacesMulti-project
Incremental BuildsYesTimestamp-basedPartialYesYes
Release BuildingBuilt-inExternalExternal (webpack)Built-inBuilt-in
Parallel ExecutionTests only-j flagLimitedYesYes

Mix is the natural and only build tool for Elixir projects. Its deep integration with the language compiler, OTP release system, and Hex package manager makes it irreplaceable in the platform's toolchain.

  • Elixir - The language Mix is built for and ships with
  • ExUnit - Testing framework executed through Mix
  • Dialyzer - Static analysis run through Mix via dialyxir
  • Credo - Code quality analysis invoked through Mix
  • Ecto - Database migrations managed through Mix tasks
  • Phoenix - Web framework with Mix tasks for routes, generators, and server management
  • All 90 Prismatic Platform applications are built, tested, and managed with Mix
  • prismatic_safety - Quality gate tasks implemented as Mix tasks
  • prismatic_web - Phoenix-specific Mix tasks for web development

Connect & Contribute

Created by Tomáš Korcak (korczis) | Open Source under GHL