Prompting & Workflows Beginner Project 17 of 17

Build a Database Issue Tracker with AI

Create a full-stack issue tracking system that combines AI coding, database queries, and cost-effective prompting strategies.

What You'll Build

A PostgreSQL database schema for tracking issues and comments
GitHub repository with AI-generated code using Copilot Workspace
Claude MCP integration for database queries and operations
Token-optimized prompts that minimize AI costs
Web interface for creating, updating, and viewing issues
Automated workflow that connects code generation to database operations

What You'll Need

Claude (with MCP)

We'll use Claude's MCP capabilities for database operations and GitHub Copilot Workspace for code generation. You'll need access to both platforms.

Text Editor & GitHub

Any text editor for reviewing generated code, plus a GitHub account for using Copilot Workspace and managing your repository.

1

Create the GitHub Issue and Repository Setup

We'll start by creating a detailed GitHub issue that Copilot Workspace can use to generate our initial codebase. This step teaches you how to write AI-friendly issue descriptions that lead to better code generation while being mindful of token usage.

**Issue Title:** Build Database-Connected Issue Tracker with MCP Integration

**Description:**
Create a web-based issue tracking system with the following requirements:

**Database Schema:**
- Issues table: id, title, description, status, priority, created_at, updated_at
- Comments table: id, issue_id, content, author, created_at
- Use PostgreSQL with proper foreign keys

**Backend:**
- Node.js/Express API with endpoints for CRUD operations
- Database connection setup for PostgreSQL
- Input validation and error handling
- RESTful API design

**Frontend:**
- Simple HTML/CSS/JavaScript interface
- Forms for creating/editing issues
- Issue listing with filtering by status
- Comment system for each issue

**Technical Details:**
- Include package.json with dependencies
- Environment variable configuration
- Basic SQL migration files
- Error handling and logging

Acceptance Criteria:
- Can create, read, update, delete issues
- Can add comments to issues
- Database queries work with MCP integration
- Clean, maintainable code structure

Look for Copilot Workspace to generate a complete project structure including package.json, database schemas, API endpoints, and basic frontend files. The AI should create around 8-12 files with proper separation of concerns.

2

Set Up Database Schema with Token-Efficient Prompting

Now we'll use Claude to create our database schema and initial data. This step demonstrates how to structure prompts to get exactly what you need while minimizing token usage and costs.

Create PostgreSQL schema for issue tracker. Output only SQL:

1. Issues table:
   - id (primary key, auto-increment)
   - title (varchar 255, required)
   - description (text)
   - status (enum: open, in_progress, closed)
   - priority (enum: low, medium, high)
   - created_at, updated_at (timestamps)

2. Comments table:
   - id (primary key, auto-increment)
   - issue_id (foreign key to issues)
   - content (text, required)
   - author (varchar 100)
   - created_at (timestamp)

3. Include:
   - Proper indexes
   - 3 sample issues
   - 2 comments per issue

Format: CREATE statements, INSERT statements, no explanations.

You should receive clean SQL statements without extra commentary. Notice how the prompt structure saves tokens by being specific about format and avoiding unnecessary explanations. Claude should generate about 200-300 tokens of SQL code.

3

Configure Claude MCP for Database Operations

We'll set up Claude's MCP (Model Context Protocol) to connect to your PostgreSQL database. This allows Claude to directly query and manipulate your data, creating a powerful workflow for database-driven development.

I need to connect to a PostgreSQL database for my issue tracker project.

Database details:
- Host: localhost (or your database host)
- Port: 5432
- Database name: issue_tracker
- Username: [your username]
- Password: [your password]

Tables created:
- issues (id, title, description, status, priority, created_at, updated_at)
- comments (id, issue_id, content, author, created_at)

Once connected, please:
1. Verify the connection works
2. Show me all current issues
3. Test creating a new issue with title "Test MCP Integration" and description "Testing database connection through MCP"

Confirm each step works before proceeding.

Claude should establish the MCP connection and execute the test queries successfully. You'll see the database contents and confirmation that the new test issue was created. If connection fails, Claude will provide specific troubleshooting steps.

4

Optimize API Endpoints with Context-Aware Prompting

Now we'll refine the generated API code by using Claude's database connection to test and improve the endpoints. This step shows how to use context windows effectively by building on previous conversation history.

Using the database connection we just established, help me improve the API endpoints from the Copilot-generated code.

For each endpoint, I need you to:
1. Test the current database state
2. Suggest optimized SQL queries
3. Provide improved error handling

Endpoints to optimize:

GET /api/issues
- Add filtering by status and priority
- Include comment count per issue
- Add pagination (limit 10 per page)

POST /api/issues  
- Validate required fields
- Auto-set created_at/updated_at
- Return full created issue

GET /api/issues/:id/comments
- Order by created_at DESC
- Include author info

Test each query against our current data before providing the final code.

Claude will test each query against your live database, show you the results, and then provide optimized code. You should see actual data from your database and improved API endpoint code with better error handling and validation.

5

Create Interactive Frontend with Cost-Optimized Prompts

Finally, we'll generate an interactive frontend that connects to our API. We'll use cost-conscious prompting techniques to get exactly what we need without generating excessive code or explanations.

Generate frontend files for issue tracker. Match this exact structure:

**index.html:**
- Issue list with status badges
- "New Issue" button
- Filter dropdown (all/open/closed)
- Click issue to view details

**styles.css:**
- Dark theme
- Status badges: green=open, blue=in_progress, gray=closed  
- Responsive grid layout
- Form styling

**script.js:**
- fetchIssues() - GET /api/issues
- createIssue(data) - POST /api/issues
- showIssueDetail(id) - shows comments
- addComment(issueId, content)

**Requirements:**
- Use fetch() for API calls
- Show loading states
- Handle errors gracefully
- No frameworks, vanilla JS only

Provide 3 separate code blocks: HTML, CSS, JS. No explanations between code blocks.

You'll receive three clean code blocks for HTML, CSS, and JavaScript without extra commentary. The prompt structure minimizes output tokens while ensuring you get complete, functional frontend code that integrates with your database-connected API.

Common Issues

MCP Connection Fails

Double-check your database credentials and ensure PostgreSQL is running. Try connecting with a simpler query first, like SELECT version();

Copilot Workspace Generates Too Much Code

Be more specific in your GitHub issue. Break down requirements into smaller, focused sections. This helps the AI generate more targeted, useful code.

High Token Usage in Claude

Use structured prompts that specify output format. Ask for "code only" or "SQL only" when you don't need explanations. This can reduce costs by 50-70%.

API Endpoints Don't Work

Test each endpoint individually using Claude's MCP connection before integrating with frontend. This helps isolate database vs. API vs. frontend issues.

What You Learned

AI-Driven Development Workflow

Combined GitHub Copilot Workspace for code generation with Claude MCP for database operations, creating an integrated AI development pipeline.

Database Integration with MCP

Used Claude's Model Context Protocol to directly query and manipulate PostgreSQL data, enabling real-time database testing and optimization.

Token-Efficient Prompting

Learned to structure prompts for minimal token usage while maximizing output quality, reducing AI costs through strategic prompt design.

Context Window Optimization

Built complex functionality by leveraging conversation history and context, showing how to maintain state across multiple AI interactions.

Tips for Going Further

Add Authentication: Use Claude to generate JWT-based user authentication and associate issues with specific users.

Real-time Updates: Ask Copilot Workspace to add WebSocket support for live issue updates across multiple users.

Advanced Queries: Use Claude MCP to create complex reporting queries - issue statistics, user activity, time-to-resolution metrics.

Mobile Interface: Generate a responsive mobile-first design using token-efficient CSS prompts.

Deployment Automation: Create Docker configurations and deployment scripts using AI-generated DevOps workflows.