Skip to content

Commit c0b3fa5

Browse files
committed
feat: Complete ERD generation system with package migration
🚀 Major Features Implemented: - Automatic Mermaid ERD generation from SQLModel definitions - Bidirectional relationship deduplication for clean diagrams - Comprehensive validation system with syntax checking - CLI interface for ERD generation and management - Performance-optimized generation (<30 seconds for 20 tables) 📦 Package Migration: - Moved all ERD code to dedicated backend/erd package - Renamed files to remove erd_ prefix (now in erd package) - Updated all imports across 17+ files - Reorganized test structure under tests/unit/erd_tests/ 🔧 Production Optimization: - Updated .dockerignore to exclude ERD package from production builds - Clean separation between core app and documentation tools - ERD functionality can be excluded from production deployments 🧪 Testing & Quality: - Comprehensive unit tests for all ERD components - Performance tests ensuring <30 second generation time - Integration tests for complete workflows - Contract tests for CLI interface validation 📚 Documentation & Governance: - Updated constitution with ERD requirements and performance standards - Enhanced plan and tasks templates with ERD checks - Complete ERD documentation with usage examples - Generated sample ERD diagram (docs/database/erd.mmd) ✅ All Phase 3.5 tasks completed: - T023-T025: Unit tests for ERD Generator, Model Metadata, validation - T026: Performance tests (<30 seconds for large schemas) - T027: Documentation updates - T028: Constitution updates with ERD requirements - T029-T030: Template updates with ERD checks - T031: Code optimization and deduplication - T032: Manual validation testing The ERD system is now production-ready with clean architecture, comprehensive testing, and optimized deployment configuration.
1 parent df0a7c6 commit c0b3fa5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+7921
-7
lines changed

.cursor/rules/specify-rules.mdc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# full-stack-fastapi-template Development Guidelines
2+
3+
Auto-generated from all feature plans. Last updated: 2025-10-03
4+
5+
## Active Technologies
6+
- Python 3.11+ + SQLModel, Mermaid, Git hooks, pre-commit framework (001-as-a-first)
7+
8+
## Project Structure
9+
```
10+
backend/
11+
frontend/
12+
tests/
13+
```
14+
15+
## Commands
16+
cd src [ONLY COMMANDS FOR ACTIVE TECHNOLOGIES][ONLY COMMANDS FOR ACTIVE TECHNOLOGIES] pytest [ONLY COMMANDS FOR ACTIVE TECHNOLOGIES][ONLY COMMANDS FOR ACTIVE TECHNOLOGIES] ruff check .
17+
18+
## Code Style
19+
Python 3.11+: Follow standard conventions
20+
21+
## Recent Changes
22+
- 001-as-a-first: Added Python 3.11+ + SQLModel, Mermaid, Git hooks, pre-commit framework
23+
24+
<!-- MANUAL ADDITIONS START -->
25+
<!-- MANUAL ADDITIONS END -->

.pre-commit-config.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@ repos:
3232
language: system
3333
types: [text]
3434
files: ^frontend/
35+
- id: erd-generation
36+
name: ERD generation
37+
entry: bash -c 'cd backend && python scripts/generate_erd.py --validate --verbose --force'
38+
language: system
39+
types: [python]
40+
files: ^backend/app/.*\.py$
41+
stages: [pre-commit]
42+
always_run: false
43+
pass_filenames: true
44+
require_serial: false
45+
description: "Generate and validate ERD diagrams from SQLModel definitions (Mermaid format)"
3546

3647
ci:
3748
autofix_commit_msg: 🎨 [pre-commit.ci] Auto format from pre-commit.com hooks

.specify/memory/constitution.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,16 @@ All new features MUST implement secure defaults: JWT authentication, password ha
4343
- Integration tests MUST verify API endpoints and database interactions
4444
- End-to-end tests MUST validate complete user workflows
4545
- Contract tests MUST ensure API schema consistency
46+
- ERD generation MUST have unit tests, integration tests, and performance tests
47+
- ERD validation MUST include syntax validation and relationship verification
4648

4749
### Documentation Standards
4850
- All new features MUST include API documentation via OpenAPI/Swagger
4951
- User-facing features MUST have updated README sections
5052
- Complex business logic MUST include inline documentation
5153
- Deployment changes MUST update deployment.md
54+
- Database schema changes MUST automatically update Entity Relationship Diagrams (ERD)
55+
- ERD documentation MUST be generated from SQLModel definitions and kept in sync
5256

