Skip to content

Phase 6: Entity CLI commands — completing FastStack v1#9

Merged
manavgup merged 10 commits into
mainfrom
phase-6/entity-cli-commands
Apr 6, 2026
Merged

Phase 6: Entity CLI commands — completing FastStack v1#9
manavgup merged 10 commits into
mainfrom
phase-6/entity-cli-commands

Conversation

@manavgup
Copy link
Copy Markdown
Owner

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. --all and --force flags.
  • faststack migrate — Alembic wrapper (generate, upgrade, downgrade)
  • faststack list — Entity status with SHA-256 staleness detection

End-to-end workflow now works

faststack init blog-app
cd blog-app
faststack add-entity Post --fields "title:string:required,content:text,published:boolean"
faststack list                    # shows "up to date"
# edit app/models/post.py
faststack generate Post           # regenerates schemas/fakes
faststack list                    # shows "up to date" again
faststack migrate generate "add post"
faststack migrate upgrade

Test coverage

33 new tests (370 total)

How to test in Codespaces

git checkout phase-6/entity-cli-commands
make install
make check                        # 370 tests pass
faststack init my-test-app
cd my-test-app
faststack add-entity User --fields "email:string:required,name:string:required"
cat app/models/user.py            # see generated model
cat app/schemas/user.py           # see generated schemas
faststack list                    # shows User: up to date

Part of

Closes Phase 6 in #1FastStack v1 is complete!

🤖 Generated with Claude Code

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>
manavgup and others added 10 commits April 6, 2026 14:31
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>
@manavgup manavgup force-pushed the phase-6/entity-cli-commands branch from 533faf6 to 87cd1d4 Compare April 6, 2026 18:31
@manavgup manavgup merged commit 07df027 into main Apr 6, 2026
6 checks passed
@manavgup manavgup deleted the phase-6/entity-cli-commands branch April 6, 2026 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant