Skip to content

About

No description, website, or topics provided.

Resources

Contributing

Stars

2 stars

Watchers

1 watching

Forks

Repository files navigation

Email Template Editor

A visual editor for building HTML email templates as a tree of blocks. Authors compose structure, reuse elements, and generate a ready-to-send template without hand-editing raw HTML.

Built with Next.js (App Router), React, Ant Design, and Vitest.

Editor: navigation sidebar, AI assistant and live email preview

Goal

Give non-specialists (and developers) a reliable way to assemble email templates from reusable blocks, keep the structure consistent, and export HTML that a backend can render or store.

Problems it solves

Problem How this app helps
Email HTML is fragile and hard to edit by hand Structure is a tree of elements instead of a single HTML blob
Teams reinvent the same header/footer/CTA Each template has an Elements library of reusable blocks
Several emails are in progress at once Templates list: create, rename, delete and open each one
Design and code drift apart Visual tree + generate step keeps the output tied to the model
Hard to see the hierarchy of a template Tree view with add / edit / delete on each node
Generating a final file is manual Generate calls the backend and returns a link to the result
No record of what was sent Sent emails log keeps recipients, subject and the HTML

Screenshots

All screenshots use the sample data that ships with the backend: a template called "Default template" with a No More To-Go "Weekly Menu" issue of six recipes. For the list and the log, two empty templates were added and the sample was sent three times.

Templates

/ opens the list of templates. Click a name to open it in the editor; Rename and Delete sit in each row, New template creates an empty one.

Templates list

Editor

The editor works on one template. The header shows its name and a link back to the list; the toolbar has Add root element, Generate and Send email. The AI assistant is on the left, the live preview on the right (see the screenshot at the top of this page).

Live preview

The preview renders the template tree as the final email. Here are the recipe rows: each row is a {{twoBlocks}} element holding two {{recipeCard}} elements.

Live preview of the recipe rows

Template tree and Elements library

Both panels sit under the preview and are collapsed by default. Each placeholder in a node's HTML becomes a child node ({{item1}}, {{link}}, {{image}}, …). Right-click a node to add a child, edit it, or delete it. The Elements library holds the reusable blocks: {{twoBlocks}} (two-column row), {{recipeCard}} (photo, title and subtitle) and {{textBlock}} (a paragraph).

Template tree and Elements library

Editing an element

The title is the placeholder used in the tree ({{recipeCard}}). The value is the HTML it expands to, with its own placeholders.

Edit element modal

Sending an email

Send email asks for recipients and a subject (the template name by default). Delivery is not configured yet: the backend renders the template and records the email in the log without delivering it.

Send email dialog

Sent emails

The Sent emails page lists every send, newest first. Filter by template in the Template column; more than three recipients collapse into a +N tag.

Sent emails log

Click a row to see the email as it was sent: recipients, template, time, status and the HTML snapshot. The snapshot stays even if the template is changed or deleted later.

A sent email opened in the drawer

Dark theme

The button in the top-right corner switches the theme: System (default, follows the OS), Light or Dark. The choice is saved in a cookie, so the page renders in the right theme on the first paint. The email preview keeps the email's own colors: it shows what the recipient will see.

Dark theme with the theme menu open

The pages, the tree, the Elements library and the modals follow the theme too.

Templates list in the dark theme

Template tree and Elements library in the dark theme

Edit element modal in the dark theme

A sent email in the dark theme

Regenerating the screenshots

  1. Start the backend with a copy of the sample db.json (DB_FILE=/tmp/db.json npm run dev), so the extra data does not end up in the repo. Run npm run dev here.
  2. Through the API, create two more templates ("Spring newsletter", "Welcome email") and send the sample template three times (POST /templates/:id/send), one of them to five recipients.
  3. Capture at 1440×900, device scale 2, with the theme cookie set to light and the Next.js dev badge hidden:
    • /templates;
    • the editor of the sample template;
    • the preview scrolled to the first recipe row;
    • both panels expanded (capture the panels only, with a viewport tall enough to fit them);
    • the edit modal of {{recipeCard}};
    • the Send email dialog with two recipients;
    • /sent;
    • /sent with the five-recipient email open.
  4. Repeat with theme=dark (-dark suffix) for:
    • the theme menu open in the editor;
    • /templates;
    • the panels;
    • the edit modal;
    • the open sent email.

How it works

The app has three pages, reachable from the sidebar:

Page What it does
/templates All templates: create, rename, delete, or open one in the editor. / redirects here.
/templates/[id] The editor for one template: preview, AI assistant, tree and elements, Generate and Send email.
/sent The log of sent emails, newest first, filterable by template; a row opens the email as it was sent.

Each template has its own tree and its own elements library. Send email does not deliver anything yet: the backend renders the template and records it (recipients, subject, HTML) in the sent emails log.

flowchart LR
  User[Author] --> List[Templates list]
  List -->|open| UI[Editor UI]
  UI --> Tree[Template tree]
  UI --> Lib[Elements library]
  UI -->|Generate / Send| API[Backend API]
  Tree -->|load / save / update| API
  Lib -->|CRUD| API
  API --> HTML[Generated HTML]
  API --> Log[Sent emails log]
