A sophisticated email template management system with rich features for creating, editing, and managing dynamic email templates. Built with Next.js, React, TipTap rich text editor, and Prisma ORM with PostgreSQL.
- Rich Text Editing: Advanced WYSIWYG editor powered by TipTap with comprehensive formatting options
- Dynamic Variables: Insert and manage template variables with live preview functionality
- Responsive Design Testing: Preview emails in desktop and mobile views
- Email Components: Ready-made components for tables, social links, and structured sections
- Content Management: Create, save, edit, and organize templates with folder organization
- Background & Layout Editor: Customize email structure with visual background editor
- Header & Footer Management: Consistent branding with reusable headers and footers
- Export Options: Multiple export formats including HTML and variable schemas
- Database Integration: PostgreSQL with Prisma ORM for reliable storage and retrieval
- Frontend Framework: Next.js 15 with App Router
- UI Library: React 19
- Component Library: Ant Design
- Rich Text Editor: TipTap with custom extensions
- Styling: TailwindCSS 4
- Database ORM: Prisma 6
- Database: PostgreSQL
- State Management: React Hooks (useState, useEffect, useCallback)
- TypeScript: Type-safe development throughout the application
- Node.js (v18.0.0 or higher)
- PostgreSQL database server (v14 or higher)
- npm or yarn
-
Clone the repository:
git clone https://github.com/billowdev/email-management.git cd email-management
-
Install dependencies:
npm install # or yarn install
-
Set up environment variables:
# Copy the sample env file and update with your database credentials cp env-sample .env
-
Configure your database connection in
.env
:DATABASE_URL="postgresql://username:password@localhost:5432/email_management?schema=public"
-
Generate Prisma client and run migrations:
npx prisma generate npx prisma migrate dev
-
Seed the database with initial data:
npm run seed # or yarn seed
-
Start the development server:
npm run dev # or yarn dev
-
Access the application at
http://localhost:3000
email-management/
βββ prisma/ # Prisma schema and migrations
β βββ schema.prisma # Database schema definition
β βββ migrations/ # Database migrations
β βββ seed.ts # Database seeding script
βββ src/
β βββ app/ # Next.js app router pages
β β βββ api/ # API routes for templates, variables, etc.
β β βββ page.tsx # Main page (template editor)
β β βββ email-preview/ # Email preview page
β βββ components/ # React components
β β βββ editor/ # Template editor components
β β β βββ sections/ # Email section components (tables, social links)
β β β βββ variables/ # Variable management components
β β β βββ background/ # Background editor components
β β β βββ header-footer/# Header and footer components
β β βββ pages/ # Page-level components
β βββ lib/ # Utility libraries
β β βββ prisma.ts # Prisma client setup
β βββ services/ # Business logic and API services
β β βββ emailTemplateService.ts # Template-related services
β β βββ emailBackgroundService.ts # Background-related services
β β βββ exportService.ts # Export functionality
β βββ types/ # TypeScript type definitions
β βββ email-templates.ts # Email template related types
β βββ prisma.ts # Prisma-related type extensions
βββ next.config.ts # Next.js configuration
The main dashboard for managing templates. Handles template selection, creation, saving, and deletion.
The primary editor component integrating TipTap for rich text editing and providing various tools for template customization.
Renders the email template with variables replaced and allows for testing with different screen sizes.
Controls the layout, backgrounds, and structure of the email template.
Creates and manages email-compatible tables with customization options.
Inserts and configures social media links with various styling options.
Inserts pre-designed sections like buttons, dividers, headers, and spacers.
The application uses a PostgreSQL database with the following key models:
Stores the email template information, content, and relationships.
Defines the variables that can be used within a template.
Stores sample data for template previews.
Stores styling information for the email template.
Stores header and footer settings for email templates.
See prisma/schema.prisma
for the complete database schema.
-
Creating a Template:
- Use the template creation form at the top of the main page
- Default variables like
firstName
,lastName
, andemail
are automatically added
-
Editing Content:
- Use the rich text editor with the toolbar for formatting
- Insert variables using the variable panel on the right
- Add special components like tables and social links using the toolbar
-
Adding Variables:
- Click "Add New Variable" in the variable panel
- Variables are automatically available in the editor as
{{.variableName}}
-
Customizing Layout:
- Switch to the "Preview & Layout" tab
- Adjust background colors, container widths, and spacing
- Configure headers and footers with logos, text, and styling
-
Testing Templates:
- Use "Preview Mode" to see how the template looks with variables filled in
- Click "Full Page Preview" for a dedicated preview page
- Test responsive behavior using the mobile/desktop toggle
-
Exporting Templates:
- Use the Export dropdown to export in various formats
- Options include complete template, content only, or variables schema
Use the API endpoints in src/app/api/
to:
- Create, read, update, and delete templates
- Manage template variables
- Save and retrieve background and header/footer settings
When developing new features, follow these patterns to maintain consistency.
-
Create a new component in
src/components/editor/sections/
:// src/components/editor/sections/NewComponent.tsx import React from 'react'; import { Editor } from '@tiptap/react'; import { Button } from 'antd'; interface NewComponentProps { editor: Editor | null; } const NewComponent: React.FC<NewComponentProps> = ({ editor }) => { const insertContent = () => { if (!editor) return; editor.chain().focus().insertContent('<div>New component content</div>').run(); }; return <Button onClick={insertContent}>Insert New Component</Button>; }; export default NewComponent;
-
Add the component to the EmailTemplateEditor toolbar.
- Update the
VariableType
enum inprisma/schema.prisma
- Generate and run a migration
- Update the variable type options in the variable creation/edit components
- Fork the repository
- Create a feature branch (
git checkout -b feature/my-feature
) - Make your changes
- Run linting and ensure all checks pass
- Commit your changes with descriptive messages
- Push to your fork and submit a pull request
- Verify your PostgreSQL server is running
- Check your connection string in the
.env
file - Run
npx prisma db push
to sync the schema
- Check browser console for errors
- Verify TipTap extensions are properly configured
- Ensure your Node.js version is compatible
- Check for syntax errors in the export service
- Verify the template HTML structure
- Test with different browser environments
For questions or support, please open an issue on the repository.