Overview
The backend is a Node.js Express 4 server written in JavaScript (with TypeScript types available) that serves both the API and static frontend files.Server Entry Point
- Express app with CORS enabled
- Prisma client for database access
- Resend client for email delivery
- JSON body parser with 1MB limit
- ESM module syntax (
import/export)
Middleware
Rate Limiters
- Login Limiter
- Contact Limiter
POST /api/auth/loginLimits: 5 attempts per 15 minutes per IPAuthentication Middleware
- Accepts token from
Authorization: Bearer <token>header OR?token=query parameter - Verifies JWT signature using
JWT_SECRETenv var - Adds
userIdto request object for downstream handlers - Returns 401 for missing/invalid tokens
Utility Functions
HTML Escaping
Email Validation
API Routes
Authentication Routes
Project Routes
Contact Route
Admin Email Preview Routes
Email System
Email Templates
Two HTML email templates are defined inline inserver.js:
- Notification Email
- Confirmation Email
Sent to: André (contato@andreruperto.dev)Purpose: Notify about new contact form submissionFunction: See
buildNotificationEmail({ name, email, subject, message })Features:- Dark theme matching portfolio design
- Gradient orange header
- Displays all form fields with labels
- Safe HTML escaping
- Reply-to header set to user’s email
backend/src/server.js:79-158 for full template.Resend Integration
- Domain:
andreruperto.dev - From addresses:
Portfolio <contato@...>,André Ruperto <contato@...> - API key stored in
RESEND_API_KEYenv var
Static File Serving
- API routes are checked first (defined before
*route) - Static files served from
backend/dist/(Vite build output) - All unmatched routes return
index.htmlfor client-side routing
Server Startup
- Port: 3001
- Environment: development
- Logs startup info to console
Environment Variables
Required:DATABASE_URL- PostgreSQL connection stringRESEND_API_KEY- Resend email service API keyADMIN_PASSWORD- Admin login passwordJWT_SECRET- Secret for signing JWT tokens
PORT- Server port (default: 3001)NODE_ENV- Environment mode (development/production)
Error Handling
All async route handlers use try-catch:- Log errors to console
- Return 500 with generic error message
- Never expose internal error details to client
Next Steps
Database Schema
Learn about Prisma models and database structure
API Reference
Complete API endpoint documentation
