|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +This is a database documentation project that implements "docs as code" approach using Docker, tbls, Liam ERD, and VitePress. The system automatically generates database documentation from a MySQL database schema and provides both tabular documentation and ER diagrams through a web interface. |
| 8 | + |
| 9 | +## Key Components |
| 10 | + |
| 11 | +- **Database**: MySQL database with Flyway migrations in `sql/migration/` |
| 12 | +- **Documentation Generation**: tbls for schema documentation, Liam ERD for ER diagrams |
| 13 | +- **Static Site**: VitePress for serving documentation website |
| 14 | +- **Docker**: Containerized database and tbls execution |
| 15 | +- **Git Hooks**: Lefthook for pre-commit formatting and schema generation |
| 16 | + |
| 17 | +## Essential Commands |
| 18 | + |
| 19 | +### Database Operations |
| 20 | +```bash |
| 21 | +# Start database container |
| 22 | +pnpm db:serve |
| 23 | + |
| 24 | +# Stop and remove database with volumes |
| 25 | +pnpm db:down |
| 26 | + |
| 27 | +# Rebuild database from scratch |
| 28 | +pnpm db:rebuild |
| 29 | + |
| 30 | +# Generate schema documentation using tbls |
| 31 | +pnpm db:schema |
| 32 | +``` |
| 33 | + |
| 34 | +### Documentation |
| 35 | +```bash |
| 36 | +# Start VitePress development server |
| 37 | +pnpm docs:dev |
| 38 | + |
| 39 | +# Build documentation site |
| 40 | +pnpm docs:build |
| 41 | + |
| 42 | +# Preview built documentation |
| 43 | +pnpm docs:preview |
| 44 | + |
| 45 | +# Generate ER diagram from schema |
| 46 | +pnpm er:build |
| 47 | + |
| 48 | +# Serve ER diagram locally |
| 49 | +pnpm er:serve |
| 50 | +``` |
| 51 | + |
| 52 | +### Code Formatting |
| 53 | +```bash |
| 54 | +# Format all SQL files using sql-formatter |
| 55 | +pnpm sql:fix |
| 56 | +``` |
| 57 | + |
| 58 | +## Architecture |
| 59 | + |
| 60 | +### Database Schema Management |
| 61 | +- Migration files in `sql/migration/` follow Flyway naming conventions |
| 62 | +- DDL files: `V{version}__{description}.sql` for versioned migrations |
| 63 | +- DML files: Data seeding organized by environment (`local/`, `stg/`, `prd/`) |
| 64 | +- Views: `R__views.sql` as repeatable migrations |
| 65 | + |
| 66 | +### Documentation Pipeline |
| 67 | +1. Database schema → tbls → generates markdown docs in `docs/schema/` |
| 68 | +2. Schema JSON → Liam ERD → generates ER diagrams in `docs/out/` |
| 69 | +3. VitePress builds static site from docs/ directory |
| 70 | + |
| 71 | +### Configuration Files |
| 72 | +- `.tbls.yml`: tbls configuration for schema documentation generation |
| 73 | +- `.sql-formatter.json`: SQL formatting rules (MySQL dialect, uppercase keywords) |
| 74 | +- `lefthook.yml`: Git hooks for SQL formatting and schema regeneration |
| 75 | +- `.vitepress/config.ts`: VitePress site configuration |
| 76 | + |
| 77 | +## Development Workflow |
| 78 | + |
| 79 | +1. Make database schema changes in `sql/migration/` |
| 80 | +2. Run `pnpm sql:fix` to format SQL (or let git hooks handle it) |
| 81 | +3. Run `pnpm db:rebuild` to apply migrations |
| 82 | +4. Run `pnpm db:schema` to regenerate documentation |
| 83 | +5. Run `pnpm er:build` to update ER diagrams |
| 84 | +6. Use `pnpm docs:dev` to preview changes |
| 85 | + |
| 86 | +## Important Notes |
| 87 | + |
| 88 | +- The database runs on port 3306 with credentials: `user:Password@db:3306/sample_rdb` |
| 89 | +- Schema documentation is generated in Japanese (see dict section in .tbls.yml) |
| 90 | +- Pre-commit hooks automatically format SQL and rebuild documentation |
| 91 | +- ER diagrams show relationships up to distance 2 between tables |
| 92 | +- Excel schema export available in `excel/schema.xlsx` |
0 commit comments