Twig is a mature, feature-rich template engine for PHP that compiles templates to optimized PHP code. It employs a lexer-parser-compiler pipeline to transform template source into an abstract syntax tree (AST), which is then compiled to executable PHP. The engine emphasizes security through automatic escaping and a sandboxing system, and extensibility via a robust extension system that allows adding custom functions, filters, tests, and token parsers. Twig supports template inheritance, macros, and expressive syntax with features like null-safe operators and arrow functions. The architecture is modular and follows several well-established patterns: a plugin-based expression parser, a decorator-pattern caching system, a visitor pattern for AST manipulation, and an attribute-driven extension registration mechanism (using PHP 8+ attributes). The codebase demonstrates careful attention to extensibility, security, and performance, with comprehensive test coverage and active maintenance. While the project manages significant backward compatibility (notably preparing for Twig 4.0), it maintains a clean separation of concerns and provides reusable components that could be adapted for other projects, such as its chainable cache, expression parser registry, and sandbox security policy.
Mockoon is a multi-platform API mocking tool that runs mock servers locally or remotely. It is built as a monorepo with six npm packages: @mockoon/commons (shared models, migrations, OpenAPI converter), @mockoon/commons-server (core Express-based mock server engine with templating and response rules), @mockoon/app (Electron desktop application with an Angular renderer), @mockoon/cli (oclif-based command-line interface), @mockoon/cloud (cloud sync library), and the deprecated @mockoon/serverless wrapper. The architecture cleanly separates the core server logic from the delivery mechanisms. The MockoonServer class provides an HTTP/HTTPS server with a sophisticated response rule engine, a Handlebars templating system with over 100 custom helpers (including deep Faker.js integration), CRUD operations on data buckets, WebSocket support, proxy mode, and a full admin API. The desktop app uses a Redux-like state management pattern with RxJS, ensuring predictable and testable UI state transitions. The codebase demonstrates high craftsmanship in several areas. The ResponseRulesInterpreter is a self-contained DSL for matching HTTP requests to mock responses. The TemplateParser provides an extensible helper registration system. The data migration system in commons is a textbook example of handling schema evolution for JSON-based data models. The project is actively maintained with a robust CI/CD pipeline, though it carries some technical debt such as a deprecated serverless package and disabled strict TypeScript mode in the desktop app.
Twig.js is a JavaScript port of the Twig templating language, originally written in PHP. It provides a full-featured template engine for both Node.js and browser environments, implementing core Twig syntax: variable interpolation ({{ }}), logic tags ({% %}), comments ({# #}), template inheritance via extends/block, includes, embeds, macros, and a rich set of filters, functions, and tests. The library ships as a UMD bundle for browsers and CommonJS for Node, and integrates with Express as a view engine via __express and renderFile. A CLI (bin/twigjs) compiles .twig templates into standalone JavaScript modules for Node, AMD, or CJS2 targets. The architecture is modular: src/twig.core.js handles tokenization, compilation, and template caching; src/twig.expression.js implements an expression tokenizer and shunting-yard parser for operators, filters, and function calls; src/twig.logic.js handles control-flow tags; and src/twig.filters.js / src/twig.functions.js provide the standard filter/function libraries. A factory pattern (src/twig.factory.js) assembles all submodules, and an extension API (extendTag, extendFilter, extendFunction, extendTest) allows users to add custom behavior. The codebase is well-tested with an extensive suite covering control structures, inheritance, expressions, filters, loaders, parsers, and browser-specific behavior. The repository carries legacy baggage: mixed ES5/ES6 style, a custom synchronous Promise implementation (Twig.Promise) that is not fully spec-compliant, and incomplete parity with Twig 3.x features (several filters/functions marked unsupported in implementation notes). The project migrated from Travis CI to GitHub Actions (Node 22/24) and maintains active development, but the custom async layer and dependency on locutus (PHP function ports) are areas of potential fragility. Demos include an Express note-taking app and a Backbone.js Twitter feed, both using older patterns but useful as integration references.
Nunjucks is a full-featured JavaScript templating engine heavily inspired by Jinja2 (Python). It compiles templates into JavaScript functions for high-performance rendering, supporting template inheritance, macros, filters, tests, async control, and custom extensions. The library runs in both Node.js and browser environments, with a slim build for precompiled templates. It integrates with Express as a view engine and provides a CLI tool for precompiling templates offline. The architecture follows a classic compiler pipeline: lexer → parser → AST → compiler → JavaScript function. The public API exposes Environment, Template, Loader, and various configuration methods. Templates are loaded via loaders (FileSystemLoader, WebLoader, PrecompiledLoader) and rendered synchronously or asynchronously. The library includes a rich set of built-in filters (escape, default, sort, groupby, etc.) and tests (defined, odd, mapping, etc.), all extensible via addFilter/addTest. Key entry points include nunjucks/index.js (main module), bin/precompile (CLI), and browser/nunjucks.js (UMD build). External dependencies are minimal: a-sync-waterfall for async control flow, asap for microtask scheduling, and chokidar for file watching. The codebase is well-tested with Mocha and has CI via GitHub Actions. While the core engine is well-crafted and actively maintained, the repository carries technical debt from vendored documentation dependencies (Bootstrap 3, jQuery 2, Bower) and an outdated build toolchain (Babel beta, PhantomJS). The library itself is production-ready and widely used (8.9k stars).