Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Claude Code Task Management Guide

## Documentation Available

📚 **Project Documentation**: Check the documentation files in this directory for project-specific setup instructions and guides.
**Project Tasks**: Check the tasks directory in documentation/tasks for the list of tasks to be completed. Use the CLI commands below to interact with them.

## MANDATORY Task Management Workflow

🚨 **YOU MUST FOLLOW THIS EXACT WORKFLOW - NO EXCEPTIONS** 🚨

### **STEP 1: DISCOVER TASKS (MANDATORY)**
You MUST start by running this command to see all available tasks:
```bash
task-manager list-tasks
```

### **STEP 2: START EACH TASK (MANDATORY)**
Before working on any task, you MUST mark it as started:
```bash
task-manager start-task <task_id>
```

### **STEP 3: COMPLETE OR CANCEL EACH TASK (MANDATORY)**
After finishing implementation, you MUST mark the task as completed, or cancel if you cannot complete it:
```bash
task-manager complete-task <task_id> "Brief description of what was implemented"
# or
task-manager cancel-task <task_id> "Reason for cancellation"
```

## Task Files Location

📁 **Task Data**: Your tasks are organized in the `documentation/tasks/` directory:
- Task JSON files contain complete task information
- Use ONLY the `task-manager` commands listed above
- Follow the mandatory workflow sequence for each task

## MANDATORY Task Workflow Sequence

🔄 **For EACH individual task, you MUST follow this sequence:**

1. 📋 **DISCOVER**: `task-manager list-tasks` (first time only)
2. 🚀 **START**: `task-manager start-task <task_id>` (mark as in progress)
3. 💻 **IMPLEMENT**: Do the actual coding/implementation work
4. ✅ **COMPLETE**: `task-manager complete-task <task_id> "What was done"` (or cancel with `task-manager cancel-task <task_id> "Reason"`)
5. 🔁 **REPEAT**: Go to next task (start from step 2)

## Task Status Options

- `pending` - Ready to work on
- `in_progress` - Currently being worked on
- `completed` - Successfully finished
- `blocked` - Cannot proceed (waiting for dependencies)
- `cancelled` - No longer needed

## CRITICAL WORKFLOW RULES

❌ **NEVER skip** the `task-manager start-task` command
❌ **NEVER skip** the `task-manager complete-task` command (use `task-manager cancel-task` if a task is not planned, not required, or you must stop it)
❌ **NEVER work on multiple tasks simultaneously**
✅ **ALWAYS complete one task fully before starting the next**
✅ **ALWAYS provide completion details in the complete command**
✅ **ALWAYS follow the exact 3-step sequence: list → start → complete (or cancel if not required)**
136 changes: 136 additions & 0 deletions app/api/finance/assets/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import { NextRequest } from "next/server";
import { db } from "@/db";
import { assets } from "@/db/schema/finance";
import { eq, and } from "drizzle-orm";
import { assetCreateSchema, assetUpdateSchema } from "@/lib/validation";
import { createApiResponse, handleApiError, handleValidationError } from "@/lib/api-utils";
import { getSession } from "@/lib/auth-client";
import { z } from "zod";

// GET /api/finance/assets - Get all assets for current user
export async function GET(request: NextRequest) {
try {
const session = await getSession();

if (!session?.user) {
return createApiResponse(false, undefined, "Unauthorized", 401);
}

const userAssets = await db
.select()
.from(assets)
.where(eq(assets.userId, session.user.id))
.orderBy(assets.createdAt);

return createApiResponse(true, userAssets);
} catch (error) {
return handleApiError(error);
}
}

// POST /api/finance/assets - Create a new asset
export async function POST(request: NextRequest) {
try {
const session = await getSession();

if (!session?.user) {
return createApiResponse(false, undefined, "Unauthorized", 401);
}

const body = await request.json();
const validatedData = assetCreateSchema.parse(body);

const [newAsset] = await db
.insert(assets)
.values({
id: crypto.randomUUID(),
userId: session.user.id,
name: validatedData.name,
type: validatedData.type,
value: validatedData.value.toString(),
purchaseDate: validatedData.purchaseDate ? new Date(validatedData.purchaseDate) : undefined,
description: validatedData.description,
})
.returning();

return createApiResponse(true, newAsset, undefined, 201);
} catch (error) {
if (error instanceof z.ZodError) {
return handleValidationError(error);
}
return handleApiError(error);
}
}

// PUT /api/finance/assets - Update an asset
export async function PUT(request: NextRequest) {
try {
const session = await getSession();

if (!session?.user) {
return createApiResponse(false, undefined, "Unauthorized", 401);
}

const body = await request.json();
const { id, ...updateData } = body;

if (!id) {
return createApiResponse(false, undefined, "Asset ID is required", 400);
}

const validatedData = assetUpdateSchema.parse(updateData);

const [updatedAsset] = await db
.update(assets)
.set({
...validatedData,
value: validatedData.value ? validatedData.value.toString() : undefined,
purchaseDate: validatedData.purchaseDate ? new Date(validatedData.purchaseDate) : undefined,
updatedAt: new Date(),
})
.where(and(eq(assets.id, id), eq(assets.userId, session.user.id)))
.returning();

if (!updatedAsset) {
return createApiResponse(false, undefined, "Asset not found", 404);
}

return createApiResponse(true, updatedAsset);
} catch (error) {
if (error instanceof z.ZodError) {
return handleValidationError(error);
}
return handleApiError(error);
}
}

// DELETE /api/finance/assets - Delete an asset
export async function DELETE(request: NextRequest) {
try {
const session = await getSession();

if (!session?.user) {
return createApiResponse(false, undefined, "Unauthorized", 401);
}

const { searchParams } = new URL(request.url);
const id = searchParams.get("id");

if (!id) {
return createApiResponse(false, undefined, "Asset ID is required", 400);
}

const [deletedAsset] = await db
.delete(assets)
.where(and(eq(assets.id, id), eq(assets.userId, session.user.id)))
.returning();

if (!deletedAsset) {
return createApiResponse(false, undefined, "Asset not found", 404);
}

return createApiResponse(true, { message: "Asset deleted successfully" });
} catch (error) {
return handleApiError(error);
}
}
138 changes: 138 additions & 0 deletions app/api/finance/expenses/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
import { NextRequest } from "next/server";
import { db } from "@/db";
import { expenses } from "@/db/schema/finance";
import { eq, and } from "drizzle-orm";
import { expenseCreateSchema, expenseUpdateSchema } from "@/lib/validation";
import { createApiResponse, handleApiError, handleValidationError } from "@/lib/api-utils";
import { getSession } from "@/lib/auth-client";
import { z } from "zod";

// GET /api/finance/expenses - Get all expenses for current user
export async function GET(request: NextRequest) {
try {
const session = await getSession();

if (!session?.user) {
return createApiResponse(false, undefined, "Unauthorized", 401);
}

const userExpenses = await db
.select()
.from(expenses)
.where(eq(expenses.userId, session.user.id))
.orderBy(expenses.date);

return createApiResponse(true, userExpenses);
} catch (error) {
return handleApiError(error);
}
}

// POST /api/finance/expenses - Create a new expense
export async function POST(request: NextRequest) {
try {
const session = await getSession();

if (!session?.user) {
return createApiResponse(false, undefined, "Unauthorized", 401);
}

const body = await request.json();
const validatedData = expenseCreateSchema.parse(body);

const [newExpense] = await db
.insert(expenses)
.values({
id: crypto.randomUUID(),
userId: session.user.id,
description: validatedData.description,
amount: validatedData.amount.toString(),
category: validatedData.category,
date: new Date(validatedData.date),
isRecurring: validatedData.isRecurring,
recurringFrequency: validatedData.recurringFrequency,
notes: validatedData.notes,
})
.returning();

return createApiResponse(true, newExpense, undefined, 201);
} catch (error) {
if (error instanceof z.ZodError) {
return handleValidationError(error);
}
return handleApiError(error);
}
}

// PUT /api/finance/expenses - Update an expense
export async function PUT(request: NextRequest) {
try {
const session = await getSession();

if (!session?.user) {
return createApiResponse(false, undefined, "Unauthorized", 401);
}

const body = await request.json();
const { id, ...updateData } = body;

if (!id) {
return createApiResponse(false, undefined, "Expense ID is required", 400);
}

const validatedData = expenseUpdateSchema.parse(updateData);

const [updatedExpense] = await db
.update(expenses)
.set({
...validatedData,
amount: validatedData.amount ? validatedData.amount.toString() : undefined,
date: validatedData.date ? new Date(validatedData.date) : undefined,
updatedAt: new Date(),
})
.where(and(eq(expenses.id, id), eq(expenses.userId, session.user.id)))
.returning();

if (!updatedExpense) {
return createApiResponse(false, undefined, "Expense not found", 404);
}

return createApiResponse(true, updatedExpense);
} catch (error) {
if (error instanceof z.ZodError) {
return handleValidationError(error);
}
return handleApiError(error);
}
}

// DELETE /api/finance/expenses - Delete an expense
export async function DELETE(request: NextRequest) {
try {
const session = await getSession();

if (!session?.user) {
return createApiResponse(false, undefined, "Unauthorized", 401);
}

const { searchParams } = new URL(request.url);
const id = searchParams.get("id");

if (!id) {
return createApiResponse(false, undefined, "Expense ID is required", 400);
}

const [deletedExpense] = await db
.delete(expenses)
.where(and(eq(expenses.id, id), eq(expenses.userId, session.user.id)))
.returning();

if (!deletedExpense) {
return createApiResponse(false, undefined, "Expense not found", 404);
}

return createApiResponse(true, { message: "Expense deleted successfully" });
} catch (error) {
return handleApiError(error);
}
}
Loading