How maheshbabugorantla/dbtodrf works
Project type and purpose
• This is an open-source CLI tool (“drf-auto-generator”) whose sole purpose is to read a relational database schema and emit a fully configured Django + Django REST Framework project (models, serializers, views, URLs, admin, OpenAPI docs, tests).
File structure
• Top-level:
• drf_auto_generator/ – the Python package;
• examples/ – sample database + config to demonstrate usage;
• tests/ – unit & integration tests;
• config.sample.yaml, Makefile, pyproject.toml – build & configuration scaffolding.
• drf_auto_generator submodules:
• cli.py & ast_codegen_main.py – entrypoints;
• config_manager.py & config_validation.py – parse & validate YAML;
• introspection_django.py – read DB schema via Django;
• domain/ – in-memory representation of tables, fields, relationships;
• ast_codegen/ – classes to construct Python AST nodes for models, serializers, views, urls, admin, tests, project files;
• templates/ – Jinja2 templates for project boilerplate;
• codegen_utils.py, mapper.py, openapi_gen.py – helpers for mapping types, generating OpenAPI specs;
• colored_logging.py – CLI logging;
• exceptions.py, constants.py, validators.py – support.
Insights from the README
• Architecture is layered:
1. CLI reads config
2. Database introspection → domain model
3. AST-based code generator + template renderer → Django project
4. Write files to disk, run tests
• Supports extension points: custom field mapping, relation styles, test generation.
Final recommendation
• Be exhaustive in breaking out each submodule (e.g., show astro_codegen/admin.py, serializers.py as subcomponents of “AST Codegen”)
• With technologies & data formats (YAML, SQL, Python AST, Jinja2)
• The result will clearly reflect how a user’s config + DB drives code generation and file emission.