Skip to content

Job application tracker and AI-powered job search assistant. Helps job seekers manage their search journey with AI resume review, job matching, task logging, and application analytics, all while keeping your data private.

refactor: replace hardcoded values with APP_CONSTANTS for improved maintainability and consistency

Khuram Niaz997e3d1b79b4
diff --git a/src/app/api/ai/ollama/generate/route.ts b/src/app/api/ai/ollama/generate/route.ts
index 603e95e..82642c4 100644
--- a/src/app/api/ai/ollama/generate/route.ts
+++ b/src/app/api/ai/ollama/generate/route.ts
@@ -1,6 +1,7 @@
import { auth } from "@/auth";
import { getOllamaBaseUrl } from "@/actions/apiKey.actions";
import { NextResponse } from "next/server";
+import { APP_CONSTANTS } from "@/lib/constants";
export async function POST(request: Request) {
try {
@@ -15,7 +16,7 @@ export async function POST(request: Request) {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body),
- signal: AbortSignal.timeout(10000),
+ signal: AbortSignal.timeout(APP_CONSTANTS.AI_OLLAMA_GENERATE_TIMEOUT_MS),
});
if (!response.ok) {
diff --git a/src/app/api/ai/ollama/ps/route.ts b/src/app/api/ai/ollama/ps/route.ts
index 87469db..e0bc8af 100644
--- a/src/app/api/ai/ollama/ps/route.ts
+++ b/src/app/api/ai/ollama/ps/route.ts
@@ -1,6 +1,7 @@
import { auth } from "@/auth";
import { getOllamaBaseUrl } from "@/actions/apiKey.actions";
import { NextResponse } from "next/server";
+import { APP_CONSTANTS } from "@/lib/constants";
export async function GET() {
try {
@@ -11,7 +12,7 @@ export async function GET() {
const baseUrl = await getOllamaBaseUrl();
const response = await fetch(`${baseUrl}/api/ps`, {
- signal: AbortSignal.timeout(5000),
+ signal: AbortSignal.timeout(APP_CONSTANTS.AI_OLLAMA_LIST_TIMEOUT_MS),
});
if (!response.ok) {
diff --git a/src/app/api/ai/ollama/tags/route.ts b/src/app/api/ai/ollama/tags/route.ts
index 95b3849..ea67965 100644
--- a/src/app/api/ai/ollama/tags/route.ts
+++ b/src/app/api/ai/ollama/tags/route.ts
@@ -1,6 +1,7 @@
import { auth } from "@/auth";
import { getOllamaBaseUrl } from "@/actions/apiKey.actions";
import { NextResponse } from "next/server";
+import { APP_CONSTANTS } from "@/lib/constants";
export async function GET() {
try {
@@ -11,7 +12,7 @@ export async function GET() {
const baseUrl = await getOllamaBaseUrl();
const response = await fetch(`${baseUrl}/api/tags`, {
- signal: AbortSignal.timeout(5000),
+ signal: AbortSignal.timeout(APP_CONSTANTS.AI_OLLAMA_LIST_TIMEOUT_MS),
});
if (!response.ok) {
diff --git a/src/app/api/ai/resume/import/route.ts b/src/app/api/ai/resume/import/route.ts
index abda5f9..cdedb2d 100644
--- a/src/app/api/ai/resume/import/route.ts
+++ b/src/app/api/ai/resume/import/route.ts
@@ -7,6 +7,7 @@ import path from "path";
import fs from "fs";
import { getModel } from "@/lib/ai/providers";
import { checkRateLimit } from "@/lib/ai/rate-limiter";
+import { TEMPERATURES } from "@/lib/ai/config";
import { preprocessText } from "@/lib/ai";
import { extractText } from "@/lib/ai/import/extract-text";
import { ResumeImportSchema } from "@/models/resumeImport.schema";
@@ -115,7 +116,7 @@ export const POST = async (req: NextRequest) => {
output: Output.object({ schema: ResumeImportSchema }),
system: RESUME_IMPORT_SYSTEM_PROMPT,
prompt: buildResumeImportPrompt(preprocessResult.data.normalizedText),
- temperature: 0.1,
+ temperature: TEMPERATURES.ANALYSIS,
abortSignal: controller.signal,
}));
} finally {
diff --git a/src/app/api/ai/resume/match/route.ts b/src/app/api/ai/resume/match/route.ts
index 1c12998..2ea66c5 100644
--- a/src/app/api/ai/resume/match/route.ts
+++ b/src/app/api/ai/resume/match/route.ts
@@ -5,6 +5,7 @@ import { NextRequest, NextResponse } from "next/server";
import { streamText, Output } from "ai";
import { getModel } from "@/lib/ai/providers";
import { checkRateLimit } from "@/lib/ai/rate-limiter";
+import { TEMPERATURES } from "@/lib/ai/config";
import {
JobMatchSchema,
JOB_MATCH_SYSTEM_PROMPT,
@@ -104,7 +105,7 @@ export const POST = async (req: NextRequest) => {
}),
system: JOB_MATCH_SYSTEM_PROMPT,
prompt: buildJobMatchPrompt(resumeText, jobText),
- temperature: 0.3,
+ temperature: TEMPERATURES.FEEDBACK,
});
return result.toTextStreamResponse();
diff --git a/src/app/api/ai/resume/review/route.ts b/src/app/api/ai/resume/review/route.ts
index 055ea86..860e572 100644
--- a/src/app/api/ai/resume/review/route.ts
+++ b/src/app/api/ai/resume/review/route.ts
@@ -5,6 +5,7 @@ import { NextRequest, NextResponse } from "next/server";
import { streamText, Output } from "ai";
import { getModel } from "@/lib/ai/providers";
import { checkRateLimit } from "@/lib/ai/rate-limiter";
+import { TEMPERATURES } from "@/lib/ai/config";
import {
ResumeReviewSchema,
RESUME_REVIEW_SYSTEM_PROMPT,
@@ -79,7 +80,7 @@ export const POST = async (req: NextRequest) => {
}),
system: RESUME_REVIEW_SYSTEM_PROMPT,
prompt: buildResumeReviewPrompt(normalizedText),
- temperature: 0.3,
+ temperature: TEMPERATURES.FEEDBACK,
});
return result.toTextStreamResponse();
diff --git a/src/app/api/automations/[id]/run/route.ts b/src/app/api/automations/[id]/run/route.ts
index 5b289c2..8340df6 100644
--- a/src/app/api/automations/[id]/run/route.ts
+++ b/src/app/api/automations/[id]/run/route.ts
@@ -4,9 +4,7 @@ import { NextRequest, NextResponse } from "next/server";
import { auth } from "@/auth";
import db from "@/lib/db";
import { runAutomation, type RunnerResult } from "@/lib/scraper";
-
-const RATE_LIMIT_WINDOW_MS = 60 * 60 * 1000;
-const MAX_RUNS_PER_HOUR = 5;
+import { APP_CONSTANTS } from "@/lib/constants";
const recentRuns = new Map<string, number[]>();
@@ -14,10 +12,10 @@ function checkRateLimit(userId: string): boolean {
const now = Date.now();
const userRuns = recentRuns.get(userId) || [];
- const validRuns = userRuns.filter((timestamp) => now - timestamp < RATE_LIMIT_WINDOW_MS);
+ const validRuns = userRuns.filter((timestamp) => now - timestamp < APP_CONSTANTS.AUTOMATION_RATE_LIMIT_WINDOW_MS);
recentRuns.set(userId, validRuns);
- if (validRuns.length >= MAX_RUNS_PER_HOUR) {
+ if (validRuns.length >= APP_CONSTANTS.AUTOMATION_MAX_MANUAL_RUNS_PER_HOUR) {
return false;
}
@@ -41,7 +39,7 @@ export async function POST(
if (!checkRateLimit(userId)) {
return NextResponse.json(
- { message: `Rate limit exceeded. Maximum ${MAX_RUNS_PER_HOUR} manual runs per hour.` },
+ { message: `Rate limit exceeded. Maximum ${APP_CONSTANTS.AUTOMATION_MAX_MANUAL_RUNS_PER_HOUR} manual runs per hour.` },
{ status: 429 }
);
}
diff --git a/src/components/activities/ActivitiesContainer.tsx b/src/components/activities/ActivitiesContainer.tsx
index 4e3056d..41c94b3 100644
--- a/src/components/activities/ActivitiesContainer.tsx
+++ b/src/components/activities/ActivitiesContainer.tsx
@@ -125,7 +125,7 @@ function ActivitiesContainer() {
loadActivities(page + 1, APP_CONSTANTS.RECORDS_PER_PAGE, searchTerm || undefined);
}
},
- { threshold: 0.1 },
+ { threshold: APP_CONSTANTS.INTERSECTION_OBSERVER_THRESHOLD },
);
observer.observe(sentinel);
diff --git a/src/components/myjobs/JobsContainer.tsx b/src/components/myjobs/JobsContainer.tsx
index 40fa94e..68896cc 100644
--- a/src/components/myjobs/JobsContainer.tsx
+++ b/src/components/myjobs/JobsContainer.tsx
@@ -186,7 +186,14 @@ function JobsContainer({
setInitialLoading(false);
setLoadingMore(false);
},
- [jobsPerPage, companyFilter, appliedFilter, titleFilter, locationFilter, sourceFilter],
+ [
+ jobsPerPage,
+ companyFilter,
+ appliedFilter,
+ titleFilter,
+ locationFilter,
+ sourceFilter,
+ ],
);
const reloadJobs = useCallback(async () => {
@@ -287,7 +294,7 @@ function JobsContainer({
loadJobs(page + 1, filterKey, searchTerm || undefined);
}
},
- { threshold: 0.1 },
+ { threshold: APP_CONSTANTS.INTERSECTION_OBSERVER_THRESHOLD },
);
observer.observe(sentinel);
@@ -351,9 +358,13 @@ function JobsContainer({
<Card x-chunk="dashboard-06-chunk-0">
<CardHeader className="flex-col gap-3 sm:flex-row sm:justify-between sm:items-center">
<div className="flex items-baseline gap-2">
- <CardTitle>My Jobs</CardTitle>
+ <CardTitle>Jobs</CardTitle>
{!initialLoading && totalJobs > 0 && (
- <RecordsCount count={jobs.length} total={totalJobs} label="jobs" />
+ <RecordsCount
+ count={jobs.length}
+ total={totalJobs}
+ label="jobs"
+ />
)}
</div>
<div className="flex flex-wrap items-center gap-2">
diff --git a/src/components/myjobs/TagInput.tsx b/src/components/myjobs/TagInput.tsx
index 18496b7..b68950e 100644
--- a/src/components/myjobs/TagInput.tsx
+++ b/src/components/myjobs/TagInput.tsx
@@ -20,8 +20,7 @@ import { Tag } from "@/models/job.model";
import { createTag } from "@/actions/tag.actions";
import { toast } from "../ui/use-toast";
import { cn } from "@/lib/utils";
-
-const MAX_TAGS = 10;
+import { APP_CONSTANTS } from "@/lib/constants";
interface TagInputProps {
availableTags: Tag[];
@@ -40,7 +39,7 @@ export function TagInput({
const [isPending, startTransition] = useTransition();
const selectedTags = localTags.filter((t) => selectedTagIds.includes(t.id));
- const isMaxReached = selectedTagIds.length >= MAX_TAGS;
+ const isMaxReached = selectedTagIds.length >= APP_CONSTANTS.MAX_JOB_TAGS;
// Tags not yet selected, filtered by input
const filteredOptions = localTags.filter(
@@ -55,7 +54,7 @@ export function TagInput({
);
const addTagById = (id: string) => {
- if (selectedTagIds.length >= MAX_TAGS) return;
+ if (selectedTagIds.length >= APP_CONSTANTS.MAX_JOB_TAGS) return;
onChange([...selectedTagIds, id]);
};
@@ -110,7 +109,7 @@ export function TagInput({
type="button"
>
{isMaxReached
- ? `Max ${MAX_TAGS} skills reached`
+ ? `Max ${APP_CONSTANTS.MAX_JOB_TAGS} skills reached`
: "Search or add a skill..."}
<ChevronsUpDown className="ml-2 h-4 w-4 shrink-0 opacity-50" />
</Button>
diff --git a/src/components/tasks/TasksContainer.tsx b/src/components/tasks/TasksContainer.tsx
index d625936..e94c385 100644
--- a/src/components/tasks/TasksContainer.tsx
+++ b/src/components/tasks/TasksContainer.tsx
@@ -240,15 +240,10 @@ function TasksContainer({
!loadingMore &&
tasks.length < totalTasks
) {
- loadTasks(
- page + 1,
- filterKey,
- statusFilter,
- searchTerm || undefined,
- );
+ loadTasks(page + 1, filterKey, statusFilter, searchTerm || undefined);
}
},
- { threshold: 0.1 },
+ { threshold: APP_CONSTANTS.INTERSECTION_OBSERVER_THRESHOLD },
);
observer.observe(sentinel);
@@ -289,9 +284,13 @@ function TasksContainer({
<Card x-chunk="dashboard-tasks-chunk-0" className="h-full">
<CardHeader className="flex-row justify-between items-center">
<div className="flex items-baseline gap-2">
- <CardTitle>My Tasks</CardTitle>
+ <CardTitle>Tasks</CardTitle>
{!initialLoading && totalTasks > 0 && (
- <RecordsCount count={tasks.length} total={totalTasks} label="tasks" />
+ <RecordsCount
+ count={tasks.length}
+ total={totalTasks}
+ label="tasks"
+ />
)}
</div>
<div className="flex items-center">
diff --git a/src/components/ui/use-toast.ts b/src/components/ui/use-toast.ts
index 02e111d..c8ef765 100644
--- a/src/components/ui/use-toast.ts
+++ b/src/components/ui/use-toast.ts
@@ -7,8 +7,7 @@ import type {
ToastActionElement,
ToastProps,
} from "@/components/ui/toast"
-
-const TOAST_LIMIT = 1
+import { APP_CONSTANTS } from "@/lib/constants"
const TOAST_REMOVE_DELAY = 1000000
type ToasterToast = ToastProps & {
@@ -79,7 +78,7 @@ export const reducer = (state: State, action: Action): State => {
case "ADD_TOAST":
return {
...state,
- toasts: [action.toast, ...state.toasts].slice(0, TOAST_LIMIT),
+ toasts: [action.toast, ...state.toasts].slice(0, APP_CONSTANTS.TOAST_LIMIT),
}
case "UPDATE_TOAST":
diff --git a/src/lib/constants.ts b/src/lib/constants.ts
index 9f0ffa3..29dc95a 100644
--- a/src/lib/constants.ts
+++ b/src/lib/constants.ts
@@ -13,10 +13,21 @@ import {
export const APP_CONSTANTS = {
RECORDS_PER_PAGE: 25,
MAX_AUTOMATIONS_PER_USER: 10,
+ MAX_JOB_TAGS: 10,
ACTIVITY_MAX_DURATION_MINUTES: 8 * 60, // 8 Hours
ACTIVITY_MAX_DURATION_MS: 8 * 60 * 60 * 1000, // 8 hours in milliseconds
RECENT_NUM_JOBS_ACTIVITIES: 7,
AI_SLOW_RESPONSE_THRESHOLD_MS: 15_000, // 15 seconds
+ INTERSECTION_OBSERVER_THRESHOLD: 0.1,
+ TOAST_LIMIT: 1,
+
+ // Ollama API timeouts
+ AI_OLLAMA_LIST_TIMEOUT_MS: 5_000,
+ AI_OLLAMA_GENERATE_TIMEOUT_MS: 10_000,
+
+ // Automation manual run rate limiting
+ AUTOMATION_MAX_MANUAL_RUNS_PER_HOUR: 5,
+ AUTOMATION_RATE_LIMIT_WINDOW_MS: 60 * 60 * 1000, // 1 hour
// File uploads
UPLOADS_DIR: process.env.NODE_ENV !== "production" ? "data" : "/data",
@@ -70,7 +81,7 @@ export const SIDEBAR_LINKS = [
{
icon: BriefcaseBusiness,
route: "/dashboard/myjobs",
- label: "My Jobs",
+ label: "Jobs",
},
{
icon: Zap,
diff --git a/src/models/addJobForm.schema.ts b/src/models/addJobForm.schema.ts
index 0f5480d..adaa7bc 100644
--- a/src/models/addJobForm.schema.ts
+++ b/src/models/addJobForm.schema.ts
@@ -1,4 +1,5 @@
import { z } from "zod";
+import { APP_CONSTANTS } from "@/lib/constants";
export const AddJobFormSchema = z.object({
id: z.string().optional(),
@@ -59,5 +60,5 @@ export const AddJobFormSchema = z.object({
applied: z.boolean().default(false),
resume: z.string().optional(),
coverLetter: z.string().optional(),
- tags: z.array(z.string()).max(10).optional().default([]),
+ tags: z.array(z.string()).max(APP_CONSTANTS.MAX_JOB_TAGS).optional().default([]),
});
diff --git a/src/models/addQuestionForm.schema.ts b/src/models/addQuestionForm.schema.ts
index 22a9ff4..ae0e1f0 100644
--- a/src/models/addQuestionForm.schema.ts
+++ b/src/models/addQuestionForm.schema.ts
@@ -1,4 +1,5 @@
import { z } from "zod";
+import { APP_CONSTANTS } from "@/lib/constants";
export const AddQuestionFormSchema = z.object({
id: z.string().optional(),
@@ -12,6 +13,6 @@ export const AddQuestionFormSchema = z.object({
.nullable(),
tagIds: z
.array(z.string())
- .max(10, { message: "Maximum 10 skill tags allowed." })
+ .max(APP_CONSTANTS.MAX_JOB_TAGS, { message: `Maximum ${APP_CONSTANTS.MAX_JOB_TAGS} skill tags allowed.` })
.optional(),
});
diff --git a/src/utils/ai.utils.ts b/src/utils/ai.utils.ts
index ad5ee96..1adea32 100644
--- a/src/utils/ai.utils.ts
+++ b/src/utils/ai.utils.ts
@@ -1,5 +1,6 @@
import { JobResponse } from "@/models/job.model";
import { AiProvider } from "@/models/ai.model";
+import { APP_CONSTANTS } from "@/lib/constants";
// Re-export for backwards compatibility
export { convertResumeToText } from "@/lib/ai/tools/preprocessing";
@@ -20,7 +21,7 @@ export const checkOllamaConnection = async (
try {
const response = await fetch("/api/ai/ollama/tags", {
- signal: AbortSignal.timeout(5000),
+ signal: AbortSignal.timeout(APP_CONSTANTS.AI_OLLAMA_LIST_TIMEOUT_MS),
});
if (!response.ok) {