Markdown Converter
Agent skill for markdown-converter
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Sign in to like and favorite skills
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is a full-stack Todo application built with TypeScript, consisting of three main components:
The application is fully containerized using Docker and Docker Compose, and can be deployed to Google Cloud Platform (GCP) using Terraform.
Start all services (database, backend, frontend):
docker-compose up
Start services in detached mode:
docker-compose up -d
Stop all services:
docker-compose down
Stop and remove volumes (clears database):
docker-compose down -v
Rebuild containers after dependency changes:
docker-compose up --build
Location:
backend/
Development (with hot reload using ts-node-dev):
cd backend npm run dev
Build TypeScript:
cd backend npm run build
Production (requires build first):
cd backend npm run build npm start
Install dependencies:
cd backend npm install
The backend runs on port 8080 by default.
Location:
frontend/
Development server:
cd frontend npm run dev
Production build:
cd frontend npm run build npm start
Linting:
cd frontend npm run lint
The frontend runs on port 3000 by default.
The backend is a TypeScript Express application with organized modules:
Project Structure:
src/server.ts - Main Express server and application entry pointsrc/routes/todos.ts - Todo API route handlerssrc/config/database.ts - MySQL connection pool and database initializationsrc/types/todo.ts - TypeScript type definitions for Todo entitiesDatabase Initialization: On startup (
initDatabase() in src/config/database.ts), the server automatically creates the todos table if it doesn't exist using a connection pool pattern.
API Endpoints:
GET /health - Health check endpointGET /api/todos - Fetch all todosGET /api/todos/:id - Fetch a specific todoPOST /api/todos - Create a new todo (requires title, optional description)PUT /api/todos/:id - Update a todo (supports partial updates: title, description, completed)DELETE /api/todos/:id - Delete a specific todoDELETE /api/todos - Delete all todosDatabase Schema:
todos ( id INT AUTO_INCREMENT PRIMARY KEY, title VARCHAR(255) NOT NULL, description TEXT, completed BOOLEAN DEFAULT false, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP )
Connection Pool: Uses
mysql2/promise with a connection pool (limit: 10 connections) for efficient database access. TypeScript types from mysql2 (ResultSetHeader, RowDataPacket) are used for type-safe database queries.
TypeScript Types: The application uses strict TypeScript typing:
Todo - Full todo entity with all fieldsCreateTodoInput - Input type for creating todosUpdateTodoInput - Input type for updating todos (all fields optional)The frontend is a Next.js 14 App Router application with TypeScript and client-side rendering:
Project Structure:
src/app/page.tsx - Main todo page (client component)src/app/layout.tsx - Root layout with metadatasrc/app/globals.css - Global styles with Tailwind directivesMain Page (
frontend/src/app/page.tsx): A single-page client component with TypeScript interfaces that handles all todo operations using React hooks and fetch API.
State Management: Uses React useState for local state:
API Integration: Communicates with the backend via
NEXT_PUBLIC_API_URL environment variable (defaults to http://localhost:8080).
User Actions:
Networks: All services communicate over a bridge network (
todo-network).
Service Dependencies:
Volume Mounts:
mysql_data volumeEnvironment Variables:
PORT, NODE_ENV, DB_HOST, DB_USER, DB_PASSWORD, DB_NAMENEXT_PUBLIC_API_URLMYSQL_ROOT_PASSWORD, MYSQL_DATABASE, MYSQL_USER, MYSQL_PASSWORDDefault credentials (configured in
docker-compose.yml):
rootpasswordtodoapp_usertodoapp_passtodo_dbFor local development, these should be overridden in
backend/.env file (see backend/.env.example).
When modifying the backend:
ts-node-dev in Docker (watches TypeScript files)npm run build to compile TypeScript to JavaScript in the dist/ folderWhen modifying the frontend:
NEXT_PUBLIC_ to be accessible in browserBackend (
backend/tsconfig.json):
dist/src/Frontend (
frontend/tsconfig.json):
@/* maps to ./src/*This project can be deployed to Google Cloud Platform using Terraform and Cloud Run.
Cloud Services:
Terraform Configuration (
terraform/):
main.tf - Provider and API enablementnetwork.tf - VPC, subnet, and VPC connectorcloudsql.tf - Cloud SQL instance and databasecloudrun.tf - Backend and frontend Cloud Run servicessecrets.tf - Secret Manager configurationartifact_registry.tf - Docker repositoryvariables.tf - Input variablesoutputs.tf - Output values (URLs, database info)Initial Setup:
gcloud config set project YOUR_PROJECT_ID ./scripts/setup-gcp.sh
Configure Terraform:
cd terraform cp terraform.tfvars.example terraform.tfvars # Edit terraform.tfvars with your project details
Deploy:
./scripts/deploy.sh
Access Application:
terraform -chdir=terraform output frontend_url
Separate production Dockerfiles are provided:
backend/Dockerfile.prod - Multi-stage build with TypeScript compilationfrontend/Dockerfile.prod - Optimized Next.js standalone buildKey differences from development:
cloudbuild.yaml provides automated deployment:
Connect to GitHub for automatic deployment on push.
Approximate monthly costs (light usage):
See
GCP_DEPLOYMENT.md for detailed deployment guide and troubleshooting.
View Logs:
gcloud run logs read todo-backend --region=asia-northeast1 gcloud run logs read todo-frontend --region=asia-northeast1
Database Connection:
cloud-sql-proxy YOUR_PROJECT_ID:asia-northeast1:todo-app-mysql
Cleanup:
cd terraform && terraform destroy