Loading
sequenceDiagram
  participant U as User
  participant UI as Editor
  participant API as Backend
  U->>UI: Open a template from /templates
  UI->>API: GET /templates/:id/tree
  API-->>UI: Current tree
  U->>UI: Add / edit / delete nodes
  UI->>API: save / update / add / delete
  U->>UI: Generate
  UI->>API: POST /templates/:id/generate
  API-->>UI: { url } of generated HTML
  UI-->>U: Open generated template
  U->>UI: Send email (to, subject)
  UI->>API: POST /templates/:id/send
  API-->>UI: Log entry (status "logged")
Loading

Features

  • Several templates, each with its own tree and elements, listed on one page
  • Send a template to a list of addresses; sent emails are kept in a log you can browse (delivery itself is not connected yet)
  • Add a root element and grow a template tree
  • Context menu on each node: add, edit, delete
  • Live preview of the email next to the AI assistant
  • Template tree and element library in collapsible panels for manual edits
  • Elements library with create, edit, and delete
  • One-click generate that returns a link to the HTML
  • AI assistant that edits the template on request (Gemini, OpenAI or Anthropic, with your own API key)
  • Build an issue from pasted text: the assistant lays the content out in blocks from your element library
  • Ant Design UI
  • Talks to a separate backend (default http://localhost:9000, override with NEXT_PUBLIC_API_URL)

Architecture

flowchart TB
  subgraph Frontend[This repo]
    Page["app/templates/[id]/page.tsx"]
    List[src/templates]
    Sent[src/sent]
    Main[Main.tsx]
    Tree[TemplateTree]
    Elements[Elements]
    Client[src/api/main.ts]
  end
  Page --> Main
  List --> Client
  Sent --> Client
  Main --> Tree
  Main --> Elements
  Main --> Client
  Tree --> Client
  Elements --> Client
  Client --> Backend[(Backend :9000)]
Loading

Getting started

npm install
npm run dev

Open http://localhost:3000 (it redirects to the templates list).

The frontend expects a backend on port 9000. Override the base URL with NEXT_PUBLIC_API_URL.

Scripts

Command Purpose
npm run dev Next.js development server
npm run lint ESLint (Next.js rules + architecture import rules)
npm run typecheck TypeScript check (tsc --noEmit)
npm run format Format with Prettier (format:check runs in CI)
npm test Run Vitest once
npm run test:watch Vitest in watch mode
npm run build Production build
npm start Start the production build locally (Docker runs .next/standalone/server.js)

Docker

docker build --build-arg NEXT_PUBLIC_API_URL=https://api.example.com -t email-template-editor .
docker run -p 3000:3000 email-template-editor

AI assistant

The assistant sits on the left of the editor, next to the preview. Open Settings (or Add key), choose a provider (Google Gemini, OpenAI or Anthropic), paste your own API key, and ask for changes in plain language, e.g. "add a heading that says Welcome under the root". The assistant reads the tree and element library, adds, edits or deletes nodes and elements, and can generate the template. It asks before deleting anything.

Build an issue from text. Paste the issue's content (an intro, a few recipes with titles, links and photos) and ask the assistant to build the email. It picks matching blocks from the element library, fills them with your text and adds them after the current content in one step; the preview updates right away. Ask it to "replace" the content to swap out the current blocks instead (it asks first). It uses only library elements, never new HTML, so the email stays within your approved design. Content that fits no element is listed in the reply, so you know which element to add. The assistant judges elements by their placeholders and HTML, so clear placeholder names ({{image}}, {{link}}, {{title}}) help it choose.

Where your key goes. The key is kept in your browser and sent only to the provider you chose; the editor's backend never sees it. By default it is kept for the current tab (sessionStorage). You can also keep it for the current page only, or remember it on the device (localStorage), and you can remove it at any time in the assistant settings. Any script running on the page, including browser extensions, could read the key, so use a key with a spending limit and revoke it if in doubt. A Content-Security-Policy blocks injected scripts and lets the page talk only to the editor's backend and the LLM providers.

Project layout

app/                    Next.js App Router (layout; /templates, /templates/[id], /sent)
src/
  api/                  Axios client and types
  ai/                   AI assistant: providers, tools, agent loop, key storage
  editor/Main/           Editor UI (tree, elements, forms, AI chat, send dialog)
  templates/            Templates list page
  sent/                 Sent emails log page
  shell/                Sidebar, header and theme
  types/                Shared types
AGENTS.md               Guide for AI coding agents
docs/AI_AGENT.md        Extended agent reference
docs/screenshots/       Screenshots used in this README
.claude/skills/         Claude skills (best practices)

For AI agents

If you are an AI coding agent, read these before changing code:

Related work

  • Migrated from Create React App to Next.js + Vitest in PR #15.
  • Agent documentation and README expansion live in PR #16.

About

No description, website, or topics provided.

Resources

Contributing

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages