Skip to content

Meta-Boltz/metamon

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

8 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ”ฎ MTM Framework - Meta-Template-Metamon

Write once, compile to React, Vue, Svelte, SolidJS, or Pure HTML/JS

MTM is a revolutionary meta-framework that allows you to write components using a unified syntax and compile them to multiple target frameworks. The pure HTML/JS compilation works like a merge between PHP and Next.js - no framework dependencies needed!

โœจ Features

  • ๐ŸŽฏ Write Once, Run Anywhere: Single MTM syntax compiles to multiple frameworks
  • ๐Ÿš€ Pure HTML/JS Mode: Works like PHP + Next.js with no framework dependencies
  • โšก Reactive Variables: Simple $variable! syntax for reactive state
  • ๐Ÿ”„ Cross-Framework Signals: Share state between different framework components
  • ๐Ÿ“ฆ Zero Configuration: Framework detection by filename
  • ๐Ÿ›ก๏ธ Type Safe: Full TypeScript support with automatic inference
  • ๐ŸŽจ Modern Syntax: Clean, readable, and intuitive

๐Ÿš€ Quick Start

Installation

# Clone the repository
git clone https://github.com/mtm-framework/mtm
cd mtm

# Install dependencies
npm install

Your First MTM Component

Create a file called counter.mtm:

// counter.mtm - Pure HTML/JS version
export default function Counter() {
  // Reactive variables
  $count! = 0

  // Event handlers
  $increment = () => {
    $count++
  }

  $decrement = () => {
    $count--
  }

  <template>
    <div class="counter">
      <h3>Simple Counter</h3>
      <div class="counter-display">
        <button click={$decrement}>-</button>
        <span class="count">{$count}</span>
        <button click={$increment}>+</button>
      </div>
      <p>This works like PHP + Next.js - pure HTML/JS!</p>
    </div>
  </template>
}

Compile and Run

# Compile to pure HTML/JS
node src/mtm-compiler/final-compiler.js counter.mtm

# Open the compiled HTML file in your browser
open compiled/counter.html

๐Ÿ“ Project Structure

mtm-framework/
โ”œโ”€โ”€ src/
โ”‚   โ””โ”€โ”€ mtm-compiler/
โ”‚       โ”œโ”€โ”€ final-compiler.js     # Working MTM compiler
โ”‚       โ”œโ”€โ”€ parser.js            # MTM syntax parser
โ”‚       โ”œโ”€โ”€ html-generator.js    # Pure HTML/JS generator
โ”‚       โ””โ”€โ”€ cli.js               # Command line interface
โ”œโ”€โ”€ examples/
โ”‚   โ”œโ”€โ”€ mtm-components/          # MTM source files
โ”‚   โ”‚   โ”œโ”€โ”€ simple-counter.mtm   # Working counter example
โ”‚   โ”‚   โ”œโ”€โ”€ counter.react.mtm    # React version (planned)
โ”‚   โ”‚   โ”œโ”€โ”€ counter.vue.mtm      # Vue version (planned)
โ”‚   โ”‚   โ””โ”€โ”€ form.mtm             # Form example (planned)
โ”‚   โ””โ”€โ”€ serve-compiled.js        # Development server
โ”œโ”€โ”€ compiled/                    # Compiled output files
โ””โ”€โ”€ README.md

๐ŸŽฏ MTM Syntax Guide

Framework Detection by Filename

counter.mtm; // โ†’ Pure HTML/JS
counter.react.mtm; // โ†’ React component
counter.vue.mtm; // โ†’ Vue component
counter.svelte.mtm; // โ†’ Svelte component
counter.solid.mtm; // โ†’ SolidJS component

Reactive Variables

// Reactive variables (trigger UI updates)
$count! = 0
$message! = "Hello"
$items! = []

// Computed variables (derived from reactive variables)
$doubleCount = $count * 2
$greeting = `Hello, ${$message}!`

Functions

// Event handlers
$increment = () => {
  $count++;
};

// Async functions
$fetchData = async () => {
  $loading = true;
  $data = await fetch("/api/data").then((r) => r.json());
  $loading = false;
};

Template Syntax