5357
## Quality Standards
5458

@@ -57,6 +61,7 @@ All new features MUST implement secure defaults: JWT authentication, password ha
5761
- Frontend pages MUST load within 2 seconds
5862
- Database queries MUST be optimized and indexed appropriately
5963
- Docker containers MUST start within 30 seconds
64+
- ERD generation MUST complete within 30 seconds for schemas with up to 20 tables and 100 fields
6065

6166
### Accessibility Standards
6267
- All UI components MUST meet WCAG 2.1 AA standards

.specify/templates/plan-template.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
**Auto-Generated Client**: Will API changes require frontend client regeneration?
5353
**Docker-First**: Does the feature work in containerized environment?
5454
**Security by Default**: Are authentication, validation, and security considerations included?
55+
**ERD Documentation**: Will database schema changes require ERD updates and validation?
5556

5657
## Project Structure
5758

.specify/templates/tasks-template.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,9 @@
7373
- [ ] T019 [P] Unit tests for validation in tests/unit/test_validation.py
7474
- [ ] T020 Performance tests (<200ms)
7575
- [ ] T021 [P] Update docs/api.md
76-
- [ ] T022 Remove duplication
77-
- [ ] T023 Run manual-testing.md
76+
- [ ] T022 [P] Update ERD documentation if database schema changed
77+
- [ ] T023 Remove duplication
78+
- [ ] T024 Run manual-testing.md
7879

7980
## Dependencies
8081
- Tests (T004-T007) before implementation (T008-T014)
@@ -124,4 +125,5 @@ Task: "Integration test auth in tests/integration/test_auth.py"
124125
- [ ] All tests come before implementation
125126
- [ ] Parallel tasks truly independent
126127
- [ ] Each task specifies exact file path
127-
- [ ] No task modifies same file as another [P] task
128+
- [ ] No task modifies same file as another [P] task
129+
- [ ] ERD documentation tasks included if database schema changes

backend/.dockerignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,10 @@ app.egg-info
66
.coverage
77
htmlcov
88
.venv
9+
10+
# ERD Package (development/documentation only)
11+
erd/
12+
scripts/generate_erd.py
13+
tests/unit/erd_tests/
14+
tests/performance/test_erd_*.py
15+
tests/integration/test_erd_*.py

backend/erd/__init__.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
"""
2+
ERD Package - Entity Relationship Diagram generation from SQLModel definitions.
3+
4+
This package provides functionality to automatically generate Mermaid ERD diagrams
5+
from SQLModel class definitions, including validation and output formatting.
6+
7+
Main Components:
8+
- generator: Main ERD generation logic
9+
- models: Data structures for model metadata
10+
- validation: ERD validation and error checking
11+
- discovery: SQLModel introspection and parsing
12+
- output: ERD output formatting and file handling
13+
- entities: Entity definition structures
14+
- fields: Field definition structures
15+
- relationships: Relationship definition and management
16+
- mermaid_validator: Mermaid syntax validation
17+
18+
Usage:
19+
from erd import ERDGenerator
20+
21+
generator = ERDGenerator()
22+
mermaid_code = generator.generate_erd()
23+
"""
24+
25+
from .generator import ERDGenerator
26+
from .models import (
27+
FieldMetadata,
28+
ModelMetadata,
29+
RelationshipMetadata,
30+
ConstraintMetadata
31+
)
32+
from .validation import (
33+
ERDValidator,
34+
ValidationResult,
35+
ValidationError,
36+
ErrorSeverity,
37+
ValidationMode
38+
)
39+
from .output import ERDOutput
40+
from .entities import EntityDefinition
41+
from .relationships import RelationshipDefinition, RelationshipManager
42+
from .discovery import ModelDiscovery
43+
from .mermaid_validator import MermaidValidator
44+
45+
__version__ = "1.0.0"
46+
__all__ = [
47+
"ERDGenerator",
48+
"FieldMetadata",
49+
"ModelMetadata",
50+
"RelationshipMetadata",
51+
"ConstraintMetadata",
52+
"ERDValidator",
53+
"ValidationResult",
54+
"ValidationError",
55+
"ErrorSeverity",
56+
"ValidationMode",
57+
"ERDOutput",
58+
"EntityDefinition",
59+
"RelationshipDefinition",
60+
"RelationshipManager",
61+
"ModelDiscovery",
62+
"MermaidValidator",
63+
]

0 commit comments

Comments
 (0)