New model

From hoangsonww/WealthWise-Finance-Tracker · View interactive version

New model is an AI agent skill from the GitHub repository hoangsonww/WealthWise-Finance-Tracker. Scaffold a new Mongoose model and its CRUD service for the WealthWise API. Triggers when asked to "create a model", "add a Mongoose schema", or add the data layer for a new entity without a full endpoint. Does NOT scaffold routes, controllers, or frontend code. Use $api-endpoint for the full stack.

How to use this skill

Skill file

Scaffold a new Mongoose model with its full CRUD service.

The entity name is provided in the task prompt.

Files to create

Model — `apps/api/src/models/<entity>.model.ts`

import { Schema, model, Document, Types } from 'mongoose';

export interface I<Entity> extends Document {
  userId: Types.ObjectId;
  // entity-specific fields
  createdAt: Date;
  updatedAt: Date;
}

const <entity>Schema = new Schema<I<Entity>>(
  {
    userId: {
      type: Schema.Types.ObjectId,
      ref: 'User',
      required: true,
      index: true,
    },
    // entity fields
  },
  {
    timestamps: true,    // handles createdAt/updatedAt automatically
    toJSON: { virtuals: true },
    toObject: { virtuals: true },
  }
);

// All indexes defined here — never outside the schema file
<entity>Schema.index({ userId: 1, createdAt: -1 });

export const <Entity>Model = model<I<Entity>>('<Entity>', <entity>Schema);

Service — `apps/api/src/services/<entity>.service.ts`

Five methods, fully typed:

  1. get<Entity>s(userId: string): Promise<I<Entity>[]>
  1. get<Entity>ById(id: string, userId: string): Promise<I<Entity>>
  1. create<Entity>(userId: string, data: Create<Entity>Input): Promise<I<Entity>>
  1. update<Entity>(id: string, userId: string, data: Update<Entity>Input): Promise<I<Entity>>
  1. delete<Entity>(id: string, userId: string): Promise<void>

Rules

Verification

npx turbo lint --filter=@wealthwise/api

List all created file paths and the five service method signatures.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.