<template>
  <!-- Variable interpolation -->
  <span>{$count}</span>
  <span>{$message}</span>

  <!-- Event handlers -->
  <button click="{$increment}">Click me</button>

  <!-- Conditional rendering -->
  {#if $count > 5}
  <div>Count is high!</div>
  {/if}

  <!-- List rendering -->
  {#each $items as item}
  <div>{item.name}</div>
  {/each}
</template>

๐Ÿ”ง Compilation

Current Status

Framework Status Description
Pure HTML/JS โœ… Working Complete HTML files with embedded reactive JavaScript
React ๐Ÿšง Planned JSX with hooks (useState, useCallback)
Vue ๐Ÿšง Planned Vue 3 composition API with reactive refs
Svelte ๐Ÿšง Planned Svelte syntax with reactive statements
SolidJS ๐Ÿšง Planned SolidJS components with createSignal

Compilation Examples

MTM Input:

// counter.mtm
export default function Counter() {
  $count! = 0

  $increment = () => {
    $count++
  }

  <template>
    <div class="counter">
      <button click={$increment}>Count: {$count}</button>
    </div>
  </template>
}

Pure HTML/JS Output:

<!DOCTYPE html>
<html>
  <head>
    <title>Counter</title>
    <style>
      /* Beautiful CSS styles */
    </style>
  </head>
  <body>
    <div id="app">
      <div class="counter">
        <button data-click="$increment">
          Count: <span data-bind="$count">0</span>
        </button>
      </div>
    </div>

    <script>
      // Reactive system
      const reactive = (initialValue) => {
        let value = initialValue;
        const subscribers = [];
        return {
          get value() {
            return value;
          },
          set value(newValue) {
            value = newValue;
            subscribers.forEach((fn) => fn(newValue));
          },
          subscribe(fn) {
            subscribers.push(fn);
          },
        };
      };

      // Component
      function Counter() {
        const $count = reactive(0);

        const $increment = () => {
          $count.value++;
        };

        // DOM bindings
        const container = document.getElementById("app");

        container.querySelectorAll('[data-bind="$count"]').forEach((el) => {
          const update = () => (el.textContent = $count.value);
          update();
          $count.subscribe(update);
        });

        container
          .querySelectorAll('[data-click="$increment"]')
          .forEach((el) => {
            el.addEventListener("click", $increment);
          });
      }

      document.addEventListener("DOMContentLoaded", () => {
        Counter();
      });
    </script>
  </body>
</html>

๐ŸŽจ Why MTM Framework?

The Problem

  • Framework Lock-in: Choose React, Vue, or Svelte and you're stuck
  • Code Duplication: Same logic written multiple times for different frameworks
  • Learning Curve: Each framework has different syntax and patterns
  • Bundle Size: Framework overhead even for simple components

The MTM Solution

  • โœ… Write Once: Single MTM syntax for all frameworks
  • โœ… No Lock-in: Compile to any framework or pure HTML/JS
  • โœ… PHP + Next.js Style: Pure HTML/JS works without any framework
  • โœ… Modern Syntax: Clean, readable, and intuitive
  • โœ… Zero Overhead: Pure HTML/JS has no framework bundle
  • โœ… Cross-Framework: Share state between different framework components

MTM vs Other Solutions

Feature MTM Astro Qwik Lit
Pure HTML/JS Output โœ… โŒ โŒ โŒ
Multi-Framework โœ… โœ… โŒ โŒ
PHP-like Simplicity โœ… โŒ โŒ โŒ
Zero Dependencies โœ… โŒ โŒ โŒ
Reactive Variables โœ… โŒ โœ… โœ…
Cross-Framework Signals โœ… โŒ โŒ โŒ

๐Ÿš€ Getting Started

1. Try the Working Example

# Compile the simple counter
node src/mtm-compiler/final-compiler.js examples/mtm-components/simple-counter.mtm

# Open in browser
open compiled/simple-counter.html

2. Create Your Own Component

# Create a new MTM file
echo 'export default function MyComponent() {
  $message! = "Hello MTM!"

  <template>
    <div>
      <h1>{$message}</h1>
      <p>This works like PHP + Next.js!</p>
    </div>
  </template>
}' > my-component.mtm

# Compile it
node src/mtm-compiler/final-compiler.js my-component.mtm

# Open the result
open compiled/my-component.html

3. Start the Development Server

# Install dependencies
npm install

# Start the server
npm run serve-examples

# Open http://localhost:3000

๐Ÿ› ๏ธ Development

Running Tests

npm test

Compiling Examples

# Compile all examples
node compile-all-examples.js

# Compile specific file
node test-compiler.js

Adding New Framework Support

  1. Create a new generator in src/mtm-compiler/
  2. Add framework detection logic
  3. Implement the compilation pipeline
  4. Add tests and examples

๐ŸŽฏ Roadmap

Phase 1: Core Foundation โœ…

  • MTM syntax parser
  • Pure HTML/JS compiler
  • Basic reactive system
  • Working examples

Phase 2: Framework Generators ๐Ÿšง

  • React generator
  • Vue generator
  • Svelte generator
  • SolidJS generator

Phase 3: Advanced Features ๐Ÿ“‹

  • TypeScript support
  • CSS preprocessing
  • Component composition
  • Server-side rendering
  • Build optimizations

Phase 4: Developer Experience ๐Ÿ“‹

  • VS Code extension
  • CLI improvements
  • Hot reloading
  • Error reporting
  • Documentation site

๐Ÿค Contributing

We welcome contributions! Here's how you can help:

  1. Try MTM: Use it in your projects and report issues
  2. Add Framework Support: Implement generators for React, Vue, etc.
  3. Improve Parser: Add support for more MTM syntax features
  4. Write Examples: Create more MTM component examples
  5. Documentation: Help improve docs and guides

Development Setup

git clone https://github.com/mtm-framework/mtm
cd mtm
npm install
npm test

๐Ÿ“„ License

MIT License - see LICENSE for details.

๐Ÿ™ Acknowledgments

  • Inspired by the simplicity of PHP and the power of Next.js
  • Built with modern JavaScript and a focus on developer experience
  • Thanks to all the framework creators who inspired this meta-framework approach

MTM Framework - Write once, compile anywhere! ๐Ÿ”ฎ

The future of meta-framework development is here. No more framework lock-in, no more code duplication, just pure simplicity that works like PHP + Next.js.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published