Phase 6: Entity CLI commands — completing FastStack v1#9
Merged
Conversation
manavgup
added a commit
that referenced
this pull request
Apr 6, 2026
- Add dependencies.py.j2 template generating per-entity Depends() providers - Update router.py.j2: replace stub ... bodies with real service calls - Add _register_router_in_main() to auto-update main.py on add-entity - Add _regenerate_registry_files() for multi-entity templates (dependencies.py, integration conftest), called from add-entity, generate, and init --entities - Add conftest_integration.py.j2 with AsyncClient + fake repo DI overrides - Remove TODO comment from test_integration.py.j2 - 50 new tests (387 total): router wiring, registry files, main.py registration, multi-entity templates Closes #9 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The final phase completing FastStack v1: - cmd_add_entity.py: `faststack add-entity <Name>` with --fields, --from-yaml, --update. Generates all 9 entity files respecting PRESERVED vs REGENERATABLE. Updates .project-config.yaml with hash. - cmd_generate.py: `faststack generate <Name>` regenerates REGENERATABLE files (schemas, fakes, factories) from model via AST introspection. Skips PRESERVED files. --all and --force flags. - cmd_migrate.py: `faststack migrate generate/upgrade/downgrade` — Alembic wrapper that checks for alembic.ini. - cmd_list.py: `faststack list` shows entities with staleness detection via SHA-256 hash comparison. 33 new tests (370 total) covering: - add-entity with --fields and --from-yaml, --update flag - generate with REGENERATABLE/PRESERVED distinction, hash tracking - migrate subcommands and error handling - list with up-to-date, outdated, and missing states End-to-end verified: init → add-entity → list → generate workflow works. Closes Phase 6 in #1 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Previously, --entities parsed the YAML but only used entity names for router includes in main.py. Now it generates all 9 files per entity (model, schema, repo, service, router, factory, fake, tests) and updates .project-config.yaml with hashes. Also adds examples/rag_modulo.yaml — 20 entities from the rag_modulo project for end-to-end testing. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
File naming: - All generated files now use snake_case (conversation_session.py instead of conversationsession.py) - Added snake_case and pluralize Jinja2 filters to all template rendering environments - FK references use correct pluralized snake_case table names JSONB compatibility: - Changed JSONB to JSON in model template for cross-backend compat (SQLite doesn't support JSONB). Users can switch to JSONB in their PRESERVED model files for PostgreSQL. Smoke test: - examples/smoke_test_orchestrator.py compares DB call patterns between rag_modulo's orchestrator (11 ops) and FastStack (10 ops) - FastStack saves 1 call by caching the provider lookup - Run: PYTHONPATH=. python examples/smoke_test_orchestrator.py Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add dependencies.py.j2 template generating per-entity Depends() providers - Update router.py.j2: replace stub ... bodies with real service calls - Add _register_router_in_main() to auto-update main.py on add-entity - Add _regenerate_registry_files() for multi-entity templates (dependencies.py, integration conftest), called from add-entity, generate, and init --entities - Add conftest_integration.py.j2 with AsyncClient + fake repo DI overrides - Remove TODO comment from test_integration.py.j2 - 50 new tests (387 total): router wiring, registry files, main.py registration, multi-entity templates Closes #9 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Third pass in parse_entities_yaml() now creates reverse relationships on target entities. When Agent has FK to User (many_to_one), User automatically gets a one_to_many back to Agent. This fixes SQLAlchemy mapper failures when all generated models are imported together (e.g. running full test suite of a 20-entity project). Verified: rag_modulo 20-entity project generates correctly, all 100 generated unit tests pass. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- model.py.j2: use snake_case filter for TYPE_CHECKING imports instead of | lower (ConversationSession → conversation_session, not conversationsession) - yaml_parser.py: skip pluralization for already-plural words (LlmParameters → llm_parameters, not llm_parameterss) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…dd __repr__ - Remove third-pass reverse relationship generation from yaml_parser.py - Remove back_populates from all relationships (forward-only, user adds reverse when needed) - Remove TYPE_CHECKING imports and use string annotations via `from __future__ import annotations` - Add __repr__ with id + required fields (max 5) - User model is now clean (4 columns, no relationship clutter) - Agent model has forward `user` and `team` relationships without back_populates Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- fake_repository.py.j2: populate created_at/updated_at on create so AuditedEntity response schemas don't fail validation - test_integration.py.j2: include required FK fields (uuid values), handle json/jsonb fields as dicts instead of strings - test_unit_service.py.j2: add json/jsonb type handling in test data - conftest_integration.py.j2: add follow_redirects=True to AsyncClient to handle FastAPI trailing-slash redirects Verified: 160/160 generated tests pass (100 unit + 60 integration) for the 20-entity rag_modulo project. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Changed in pyproject.toml (ruff + black) and templates/project/pyproject.toml.j2. No flake8 — ruff covers those rules natively. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
533faf6 to
87cd1d4
Compare
46 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The final phase completing FastStack v1:
faststack add-entity—--fields "name:type:required",--from-yaml,--update. Generates all 9 entity files, respects PRESERVED vs REGENERATABLE.faststack generate— Regenerates REGENERATABLE files from model via AST introspection.--alland--forceflags.faststack migrate— Alembic wrapper (generate,upgrade,downgrade)faststack list— Entity status with SHA-256 staleness detectionEnd-to-end workflow now works
Test coverage
33 new tests (370 total)
How to test in Codespaces
Part of
Closes Phase 6 in #1 — FastStack v1 is complete!
🤖 Generated with Claude Code