Skip to content

Commit e286306

Browse files
committed
feat(email): Implement email service with SMTP configuration, template rendering, and example usage
- Added EmailService class for sending emails using nodemailer with support for templates. - Implemented TemplateRenderer for rendering email templates using Pug. - Created various email templates: welcome, password reset, and notification. - Added example usage functions for sending different types of emails. - Included validation for email templates and SMTP configuration. - Established a structured approach for handling email attachments and recipients. - Introduced TypeScript types and Zod schemas for type safety and validation.
1 parent f29abcf commit e286306

File tree

17 files changed

+2323
-32
lines changed

17 files changed

+2323
-32
lines changed

package-lock.json

Lines changed: 307 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

services/backend/Mail.md

Lines changed: 632 additions & 0 deletions
Large diffs are not rendered by default.

services/backend/README.md

Lines changed: 100 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ A modular and extensible backend API for the DeployStack CI/CD platform, built w
77
- **High-performance**: Built on Fastify for optimal speed and efficiency
88
- **Type-safe**: Written in TypeScript for better development experience
99
- **Modular**: Well-organized code structure for maintainability
10+
- **Email System**: Integrated email service with Pug templates and SMTP support
11+
- **Global Settings**: Centralized configuration management with encryption
12+
- **Database Integration**: SQLite/PostgreSQL support with Drizzle ORM
13+
- **Plugin System**: Extensible architecture for custom functionality
14+
- **Authentication**: Lucia-based authentication with role management
1015
- **Logging**: Comprehensive request logging with request IDs and timing
1116
- **Developer-friendly**: Pretty logging in development, production-ready in production
1217

@@ -59,22 +64,68 @@ npm run lint
5964
```bash
6065
services/backend/
6166
├── src/
62-
│ ├── config/ # Configuration files
63-
│ │ └── logger.ts # Logger configuration
64-
│ ├── hooks/ # Fastify hooks
65-
│ │ └── request-logger.ts # Request logging hooks
66-
│ ├── plugins/ # Fastify plugins
67-
│ │ └── index.ts # Plugin registration
68-
│ ├── routes/ # API routes
69-
│ │ └── index.ts # Route definitions
67+
│ ├── api/ # API route handlers
68+
│ ├── db/ # Database configuration and schema
69+
│ │ ├── config.ts # Database connection setup
70+
│ │ ├── index.ts # Database exports
71+
│ │ ├── migrations.ts # Migration management
72+
│ │ └── schema.ts # Database schema definitions
73+
│ ├── email/ # Email system (NEW)
74+
│ │ ├── templates/ # Pug email templates
75+
│ │ │ ├── layouts/ # Base layout components
76+
│ │ │ │ ├── base.pug # Main email layout
77+
│ │ │ │ ├── header.pug # Email header
78+
│ │ │ │ └── footer.pug # Email footer
79+
│ │ │ ├── welcome.pug # Welcome email template
80+
│ │ │ ├── password-reset.pug # Password reset template
81+
│ │ │ └── notification.pug # General notification template
82+
│ │ ├── emailService.ts # Main email service
83+
│ │ ├── templateRenderer.ts # Pug template renderer
84+
│ │ ├── types.ts # Email type definitions
85+
│ │ ├── example.ts # Usage examples
86+
│ │ └── index.ts # Email module exports
87+
│ ├── fastify/ # Fastify configuration
88+
│ │ ├── config/ # Fastify setup
89+
│ │ ├── hooks/ # Request/response hooks
90+
│ │ └── plugins/ # Fastify plugins
91+
│ ├── global-settings/ # Global configuration system
92+
│ │ ├── github-oauth.ts # GitHub OAuth settings
93+
│ │ ├── smtp.ts # SMTP email settings
94+
│ │ ├── types.ts # Global settings types
95+
│ │ └── index.ts # Settings initialization
96+
│ ├── hooks/ # Authentication hooks
97+
│ ├── lib/ # External library integrations
98+
│ │ └── lucia.ts # Lucia authentication setup
99+
│ ├── middleware/ # Request middleware
100+
│ ├── plugin-system/ # Plugin architecture
101+
│ ├── plugins/ # Available plugins
102+
│ ├── routes/ # API route definitions
103+
│ │ ├── auth/ # Authentication routes
104+
│ │ ├── db/ # Database management routes
105+
│ │ ├── globalSettings/ # Settings management routes
106+
│ │ ├── roles/ # Role management routes
107+
│ │ └── users/ # User management routes
108+
│ ├── services/ # Business logic services
109+
│ │ ├── globalSettingsService.ts # Settings service
110+
│ │ ├── roleService.ts # Role management
111+
│ │ ├── teamService.ts # Team management
112+
│ │ └── userService.ts # User management
70113
│ ├── types/ # TypeScript type definitions
71-
│ │ └── fastify.ts # Fastify type extensions
72114
│ ├── utils/ # Utility functions
73-
│ │ └── banner.ts # Startup banner
115+
│ │ ├── banner.ts # Startup banner
116+
│ │ └── encryption.ts # Encryption utilities
74117
│ ├── server.ts # Server configuration
75118
│ └── index.ts # Application entry point
119+
├── drizzle/ # Database migrations
120+
├── persistent_data/ # Persistent application data
121+
├── tests/ # Test files
76122
├── .env # Environment variables (not in version control)
77-
├── .eslintrc # ESLint configuration
123+
├── DB.md # Database documentation
124+
├── GLOBAL_SETTINGS.md # Global settings documentation
125+
├── Mail.md # Email system documentation (NEW)
126+
├── PLUGINS.md # Plugin system documentation
127+
├── ROLES.md # Role management documentation
128+
├── SECURITY.md # Security documentation
78129
├── package.json # Package dependencies and scripts
79130
└── tsconfig.json # TypeScript configuration
80131
```
@@ -95,6 +146,43 @@ The `services/backend/persistent_data/` directory is designated for storing all
95146

