Skip to content

Commit 8a41c06

Browse files
Merge pull request #1 from stephanwesten/claude/read-readme-011CUg1iz7CDZJZUN4o9j1pz
Claude/read readme 011 c ug1iz7 cdzjzun4o9j1pz
2 parents f2eec5b + b6f2c80 commit 8a41c06

File tree

9 files changed

+394
-16
lines changed

9 files changed

+394
-16
lines changed

.github/workflows/deploy.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Deploy to Cloudflare Workers
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
workflow_dispatch: # Allow manual triggering
8+
9+
jobs:
10+
deploy:
11+
runs-on: ubuntu-latest
12+
name: Deploy
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
17+
- name: Setup Node.js
18+
uses: actions/setup-node@v4
19+
with:
20+
node-version: '20'
21+
cache: 'npm'
22+
23+
- name: Install dependencies
24+
run: npm ci
25+
26+
- name: Run tests
27+
run: npm test
28+
continue-on-error: true # Continue even if tests fail (for now, since we don't have tests yet)
29+
30+
- name: Deploy to Cloudflare Workers
31+
uses: cloudflare/wrangler-action@v3
32+
with:
33+
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
34+
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}

.gitignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Dependencies
2+
node_modules/
3+
4+
# Wrangler
5+
.wrangler/
6+
.dev.vars
7+
dist/
8+
9+
# TypeScript
10+
*.tsbuildinfo
11+
12+
# Environment variables (local development only)
13+
.env
14+
.env.local
15+
16+
# Editor
17+
.vscode/
18+
.idea/
19+
*.swp
20+
*.swo
21+
22+
# OS
23+
.DS_Store
24+
Thumbs.db

DEPLOYMENT.md

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# Deployment Guide
2+
3+
## Prerequisites
4+
5+
1. **Cloudflare Account**: Sign up at https://dash.cloudflare.com
6+
2. **Node.js**: v20 or higher
7+
3. **Wrangler CLI**: Installed via npm (included in dev dependencies)
8+
9+
## Local Development
10+
11+
### 1. Install Dependencies
12+
13+
```bash
14+
npm install
15+
```
16+
17+
### 2. Configure Local Environment
18+
19+
Create a `.dev.vars` file in the project root for local development:
20+
21+
```bash
22+
PERSONAL_EMAIL=your-personal@example.com
23+
WORK_EMAIL=your-work@example.com
24+
MAILCHANNELS_API_KEY=your-mailchannels-key
25+
PINCODE=your-secret-pincode
26+
FROM_EMAIL=noreply@yourdomain.com
27+
FROM_NAME=MailRelay
28+
```
29+
30+
### 3. Run Locally
31+
32+
```bash
33+
npm run dev
34+
```
35+
36+
Visit `http://localhost:8787` to test locally.
37+
38+
## Production Deployment
39+
40+
### Option 1: GitHub Actions (Automatic)
41+
42+
#### Setup GitHub Secrets
43+
44+
Go to your repository Settings → Secrets and variables → Actions, and add:
45+
46+
1. **CLOUDFLARE_API_TOKEN**
47+
- Go to https://dash.cloudflare.com/profile/api-tokens
48+
- Create token with "Edit Cloudflare Workers" permissions
49+
- Copy and paste into GitHub secret
50+
51+
2. **CLOUDFLARE_ACCOUNT_ID**
52+
- Find at https://dash.cloudflare.com
53+
- Look in the URL or Workers & Pages section
54+
- Copy your Account ID
55+
56+
#### Configure Worker Secrets
57+
58+
Set environment variables in Cloudflare:
59+
60+
```bash
61+
# Using Wrangler CLI locally
62+
wrangler secret put PERSONAL_EMAIL
63+
wrangler secret put WORK_EMAIL
64+
wrangler secret put MAILCHANNELS_API_KEY
65+
wrangler secret put PINCODE
66+
wrangler secret put FROM_EMAIL
67+
wrangler secret put FROM_NAME
68+
```
69+
70+
Or set them in the Cloudflare Dashboard:
71+
- Go to Workers & Pages → mailrelay → Settings → Variables
72+
- Add each secret
73+
74+
#### Deploy
75+
76+
Push to `main` branch:
77+
78+
```bash
79+
git push origin main
80+
```
81+
82+
GitHub Actions will automatically deploy to Cloudflare Workers.
83+
84+
### Option 2: Manual Deployment
85+
86+
```bash
87+
# Build and deploy
88+
npm run deploy
89+
```
90+
91+
## MailChannels Setup
92+
93+
MailRelay uses MailChannels for email delivery. You need:
94+
95+
1. **Domain with SPF/DKIM configured** for MailChannels
96+
2. **MailChannels API access** (free for Cloudflare Workers users)
97+
98+
See: https://blog.cloudflare.com/sending-email-from-workers-with-mailchannels/
99+
100+
## Verification
101+
102+
After deployment:
103+
104+
1. Visit your worker URL (e.g., `https://mailrelay.<your-subdomain>.workers.dev`)
105+
2. You should see "Deployment Test Successful"
106+
3. Test sending an email through the form
107+
108+
## Troubleshooting
109+
110+
### Deployment fails
111+
112+
- Check GitHub Actions logs
113+
- Verify CLOUDFLARE_API_TOKEN has correct permissions
114+
- Verify CLOUDFLARE_ACCOUNT_ID is correct
115+
116+
### Worker runs but emails don't send
117+
118+
- Check MailChannels API key is set correctly
119+
- Verify domain SPF/DKIM records
120+
- Check worker logs in Cloudflare Dashboard
121+
122+
### Local development issues
123+
124+
- Ensure `.dev.vars` file exists with all required variables
125+
- Run `wrangler login` if authentication fails

