A production-ready backend server for the Job Swiper application built with Hono (TypeScript), Drizzle ORM, and PostgreSQL.
β οΈ Repository Naming Note: This repository is namedjob-swipper-server(with double 'p'), while the client repository isjob-swiper(single 'p'). This naming inconsistency is historical and does not affect functionality.
- Framework: Hono (TypeScript)
- ORM: Drizzle ORM
- Database: PostgreSQL (Neon-compatible)
- Authentication: JWT with email/password, Google OAuth, GitHub OAuth
- File Storage: S3-compatible (Cloudflare R2, AWS S3)
- PDF Generation: PDFKit for export functionality
- Validation: Zod for request/response validation
- Logging: Pino for structured JSON logging
- Deployment: Vercel serverless
- β 96 RESTful API endpoints for comprehensive job management
- β Job Swiper functionality (accept, reject, skip, save, rollback)
- β Application Tracking with 12 customizable stages
- β AI-powered Document Generation (resumes & cover letters via microservices)
- β Email Integration with OAuth (Gmail, Outlook, Yahoo) and IMAP support
- β Real-time Notifications via Server-Sent Events (SSE)
- β Advanced Filtering (search, location, salary range)
- β Export Functionality (CSV, PDF)
- β Audit Logging for all user actions
- β Rate Limiting (100 requests/minute per user)
- β GDPR Compliance (data export & account deletion)
- β Automated Job Scraping via cron (every 2 hours)
- Node.js 18+
- PostgreSQL 14+
- npm or yarn
- Clone the repository:
git clone https://github.com/aliassar/job-swiper-server.git
cd job-swiper-server- Install dependencies:
npm install- Set up environment variables:
cp .env.example .envEdit .env with your configuration:
DATABASE_URL=postgresql://user:password@localhost:5432/job_swiper
JWT_SECRET=your-secure-secret-key
JWT_EXPIRES_IN=7d
PORT=5000- Run database migrations:
npm run db:migrate- Start the development server:
npm run devThe server will be available at http://localhost:5000.
This backend is designed to work with the job-swiper frontend.
- In the frontend repository, set the environment variable:
NEXT_PUBLIC_API_URL=http://localhost:5000- The frontend will automatically use this URL for all API requests.
| Category | Endpoints | Description |
|---|---|---|
| Auth | /api/auth/* |
Login, register, token refresh |
| Jobs | /api/jobs/* |
Job listing, accept, reject, skip |
| Applications | /api/applications/* |
Application tracking and management |
| Notifications | /api/notifications/* |
User notifications |
| Settings | /api/settings |
User preferences |
See docs/API.md for full API documentation.
- Frontend: aliassar/job-swiper - Next.js frontend
- Backend (this repo): Hono.js API server with PostgreSQL
# Run in development mode with hot reload
npm run dev
# Run tests
npm test
# Generate new migration
npm run db:generate
# Apply migrations
npm run db:migratejob-swipper-server/
βββ src/
β βββ db/
β β βββ migrations/ # Database migrations
β β βββ schema.ts # Drizzle schema definitions
β β βββ seed.ts # Database seeding
β βββ lib/
β β βββ audit.ts # Audit logging utilities
β β βββ db.ts # Database connection
β β βββ email-client.ts # Email client utilities
β β βββ encryption.ts # Encryption utilities
β β βββ errors.ts # Custom error classes
β β βββ microservice-client.ts # Microservice communication
β β βββ storage.ts # S3 storage utilities
β β βββ utils.ts # Helper functions
β βββ middleware/
β β βββ auth.ts # JWT authentication
β β βββ error-handler.ts # Global error handler
β β βββ logger.ts # Request logging
β β βββ rate-limit.ts # Rate limiting
β β βββ request-id.ts # Request ID generation
β βββ routes/
β β βββ admin.ts # Admin endpoints
β β βββ applications.ts # Application management
β β βββ auth.ts # Authentication
β β βββ cover-letters.ts # Cover letter management
β β βββ email-connections.ts # Email OAuth/IMAP
β β βββ generation.ts # AI document generation
β β βββ history.ts # Action history
β β βββ jobs.ts # Job swiping
β β βββ notifications.ts # Notifications
β β βββ reported.ts # Reported jobs
β β βββ resumes.ts # Resume management
β β βββ saved.ts # Saved jobs
β β βββ settings.ts # User settings
β β βββ sync.ts # Job sync (cron)
β β βββ user-profile.ts # User profile
β β βββ users.ts # User data management
β β βββ webhooks.ts # Webhook handlers
β βββ services/
β β βββ application.service.ts
β β βββ auth.service.ts
β β βββ cover-letter.service.ts
β β βββ email-connection.service.ts
β β βββ generation.service.ts
β β βββ job.service.ts
β β βββ notification.service.ts
β β βββ resume.service.ts
β β βββ scraper.service.ts
β β βββ workflow.service.ts
β βββ types/
β β βββ index.ts # TypeScript type definitions
β βββ index.ts # Application entry point
βββ .env.example # Environment variables template
βββ drizzle.config.ts # Drizzle ORM configuration
βββ package.json # Dependencies and scripts
βββ tsconfig.json # TypeScript configuration
βββ vercel.json # Vercel deployment config
POST /api/auth/register- Email/password registrationPOST /api/auth/login- Email/password loginPOST /api/auth/verify-email- Verify email with tokenPOST /api/auth/forgot-password- Request password resetPOST /api/auth/reset-password- Reset password with tokenGET /api/auth/google- Initiate Google OAuthGET /api/auth/google/callback- Google OAuth callbackGET /api/auth/github- Initiate GitHub OAuthGET /api/auth/github/callback- GitHub OAuth callbackPOST /api/auth/logout- Logout (client-side token removal)GET /api/auth/me- Get current user info
GET /api/jobs- Get pending jobs with filters- Query params:
search,limit,location,salaryMin,salaryMax
- Query params:
GET /api/jobs/filters- Get blocked companies listGET /api/jobs/skipped- Get skipped jobs (paginated)- Query params:
page,limit,search
- Query params:
POST /api/jobs/:id/accept- Accept job and create applicationPOST /api/jobs/:id/reject- Reject jobPOST /api/jobs/:id/skip- Skip job temporarilyPOST /api/jobs/:id/save- Toggle save statusDELETE /api/jobs/:id/save- Unsave a jobPOST /api/jobs/:id/rollback- Rollback previous decisionPOST /api/jobs/:id/report- Report job (reasons:fake,not_interested,dont_recommend_company)POST /api/jobs/:id/unreport- Remove report
GET /api/applications- List applications (paginated)- Query params:
page,limit,search
- Query params:
GET /api/applications/:id- Get application details with job and documentsPUT /api/applications/:id/stage- Update application stage- Stages:
Syncing,CV Check,Message Check,Being Applied,Applied,Interview 1,Next Interviews,Offer,Rejected,Accepted,Withdrawn,Failed
- Stages:
PUT /api/applications/:id/notes- Update application notesGET /api/applications/:id/documents- Get application documents (resume, cover letter)PUT /api/applications/:id/documents- Update custom document URLsPOST /api/applications/:id/cv/confirm- Confirm CV for applicationPOST /api/applications/:id/cv/reupload- Reupload CV (multipart/form-data)POST /api/applications/:id/message/confirm- Confirm cover letter messagePUT /api/applications/:id/message- Update cover letter messageGET /api/applications/:id/download/resume- Download generated resume (redirect to S3)GET /api/applications/:id/download/cover-letter- Download cover letter (redirect to S3)POST /api/applications/:id/toggle-auto-status- Toggle automatic status updates
GET /api/saved- Get saved jobs (paginated)- Query params:
page,limit,search
- Query params:
GET /api/saved/export?format=csv- Export saved jobs to CSVGET /api/saved/export?format=pdf- Export saved jobs to PDF
GET /api/notifications- Get notifications (paginated)- Query params:
page,limit
- Query params:
GET /api/notifications/stream- SSE endpoint for real-time notificationsGET /api/notifications/unread-count- Get unread notification countPOST /api/notifications/:id/read- Mark notification as readPOST /api/notifications/read-all- Mark all notifications as readDELETE /api/notifications/:id- Delete single notificationDELETE /api/notifications- Clear all notifications
GET /api/email-connections- List connected email accountsPOST /api/email-connections/gmail- Start Gmail OAuth flowGET /api/email-connections/gmail/callback- Gmail OAuth callbackPOST /api/email-connections/outlook- Start Outlook OAuth flowGET /api/email-connections/outlook/callback- Outlook OAuth callbackPOST /api/email-connections/yahoo- Start Yahoo OAuth flowGET /api/email-connections/yahoo/callback- Yahoo OAuth callbackPOST /api/email-connections/imap- Add IMAP email connectionDELETE /api/email-connections/:id- Remove email connectionPOST /api/email-connections/:id/test- Test email connectionPOST /api/email-connections/:id/sync- Sync credentials to Stage Updater service
GET /api/settings- Get user settingsPUT /api/settings- Update user settings- Fields:
theme,emailNotifications,pushNotifications,automationStages,autoGenerateResume,autoGenerateCoverLetter,autoGenerateEmail,aiFilteringEnabled
- Fields:
GET /api/user-profile- Get user profilePUT /api/user-profile- Update user profile- Fields:
firstName,lastName,phone,linkedinUrl,address,city,state,zipCode,country
- Fields:
POST /api/user-profile/base-resume- Upload base resume (multipart/form-data)POST /api/user-profile/base-cover-letter- Upload base cover letter (multipart/form-data)DELETE /api/user-profile/base-resume- Remove base resumeDELETE /api/user-profile/base-cover-letter- Remove base cover letter
POST /api/users/me/export- Export all user data (GDPR compliance)DELETE /api/users/me- Delete user account and all data
GET /api/resumes- List uploaded resume filesPOST /api/resumes- Upload resume file (multipart/form-data)GET /api/resumes/:id- Get resume detailsDELETE /api/resumes/:id- Delete resumePATCH /api/resumes/:id/primary- Set resume as primaryPATCH /api/resumes/:id/reference- Set resume as reference
GET /api/cover-letters- List uploaded cover lettersGET /api/cover-letters/:id- Get cover letter detailsPATCH /api/cover-letters/:id/reference- Set cover letter as reference
POST /api/jobs/:id/generate/resume- Generate tailored resume for job- Body:
{ baseResumeId: "uuid" }
- Body:
POST /api/jobs/:id/generate/cover-letter- Generate cover letter for jobGET /api/generated/resumes- List generated resumesGET /api/generated/cover-letters- List generated cover lettersGET /api/generated/resumes/:id/download- Download generated resumeGET /api/generated/cover-letters/:id/download- Download generated cover letter
GET /api/history- Get action history (last 100 actions)GET /api/reported- Get reported jobs (paginated)- Query params:
page,limit,search
- Query params:
GET /api/application-history- Get application history with filters- Query params:
startDate,endDate,search,stage,page,limit
- Query params:
GET /api/application-history/export?format=csv- Export application history to CSVGET /api/application-history/export?format=pdf- Export application history to PDF
POST /api/email/sync- Trigger email syncGET /api/email/status- Get email sync status
POST /api/admin/normalize-salaries- Batch normalize salary dataGET /api/admin/health- Health check endpoint
POST /api/sync- Trigger job scraping sync (no auth for cron)GET /api/sync/status- Get last sync status
POST /api/webhooks/status-update- Receive application status updates from Stage UpdaterPOST /api/webhooks/generation-complete- Receive AI generation completion callbacksPOST /api/webhooks/application-submitted- Receive application submission confirmations
GET /api/health- Basic health check
Applications flow through the following stages:
| Stage | Description |
|---|---|
| Syncing | Initial stage when application is created |
| CV Check | Resume is being reviewed/verified by user |
| Message Check | Cover letter is being reviewed/verified by user |
| Being Applied | Application is in progress of being submitted |
| Applied | Application has been successfully submitted |
| Interview 1 | First interview scheduled/completed |
| Next Interviews | Additional interview rounds |
| Offer | Job offer received |
| Rejected | Application was rejected by employer |
| Accepted | Job offer accepted |
| Withdrawn | Application withdrawn by user |
| Failed | Application submission failed |
The server integrates with multiple microservices for extended functionality:
| Service | Purpose | Environment Variables |
|---|---|---|
| Scraper | Job scraping from various sources | SCRAPER_SERVICE_URL, SCRAPER_SERVICE_KEY |
| Resume AI | AI-powered resume generation | RESUME_AI_SERVICE_URL, RESUME_AI_SERVICE_KEY |
| Cover Letter AI | AI-powered cover letter generation | COVER_LETTER_AI_SERVICE_URL, COVER_LETTER_AI_SERVICE_KEY |
| Stage Updater | Email monitoring for application status updates | STAGE_UPDATER_SERVICE_URL, STAGE_UPDATER_SERVICE_KEY |
| Job Filter | AI-based job filtering | JOB_FILTER_SERVICE_URL |
| Application Sender | Automated application submission | APPLICATION_SENDER_SERVICE_URL |
All endpoints return standardized JSON responses:
{
"success": true,
"data": {
// Response data
},
"meta": {
"requestId": "req_abc123",
"timestamp": "2024-01-01T00:00:00.000Z"
}
}{
"success": false,
"error": {
"code": "VALIDATION_ERROR",
"message": "Invalid request body",
"details": [
{
"field": "email",
"message": "Invalid email format"
}
]
},
"meta": {
"requestId": "req_abc123",
"timestamp": "2024-01-01T00:00:00.000Z"
}
}{
"success": true,
"data": {
"items": [...],
"pagination": {
"page": 1,
"limit": 20,
"total": 100,
"totalPages": 5
}
},
"meta": {
"requestId": "req_abc123",
"timestamp": "2024-01-01T00:00:00.000Z"
}
}See .env.example for a complete list of environment variables with detailed documentation.
DATABASE_URL- PostgreSQL connection stringJWT_SECRET- Secret for JWT token signing (generate with:openssl rand -base64 32)S3_BUCKET- S3 bucket name for file storageS3_REGION- S3 region (e.g.,us-east-1orautofor Cloudflare R2)S3_ACCESS_KEY- S3 access key IDS3_SECRET_KEY- S3 secret access keyS3_ENDPOINT- S3 endpoint URL
ALLOWED_ORIGINS- Comma-separated list of frontend URLs allowed to make CORS requests- Example:
https://app.yourdomain.com,https://staging.yourdomain.com - Critical: Your frontend URL must be listed here or requests will be blocked
- Example:
FRONTEND_URL- Base URL of your frontend (used for OAuth redirects)NEXTAUTH_URL- Base URL of this API server (used for OAuth callbacks)
- OAuth Providers:
GOOGLE_CLIENT_ID,GOOGLE_CLIENT_SECRET,GITHUB_CLIENT_ID,GITHUB_CLIENT_SECRET - Email Features:
SMTP_HOST,SMTP_PORT,SMTP_USER,SMTP_PASS,FROM_EMAIL - Email Connections:
ENCRYPTION_KEY,GMAIL_CLIENT_ID,OUTLOOK_CLIENT_ID,YAHOO_CLIENT_ID - Microservices: Various service URLs and API keys (see
.env.example) - Security:
ADMIN_API_KEY,WEBHOOK_SECRET,CRON_SECRET
For complete documentation and examples, see .env.example.
The server uses CORS middleware to control which frontend origins can access the API.
ALLOWED_ORIGINS=http://localhost:3000# Single frontend
ALLOWED_ORIGINS=https://app.yourdomain.com
# Multiple environments
ALLOWED_ORIGINS=https://app.yourdomain.com,https://staging.yourdomain.comImportant CORS Notes:
- π¨ Frontend URL must be in
ALLOWED_ORIGINSor requests will be blocked - β
Use exact URLs with protocol (e.g.,
https://app.yourdomain.com) - β No trailing slashes
- β Separate multiple origins with commas (no spaces)
- β Do NOT use wildcards (
*) in production
If your frontend gets CORS errors:
- Check that
ALLOWED_ORIGINSincludes your frontend URL - Ensure the URL matches exactly (including
https://) - Restart the server after changing environment variables
- Clear browser cache (CORS headers can be cached)
For detailed production deployment instructions, see docs/DEPLOYMENT.md.
# Install Vercel CLI
npm i -g vercel
# Deploy
vercel deploy
# Deploy to production
vercel --prod- β Set up PostgreSQL database (Neon recommended)
- β Configure S3-compatible storage (Cloudflare R2 recommended)
- β
Generate secure secrets (
JWT_SECRET,ADMIN_API_KEY, etc.) - β Configure all required environment variables in your deployment platform
- β
Set
ALLOWED_ORIGINSto include your frontend URL(s) - β
Run database migrations:
npm run db:push - β Set up OAuth applications if using Google/GitHub login
- β Configure SMTP if using email/password registration
- β
Test health check endpoint:
GET https://api.yourdomain.com/ - β Verify CORS by testing API calls from your frontend
Important: OAuth authentication (Google/GitHub login) is handled by THIS server, not the frontend.
OAuth Flow:
- Frontend redirects user to:
GET /api/auth/googleorGET /api/auth/github - Server handles OAuth with provider
- Server redirects back to frontend with JWT token
- Frontend stores JWT and uses it for API requests
Required Settings:
- Set
NEXTAUTH_URLto your API server URL (e.g.,https://api.yourdomain.com) - Set
FRONTEND_URLto your frontend URL (e.g.,https://app.yourdomain.com) - Configure OAuth callback URLs in provider settings:
- Google:
${NEXTAUTH_URL}/api/auth/google/callback - GitHub:
${NEXTAUTH_URL}/api/auth/github/callback
- Google:
See docs/DEPLOYMENT.md for complete deployment guide.
- π JWT Authentication with configurable expiration
- π Password Hashing with bcrypt
- π Email Credential Encryption using AES-256
- π Rate Limiting (100 req/min per user)
- π Request ID Tracking for audit trails
- π Webhook Signature Verification
- π CORS Protection
- π SQL Injection Prevention via Drizzle ORM
- π Input Validation with Zod schemas
- docs/API.md - Complete API reference with request/response examples for all 96 endpoints
- docs/DEPLOYMENT.md - Production deployment guide with environment setup, CORS configuration, and troubleshooting
- docs/WORKFLOW.md - Application workflow processes and stage transitions
- MICROSERVICE_IMPLEMENTATION.md - Microservice integration details
- SECURE_CREDENTIALS.md - Credential handling and encryption documentation
- .env.example - Comprehensive environment variable documentation with required/optional markers
MIT