96147
This ensures that persistent data is managed in a predictable way and is not scattered across the project.
97148

149+
## 📧 Email System
150+
151+
DeployStack includes a comprehensive email system with Pug templates and SMTP integration:
152+
153+
### Quick Start
154+
155+
```typescript
156+
import { EmailService } from './src/email';
157+
158+
// Send a welcome email
159+
await EmailService.sendWelcomeEmail({
160+
161+
userName: 'John Doe',
162+
userEmail: '[email protected]',
163+
loginUrl: 'https://app.deploystack.com/login'
164+
});
165+
166+
// Send a notification
167+
await EmailService.sendNotificationEmail({
168+
169+
title: 'Deployment Complete',
170+
message: 'Your app has been deployed successfully.'
171+
});
172+
```
173+
174+
### Configuration
175+
176+
1. Configure SMTP settings in the global settings interface
177+
2. Required settings: `smtp.host`, `smtp.port`, `smtp.username`, `smtp.password`
178+
3. Optional settings: `smtp.secure`, `smtp.from_name`, `smtp.from_email`
179+
180+
### Documentation
181+
182+
- **[Mail.md](./Mail.md)**: Complete email system documentation
183+
- **Templates**: Located in `src/email/templates/`
184+
- **Examples**: See `src/email/example.ts` for usage examples
185+
98186
## 🌍 Environment Variables
99187

100188
Create a `.env` file in the `services/backend` directory with the following variables:
@@ -103,7 +191,7 @@ Create a `.env` file in the `services/backend` directory with the following vari
103191
NODE_ENV=development
104192
PORT=3000
105193
LOG_LEVEL=debug
106-
FOO=bar # Example environment variable used in the demo route
194+
DEPLOYSTACK_ENCRYPTION_SECRET=your-32-character-secret-key-here # Required for global settings encryption
107195
```
108196

109197
## 🤝 Contributing

services/backend/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@
2323
"fastify": "^5.3.3",
2424
"fastify-favicon": "^5.0.0",
2525
"lucia": "^3.2.2",
26+
"nodemailer": "^6.9.8",
2627
"pino": "^9.7.0",
2728
"pino-pretty": "^13.0.0",
29+
"pug": "^3.0.2",
2830
"zod": "^3.25.42"
2931
},
3032
"devDependencies": {
@@ -35,6 +37,8 @@
3537
"@types/better-sqlite3": "^7.6.13",
3638
"@types/fs-extra": "^11.0.4",
3739
"@types/jest": "^29.5.14",
40+
"@types/nodemailer": "^6.4.14",
41+
"@types/pug": "^2.0.10",
3842
"@types/supertest": "^6.0.3",
3943
"@typescript-eslint/eslint-plugin": "^8.33.0",
4044
"@typescript-eslint/parser": "^8.33.0",

0 commit comments

Comments
 (0)