README.md

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,17 @@ MailRelay is an email relay service built on Cloudflare Workers using MailChanne
1414

1515
### 1. Web Form Interface
1616

17+
- **Pincode Authentication**: Optional URL parameter (`?pincode=xxx`) for bookmarking. If not provided, displays pincode input field
1718
- **Address Toggle**: Switch between personal and work email addresses
18-
- **Subject Field**: Text input for email subject line
19+
- **Subject Field**: Text input for email subject line (required)
1920
- **Message Field**: Textarea for email body/description
2021
- **Submit Button**: Send email via form submission
2122
- **Success/Error Feedback**: Visual confirmation of email delivery status
2223

2324
### 2. REST API
2425

2526
- **POST Endpoint**: `/api/send` for programmatic email sending
26-
- **Authentication**: API key/token for secure access
27+
- **Authentication**: Pincode in request body for simple authentication
2728
- **JSON Payload**: Accepts structured email data
2829
- **Response Codes**: Standard HTTP status codes with error messages
2930

@@ -54,9 +55,9 @@ MailRelay is an email relay service built on Cloudflare Workers using MailChanne
5455
PERSONAL_EMAIL=your-personal@example.com
5556
WORK_EMAIL=your-work@example.com
5657
MAILCHANNELS_API_KEY=xxx
57-
API_AUTH_TOKEN=xxx (for API endpoint security)
58+
PINCODE=your-secret-pincode
5859
FROM_EMAIL=noreply@yourdomain.com
59-
FROM_NAME=MailRally
60+
FROM_NAME=MailRelay
6061
```
6162

6263
-----
@@ -68,14 +69,14 @@ FROM_NAME=MailRally
6869
**Headers:**
6970

7071
```
71-
Authorization: Bearer {API_AUTH_TOKEN}
7272
Content-Type: application/json
7373
```
7474

7575
**Request Body:**
7676

7777
```json
7878
{
79+
"pincode": "string",
7980
"destination": "personal" | "work",
8081
"subject": "string",
8182
"message": "string"
@@ -88,7 +89,9 @@ Content-Type: application/json
8889
{
8990
"success": true,
9091
"message": "Email sent successfully",
91-
"destination": "personal"
92+
"data": {
93+
"destination": "personal"
94+
}
9295
}
9396
```
9497

@@ -97,10 +100,18 @@ Content-Type: application/json
97100
```json
98101
{
99102
"success": false,
100-
"error": "Error message description"
103+
"message": "Error message description",
104+
"data": null
101105
}
102106
```
103107

108+
**Consistent Structure Benefits:**
109+
110+
- Client only needs to check `success` boolean
111+
- `message` always contains human-readable feedback
112+
- `data` contains payload (object on success, null on error)
113+
- Same parsing logic for all responses
114+
104115
-----
105116

106117
## User Interface Design
@@ -112,6 +123,9 @@ Content-Type: application/json
112123
│ MailRelay 📧 │
113124
├─────────────────────────────────────┤
114125
│ │
126+
│ Pincode: [________________] │
127+
│ (hidden if in URL) │
128+
│ │
115129
│ Send To: ( ) Personal ( ) Work │
116130
│ │
117131
│ Subject: [________________] │
@@ -127,17 +141,22 @@ Content-Type: application/json
127141
└─────────────────────────────────────┘
128142
```
129143

144+
**Pincode URL Parameter**: Users can bookmark `/?pincode=xxx` to skip entering pincode each time.
145+
130146
Error feedback is crucial. log all information and print all information except for sensitive information like keys to make debugging easier.
131147
In the API return in the response an error message with as much information as possible.
132148
-----
133149

134150
## Security Considerations
135151

136-
- API authentication via Bearer token
137-
- Rate limiting to prevent abuse
138-
- Input validation and sanitization
139-
- CORS configuration for API access
140-
- Environment variables for sensitive data (never in code)
152+
- **Simple Pincode Authentication**: Pincode compared against `PINCODE` environment variable
153+
- Can be passed as URL parameter `?pincode=xxx` for web form bookmarking
154+
- Required in API request body
155+
- Not highly secure, but sufficient for personal use MVP
156+
- **Input Validation**: Validate and sanitize all user inputs
157+
- **CORS Configuration**: Configure appropriate CORS headers for API access
158+
- **Environment Variables**: Store all sensitive data (emails, pincode, API keys) in environment variables, never in code
159+
- **No Rate Limiting**: Intentionally omitted for MVP simplicity (add later if needed)
141160

142161
-----
143162

@@ -169,9 +188,8 @@ In the API return in the response an error message with as much information as p
169188
170189
**Questions to finalize:**
171190
172-
1. Do you want TypeScript or JavaScript? depends, typescript requires compilation, but is type safe. depends on github actions.
173-
1. Any specific styling preferences (minimal, modern, colorful)? minimal but modern.
174-
1. Should the form have validation (required fields, max length)? Title is required.
191+
1. Do you want TypeScript or JavaScript? depends, typescript requires compilation, but is type safe. depends on github actions.
192+
1. Any specific styling preferences (minimal, modern, colorful)? minimal but modern.
193+
1. Should the form have validation (required fields, max length)? Subject is required.
175194
1. Do you want email confirmation/receipts? no
176-
1. Rate limiting: how many emails per hour/day? 5
177195

claude.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Development Guidelines for MailRelay
2+
3+
## Development Methodology
4+
5+
This project follows **Test-Driven Development (TDD)** and **Extreme Programming (XP)** practices.
6+
7+
### Test-Driven Development (TDD)
8+
9+
Follow the Red-Green-Refactor cycle:
10+
11+
1. **Red**: Write a failing test first
12+
2. **Green**: Write minimal code to make the test pass
13+
3. **Refactor**: Improve code while keeping tests green
14+
15+
#### TDD Principles
16+
17+
- Write tests before implementation code
18+
- Tests should be small, focused, and fast
19+
- Each test should verify one behavior
20+
- All code must have corresponding tests
21+
- Run tests frequently during development
22+
23+
### Extreme Programming (XP) Practices
24+
25+
#### Core Practices
26+
27+
- **Simple Design**: Implement the simplest solution that works
28+
- **Refactoring**: Continuously improve code structure
29+
- **Continuous Integration**: Integrate and test code frequently
30+
- **Small Releases**: Deploy small, incremental changes
31+
- **Collective Code Ownership**: Any developer can improve any part of the code
32+
33+
#### Coding Standards
34+
35+
- Write clear, self-documenting code
36+
- Follow consistent naming conventions
37+
- Keep functions small and focused
38+
- DRY (Don't Repeat Yourself)
39+
- YAGNI (You Aren't Gonna Need It) - don't add functionality until needed
40+
41+
### Testing Strategy
42+
43+
#### Unit Tests
44+
45+
- Test individual functions and modules in isolation
46+
- Mock external dependencies (MailChannels API, environment variables)
47+
- Fast execution (milliseconds)
48+
49+
#### Integration Tests
50+
51+
- Test API endpoints end-to-end
52+
- Test web form submission flow
53+
- Verify error handling and edge cases
54+
55+
#### Test Coverage Goals
56+
57+
- Aim for >80% code coverage
58+
- 100% coverage for critical paths (email sending, authentication)
59+
- All error handlers must be tested
60+
61+
### Development Workflow
62+
63+
1. Create a failing test for new feature/bugfix
64+
2. Write minimal code to pass the test
65+
3. Refactor if needed
66+
4. Run full test suite
67+
5. Commit with descriptive message
68+
6. Push and deploy via CI/CD
69+
70+
### Tools
71+
72+
- **Testing Framework**: Vitest (or Jest)
73+
- **Mocking**: Built-in test framework mocks
74+
- **CI/CD**: GitHub Actions
75+
- **Code Quality**: ESLint, Prettier
76+
77+
---
78+
79+
**Remember**: If it's not tested, it's broken.

0 commit comments

Comments
 (0)