Mage AI (Mage OSS) is a self-hosted, notebook-style data pipeline tool for building ETL, ELT, and dbt workflows in Python, SQL, or R, run locally via Docker, pip, or conda.
- Language
- Python
- Database
- PostgreSQL
- Hosting
- Docker
- License
- Apache-2.0
- Running for
- 2 years 8 months
- Team
- 6-20 people
Why this architecture
A Tornado Python server handles orchestration over a SQLAlchemy and Alembic-modeled Postgres database, while the pipeline editor ships as an independent Next.js frontend, and Spark or dbt support is layered in through opt-in Docker images and bundled adapters.
Tech stack by layer
12 technologies · audited Sep 17, 2026- Next.jsThe mage_ai/frontend app provides the block-based pipeline editor and notebook UI.
- Tornadomage_ai/server runs a Python Tornado web server exposing the API and websockets to the frontend.
- SQLAlchemyORM for the orchestration database (pipelines, runs, blocks) under mage_ai/orchestration.
- AlembicManages schema migrations for the orchestration database.
- PostgreSQLDefault orchestration datastore, provisioned via the pgvector/pgvector image in dev compose.
- RedisUsed for caching and coordination alongside the orchestration database.
- dbtdbt-core plus per-warehouse adapters let pipelines run dbt models as blocks.
- DockerDockerfile builds the all-in-one server and frontend image; Spark/Databricks variants exist too.
- KubernetesProvides a sample Kubernetes deployment manifest for running Mage in a cluster.
- Apache SparkSpark and custom-Spark Dockerfiles bundle PySpark for large-scale pipeline execution.
Mage AI architecture diagram
Open SVGDiagram as text
- Pipeline editor (Next.js) → Mage server (Python · Tornado): REST · WebSocket
- Mage server (Python · Tornado) → Orchestrator (pipelines · runs): trigger
- Orchestrator (pipelines · runs) → Blocks (Python · SQL · dbt): execute
- Blocks (Python · SQL · dbt) → Spark (optional) (PySpark variants): large jobs
- Orchestrator (pipelines · runs) → Orchestration DB (Postgres (SQLAlchemy)): run state
- Mage server (Python · Tornado) → Redis (cache · coordination): cache
- Blocks (Python · SQL · dbt) → Warehouses (dbt adapters): dbt models
Key architectural decisions
5 decisions- 01
One Python package ships both the orchestrator and the integrations library
The repo root requirements.txt and pyproject.toml define the mage-ai package (mage_ai/), while mage_integrations/ is a separately packaged Singer-based connector library (mage_integrations/pyproject.toml) installed as the [all] extra in the Dockerfile.
- 02
The frontend is a separate Next.js app talking to a Tornado backend
mage_ai/frontend/package.json is an independent Next.js/React app built with next build/next export, compiled into static assets and served by the Python Tornado server in mage_ai/server rather than rendered server-side by Next.js itself.
- 03
dbt is a first-class block type with adapters bundled for every major warehouse
requirements.txt pins dbt-core alongside dbt-bigquery, dbt-snowflake, dbt-redshift, dbt-spark, and dbt-postgres, so pipelines can run existing dbt projects as blocks without a separate dbt installation.
- 04
Spark support ships as opt-in Docker variants, not the default image
dev.spark.Dockerfile and integrations/spark/Dockerfile install OpenJDK and PySpark on top of the base mageai/mageai image, keeping the default Docker image lighter for users who do not need Spark.
- 05
Postgres with pgvector is the default orchestration database in dev
docker-compose.yml's database service uses the pgvector/pgvector:0.6.0-pg16 image rather than plain postgres, making vector-backed features available without a separate extension install step.
How Mage AI is built
How Mage AI is structured
Mage AI's Python package lives in mage_ai/, split into functional subpackages: mage_ai/server (the Tornado web server and API), mage_ai/orchestration (scheduling, pipeline runs, the SQLAlchemy models), mage_ai/data_preparation (pipeline and block execution logic), mage_ai/data_integrations and the sibling mage_integrations/ package (Singer-based source/destination connectors, published separately via its own pyproject.toml), and mage_ai/frontend (an independent Next.js app). mage_ai/cli, mage_ai/authentication, mage_ai/cluster_manager, and mage_ai/streaming round out CLI tooling, auth, cluster orchestration (Kubernetes/ECS), and streaming pipeline support respectively. The root requirements.txt is large and unusually broad, bundling optional connector dependencies (Snowflake, BigQuery, Kafka, MongoDB, and dozens more) directly into the base install rather than as separate extras.
Frontend
mage_ai/frontend/package.json defines a Next.js 12 application using React 18, styled-components, and a Monaco-based code/notebook editor (@monaco-editor/react, monaco-editor, monaco-languageclient) for writing pipeline block code in-browser. Visualization uses the Airbnb Visx library family (@visx/axis, @visx/heatmap, @visx/stats, and others) for pipeline run charts. The export/export_prod scripts run next build && next export, producing static assets rather than a running Next.js server — those assets are then served by the Python backend, not by Next.js itself. Storybook (storybook, build-storybook scripts) and Playwright (test, test:ci) cover component development and end-to-end testing.
Backend & APIs
The backend server is Tornado, a Python async web framework pinned in requirements.txt (tornado==6.4.2); mage_ai/server implements the REST and websocket API consumed by the frontend, started via scripts/run_app.sh and mage_ai/server/server.py (referenced directly in docker-compose.yml's command). Pipeline orchestration state (pipelines, blocks, runs, triggers) is modeled with SQLAlchemy (sqlalchemy>2.0.0) and migrated with Alembic (alembic>=1.7.5) under mage_ai/orchestration. Data integration connectors live in the sibling mage_integrations package, built on the Singer protocol (singer_sdk), and are installed into the Docker image via a git+https://github.com/mage-ai/mage-ai.git#egg=mage-integrations&subdirectory=mage_integrations reference rather than a published PyPI split. mage_ai/ai and mage_ai/autocomplete house AI-assisted features (referenced by ENABLE_OPEN_AI/ENABLE_HUGGING_FACE environment variables in docker-compose.yml), and mage_ai/command_center implements the in-app command palette exposed through the Tornado API.
Data & persistence
docker-compose.yml's database service uses pgvector/pgvector:0.6.0-pg16 as the default Postgres image, so vector-backed features work out of the box during local development. requirements.txt pins redis~=5.0.1 for caching/coordination. For transformation workloads, dbt-core (dbt-core==1.10.20) ships with adapters for BigQuery, Snowflake, Redshift, Postgres, DuckDB, ClickHouse, Spark, SQL Server, Synapse, and Trino, letting existing dbt projects run as Mage blocks without a separate dbt install. Dozens of additional connector libraries (snowflake-connector-python, google-cloud-bigquery, pymongo, kafka-python, elasticsearch) are bundled directly rather than split into optional extras.
Build, test & deploy
The project uses Poetry for its dev tooling (pyproject.toml's [tool.poetry] group defines mypy, black, flake8, pytest, pre-commit, isort), while runtime dependencies are pinned separately in requirements.txt; pyproject.toml also configures Ruff linting rules that exclude the generated mage_ai/data_preparation/templates and migration versions directories. Makefile targets (install-hooks, dev_env) wire up git hooks from .git-dev/hooks and create the Poetry virtualenv. GitHub Actions workflows include build_and_test.yml, codeql-analysis.yml, lint_docker_image.yml, publish_docker_image.yml, publish_to_pypi.yml, and trivy.yml for container vulnerability scanning, covering both the Docker image and PyPI package release paths. templates/github_actions and templates/gitlab_cicd ship example CI/CD pipeline templates for users deploying their own Mage-orchestrated pipelines, and templates/cicd provides Mage-native pipeline templates for CI/CD-triggered runs.
Self-hosting notes
The primary self-hosting path is Docker: docker pull mageai/mageai:latest, or building the root Dockerfile, which installs system dependencies (ODBC drivers, R, postgresql-client), sparkmagic for optional Spark notebook kernels, and the mage-ai[all] extra. Alternative install paths are pip install mage-ai and conda install -c conda-forge mage-ai. docker-compose.yml defines multiple service variants (server, server_spark, app, app_spark, lsp for a language server, and database) behind shared YAML anchors, and kube/app.yaml provides a starting point for Kubernetes deployments. Separate Dockerfiles under integrations/ (Databricks, Hadoop, Oracle, custom Spark, OpenSSL 1.1.1) extend the base image for specific enterprise data platform connectivity.
Sources & repo audit
- Audited
- Sep 17, 2026
- Commit
- 1912c29
- License
- Apache-2.0
- requirements.txt (Tornado, SQLAlchemy, Alembic, dbt, Redis dependencies)
- mage_ai/frontend/package.json (Next.js frontend)
- docker-compose.yml (pgvector Postgres, dev services)
- Dockerfile (production image, mage-ai[all] install)
- integrations/spark/Dockerfile (Spark integration image)
Independent analysis of repository at github.com/mage-ai/mage-ai. Spotted an inaccuracy? Use the claim form to request a correction.
Show this stack on your README or website
[](https://stackitfast.com/project/mage-ai)Paste it into your README. It shows your current stack and links to this page.
Scaffold it with your agent
Paste this prompt into Claude Code, Cursor, Windsurf or AGY to start a project with Mage AI's architecture.
- 1Copy the promptThe full markdown spec, with every layer and decision.
- 2Open your AI toolClaude Code, Cursor, Windsurf or Copilot, in a new repo.
- 3Paste and scaffoldUse it as the first instruction; review before you ship.
# MISSION: Scaffold "Mage AI" Production Architecture
You are an expert Senior Staff Software Architect and Full-Stack Engineer. Your mission is to scaffold and implement a production-grade, highly reliable, and modular codebase following the proven architecture of **Mage AI**.
---
## 1. PROJECT SPECIFICATIONS & BENCHMARK
- **Reference Architecture**: Mage AI
- **What It Does**: Mage AI (Mage OSS) is a self-hosted, notebook-style data pipeline tool for building ETL, ELT, and dbt workflows in Python, SQL, or R, run locally via Docker, pip, or conda.
- **Domain & Category**: Data Pipeline Engine
- **Production Scale**: 6-20 people
- **Development Mode**: HYBRID
- **Architectural Rationale**: A Tornado Python server handles orchestration over a SQLAlchemy and Alembic-modeled Postgres database, while the pipeline editor ships as an independent Next.js frontend, and Spark or dbt support is layered in through opt-in Docker images and bundled adapters.
- **Live Website Reference**: https://www.mage.ai
- **Source Repository**: https://github.com/mage-ai/mage-ai
---
## 2. PRODUCTION TECH STACK
- **Full Stack Array**: Python, TypeScript, Next.js, PostgreSQL, Redis, SQLAlchemy, Alembic, Docker, Kubernetes, dbt, Apache Spark, Tornado
- **Primary Language(s)**: Python, TypeScript
- **License of the reference repo**: Apache-2.0
- **Frontend**: Next.js — The mage_ai/frontend app provides the block-based pipeline editor and notebook UI.
- **Backend & APIs**: Tornado — mage_ai/server runs a Python Tornado web server exposing the API and websockets to the frontend.; SQLAlchemy — ORM for the orchestration database (pipelines, runs, blocks) under mage_ai/orchestration.; Alembic — Manages schema migrations for the orchestration database.
- **Data & persistence**: PostgreSQL — Default orchestration datastore, provisioned via the pgvector/pgvector image in dev compose.; Redis — Used for caching and coordination alongside the orchestration database.; dbt — dbt-core plus per-warehouse adapters let pipelines run dbt models as blocks.
- **Infrastructure & deploy**: Docker — Dockerfile builds the all-in-one server and frontend image; Spark/Databricks variants exist too.; Kubernetes — Provides a sample Kubernetes deployment manifest for running Mage in a cluster.; Apache Spark — Spark and custom-Spark Dockerfiles bundle PySpark for large-scale pipeline execution.
---
## 3. KEY ARCHITECTURAL DECISIONS (audited from https://github.com/mage-ai/mage-ai @ 1912c29)
1. **One Python package ships both the orchestrator and the integrations library**: The repo root requirements.txt and pyproject.toml define the mage-ai package (mage_ai/), while mage_integrations/ is a separately packaged Singer-based connector library (mage_integrations/pyproject.toml) installed as the [all] extra in the Dockerfile.
2. **The frontend is a separate Next.js app talking to a Tornado backend**: mage_ai/frontend/package.json is an independent Next.js/React app built with next build/next export, compiled into static assets and served by the Python Tornado server in mage_ai/server rather than rendered server-side by Next.js itself.
3. **dbt is a first-class block type with adapters bundled for every major warehouse**: requirements.txt pins dbt-core alongside dbt-bigquery, dbt-snowflake, dbt-redshift, dbt-spark, and dbt-postgres, so pipelines can run existing dbt projects as blocks without a separate dbt installation.
4. **Spark support ships as opt-in Docker variants, not the default image**: dev.spark.Dockerfile and integrations/spark/Dockerfile install OpenJDK and PySpark on top of the base mageai/mageai image, keeping the default Docker image lighter for users who do not need Spark.
5. **Postgres with pgvector is the default orchestration database in dev**: docker-compose.yml's database service uses the pgvector/pgvector:0.6.0-pg16 image rather than plain postgres, making vector-backed features available without a separate extension install step.
---
## 4. NON-NEGOTIABLE ARCHITECTURAL GUARDRAILS
1. **Monorepo & Modular Separation**:
- Structure as a Turborepo monorepo with strict package boundaries:
- `apps/web`: Application UI, routing, layouts, and server endpoints.
- `packages/ui`: Shared design tokens, CSS variables, and Radix UI primitive components.
- `packages/db`: Database schemas, client singleton, declarative migrations, and seed scripts.
- `packages/config`: Shared TypeScript, ESLint, and build configurations.
2. **Strict Type Safety & Zero `any` Policy**:
- Enable `strict: true`, `noImplicitAny: true`, and `strictNullChecks: true`.
- Validate ALL external inputs, API request bodies, and query parameters with **Zod** schemas before execution.
3. **Frontend & Rendering Guidelines**:
- Utilize Next.js 15 App Router: default to React Server Components (RSC) for data fetching. Handle mutations through Server Actions with Zod validation. Keep 'use client' directives restricted strictly to interactive leaf components.
4. **Design System & Aesthetics**:
- Keep every color, radius, shadow and font in a single token file (CSS variables) and consume tokens everywhere; never hardcode hex values in components.
- Prefer crisp 1px borders and one subtle shadow scale over blurry default shadows. Pair one sans-serif for body/headings with one monospace for tags, badges, metrics, and code.
5. **Data Layer & Reliability**:
- Write declarative schema definitions with foreign keys, composite indexes on queried filters, and automated timestamp triggers.
- Use connection pooling and prepared statements for serverless database execution.
---
## 5. STEP-BY-STEP SCAFFOLDING ROADMAP
- **Phase 1: Workspace & Root Config**: Initialize package manager, monorepo configuration (`turbo.json`, `tsconfig.base.json`, `package.json`).
- **Phase 2: Database Schema & Client**: Set up the data layer (PostgreSQL, Redis, dbt): client, connection pool, models, and migration scripts.
- **Phase 3: Design Tokens & UI Primitives**: Build accessible `Button`, `Input`, `Card`, `Badge`, and layout wrappers inside `packages/ui`.
- **Phase 4: Core Application Routes & Handlers**: Implement primary authentication, user session handling, and application routes.
- **Phase 5: Quality Assurance & Build Verification**: Run `tsc --noEmit`, ESLint, Prettier, and smoke test suites to ensure zero compilation or runtime errors.
---
## 6. EXECUTION INSTRUCTIONS
1. Review all specifications, architectural guardrails, and stack choices above.
2. Present the full monorepo directory tree structure.
3. Systematically generate the complete, production-ready codebase according to the 5-phase roadmap above — starting with the root workspace setup, followed by the database schema, UI design system package, and full-stack application routes until the repository is fully scaffolded and ready to run.Frequently asked about Mage AI
What is Mage AI built with?
Mage (mage-ai) is a Python package: a Tornado web server in mage_ai/server backed by SQLAlchemy and Alembic over PostgreSQL, paired with a separate Next.js and React frontend in mage_ai/frontend.
Does Mage support dbt?
Yes, requirements.txt bundles dbt-core with adapters for BigQuery, Snowflake, Redshift, Postgres, DuckDB, and Spark, so dbt models can run as pipeline blocks.
Can Mage run Spark pipelines?
Yes, via opt-in Docker images: dev.spark.Dockerfile and integrations/spark/Dockerfile install OpenJDK and PySpark on top of the base Mage image for Spark-based pipeline execution.
Can I self-host Mage?
Yes, Mage OSS is self-hosted by design, installable via the root Dockerfile, pip install mage-ai, or conda install -c conda-forge mage-ai, all documented in the README quickstart.
One email a month: new deep dives and stack trends
New source-audited architectures, head-to-head comparisons and the monthly stack report. No spam, unsubscribe anytime.
Similar architectures
- Crowd.devClassicDeveloper Data Platform · 6-20 peopleShares TypeScript · PostgreSQL · Redis
- FormbricksAI-agentSurvey & Feedback SaaS · 2-5 peopleShares Next.js · TypeScript · PostgreSQL
- Mem0AI-agentAI Memory & Context Engine · 2-5 peopleShares Python · TypeScript · PostgreSQL
- Dify.aiAI-agentLLM App Builder · 20+ peopleShares Next.js · TypeScript · Python
- UmamiHybridWeb Analytics · SoloShares TypeScript · Next.js · PostgreSQL
- DragonflyClassicMulti-Threaded In-Memory Key-Value Store · 20+ PeopleShares Python · Docker · Redis