ai-first-cli 1.3.1 → 1.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.ai-dev/index.db +0 -0
- package/CHANGELOG.md +241 -0
- package/PHASE1_USER_SIMULATION.md +56 -0
- package/PHASE2_USER_SIMULATION.md +81 -0
- package/PHASE3_USER_SIMULATION.md +176 -0
- package/README.es.md +73 -0
- package/README.md +119 -15
- package/ai/graph/knowledge-graph.json +10 -0
- package/ai-context/ai_context.md +130 -0
- package/{test-projects/react-app/.ai-dev → ai-context}/ai_rules.md +10 -5
- package/ai-context/architecture.md +136 -0
- package/ai-context/context/features/src.json +69 -0
- package/ai-context/context/features/test-projects.json +69 -0
- package/ai-context/context/flows/ai-first.json +9 -0
- package/ai-context/context/flows/auth.json +13 -0
- package/ai-context/context/flows/doctor.json +9 -0
- package/ai-context/context/flows/explore.json +9 -0
- package/ai-context/context/flows/routes.json +15 -0
- package/ai-context/context/flows/user.json +23 -0
- package/ai-context/context/flows/views.json +12 -0
- package/{test-projects/react-app/.ai-dev → ai-context}/conventions.md +3 -2
- package/ai-context/dependencies.json +3360 -0
- package/ai-context/entrypoints.md +45 -0
- package/ai-context/index-state.json +196 -0
- package/ai-context/modules.json +901 -0
- package/ai-context/project.json +33 -0
- package/ai-context/repo_map.json +8857 -0
- package/ai-context/repo_map.md +2002 -0
- package/{test-projects/flask-app/.ai-dev → ai-context}/schema.json +1 -1
- package/ai-context/summary.md +46 -0
- package/ai-context/symbols.json +82467 -0
- package/{test-projects/react-app/.ai-dev → ai-context}/tech_stack.md +15 -7
- package/ai-context-evaluation-report-1774223059505.md +206 -0
- package/dist/analyzers/architecture.d.ts.map +1 -1
- package/dist/analyzers/architecture.js +78 -5
- package/dist/analyzers/architecture.js.map +1 -1
- package/dist/analyzers/entrypoints.d.ts.map +1 -1
- package/dist/analyzers/entrypoints.js +358 -0
- package/dist/analyzers/entrypoints.js.map +1 -1
- package/dist/analyzers/symbols.d.ts.map +1 -1
- package/dist/analyzers/symbols.js +119 -3
- package/dist/analyzers/symbols.js.map +1 -1
- package/dist/analyzers/techStack.d.ts +8 -0
- package/dist/analyzers/techStack.d.ts.map +1 -1
- package/dist/analyzers/techStack.js +118 -0
- package/dist/analyzers/techStack.js.map +1 -1
- package/dist/utils/fileUtils.d.ts.map +1 -1
- package/dist/utils/fileUtils.js +5 -0
- package/dist/utils/fileUtils.js.map +1 -1
- package/package.json +1 -1
- package/scripts/ai-context-evaluator.ts +440 -0
- package/src/analyzers/architecture.ts +83 -6
- package/src/analyzers/entrypoints.ts +400 -0
- package/src/analyzers/symbols.ts +129 -3
- package/src/analyzers/techStack.ts +137 -0
- package/src/utils/fileUtils.ts +5 -0
- package/tests/apex-parser.test.ts +193 -0
- package/tests/cli-commands-batch1.test.ts +808 -0
- package/tests/cli-commands-batch2.test.ts +1113 -0
- package/tests/cli-commands-batch3.test.ts +1128 -0
- package/tests/cli-index.test.ts +1007 -0
- package/tests/cli-init.test.ts +761 -0
- package/tests/entrypoints-languages.test.ts +373 -0
- package/tests/framework-detection.test.ts +296 -0
- package/tests/salesforce-apex-classes.test.ts +713 -0
- package/tests/salesforce-apex-triggers.test.ts +871 -0
- package/tests/salesforce-custom-objects.test.ts +918 -0
- package/tests/salesforce-flows.test.ts +710 -0
- package/tests/salesforce-lwc.test.ts +963 -0
- package/tests/salesforce-sfdx-integration.test.ts +1125 -0
- package/ANALISIS_COMPLETO.md +0 -424
- package/ANALISIS_MEJORAS.md +0 -327
- package/CONTRIBUTING.md +0 -89
- package/FLOW.md +0 -129
- package/TEST_RESULTS.md +0 -198
- package/TEST_RESULTS_COMPARATIVE.md +0 -159
- package/TEST_RESULTS_COMPLETE.md +0 -127
- package/TEST_RESULTS_COMPREHENSIVE.md +0 -208
- package/install.sh +0 -188
- package/run-all-tests.sh +0 -184
- package/test-ai-context-understanding.sh +0 -21
- package/test-projects/django-app/.ai-dev/ai_context.md +0 -92
- package/test-projects/django-app/.ai-dev/ai_rules.md +0 -47
- package/test-projects/django-app/.ai-dev/architecture.md +0 -57
- package/test-projects/django-app/.ai-dev/cache.json +0 -169
- package/test-projects/django-app/.ai-dev/context/flows/views.json +0 -10
- package/test-projects/django-app/.ai-dev/conventions.md +0 -51
- package/test-projects/django-app/.ai-dev/dependencies.json +0 -312
- package/test-projects/django-app/.ai-dev/entrypoints.md +0 -4
- package/test-projects/django-app/.ai-dev/files.json +0 -209
- package/test-projects/django-app/.ai-dev/graph/knowledge-graph.json +0 -36
- package/test-projects/django-app/.ai-dev/graph/module-graph.json +0 -145
- package/test-projects/django-app/.ai-dev/graph/symbol-graph.json +0 -1488
- package/test-projects/django-app/.ai-dev/graph/symbol-references.json +0 -1
- package/test-projects/django-app/.ai-dev/index-state.json +0 -294
- package/test-projects/django-app/.ai-dev/modules.json +0 -35
- package/test-projects/django-app/.ai-dev/project.json +0 -11
- package/test-projects/django-app/.ai-dev/repo_map.json +0 -412
- package/test-projects/django-app/.ai-dev/repo_map.md +0 -105
- package/test-projects/django-app/.ai-dev/schema.json +0 -5
- package/test-projects/django-app/.ai-dev/summary.md +0 -15
- package/test-projects/django-app/.ai-dev/symbols.json +0 -1
- package/test-projects/django-app/.ai-dev/tech_stack.md +0 -32
- package/test-projects/django-app/README.md +0 -91
- package/test-projects/django-app/blog/__init__.py +0 -0
- package/test-projects/django-app/blog/admin.py +0 -31
- package/test-projects/django-app/blog/models.py +0 -55
- package/test-projects/django-app/blog/serializers.py +0 -69
- package/test-projects/django-app/blog/urls.py +0 -14
- package/test-projects/django-app/blog/views.py +0 -96
- package/test-projects/django-app/django_app/__init__.py +0 -0
- package/test-projects/django-app/django_app/settings.py +0 -90
- package/test-projects/django-app/django_app/urls.py +0 -11
- package/test-projects/django-app/django_app/wsgi.py +0 -9
- package/test-projects/django-app/manage.py +0 -23
- package/test-projects/django-app/requirements.txt +0 -3
- package/test-projects/django-app/users/__init__.py +0 -0
- package/test-projects/django-app/users/admin.py +0 -42
- package/test-projects/django-app/users/models.py +0 -54
- package/test-projects/django-app/users/serializers.py +0 -113
- package/test-projects/django-app/users/urls.py +0 -13
- package/test-projects/django-app/users/views.py +0 -135
- package/test-projects/express-api/.ai-dev/ai_context.md +0 -112
- package/test-projects/express-api/.ai-dev/ai_rules.md +0 -50
- package/test-projects/express-api/.ai-dev/architecture.md +0 -62
- package/test-projects/express-api/.ai-dev/context/features/controllers.json +0 -13
- package/test-projects/express-api/.ai-dev/context/features/services.json +0 -13
- package/test-projects/express-api/.ai-dev/context/flows/auth.json +0 -12
- package/test-projects/express-api/.ai-dev/context/flows/user.json +0 -13
- package/test-projects/express-api/.ai-dev/conventions.md +0 -51
- package/test-projects/express-api/.ai-dev/dependencies.json +0 -54
- package/test-projects/express-api/.ai-dev/entrypoints.md +0 -17
- package/test-projects/express-api/.ai-dev/modules.json +0 -30
- package/test-projects/express-api/.ai-dev/project.json +0 -15
- package/test-projects/express-api/.ai-dev/repo_map.json +0 -100
- package/test-projects/express-api/.ai-dev/repo_map.md +0 -36
- package/test-projects/express-api/.ai-dev/schema.json +0 -5
- package/test-projects/express-api/.ai-dev/summary.md +0 -14
- package/test-projects/express-api/.ai-dev/symbols.json +0 -7
- package/test-projects/express-api/.ai-dev/tech_stack.md +0 -38
- package/test-projects/express-api/.ai-dev/tools.json +0 -10
- package/test-projects/express-api/controllers/authController.js +0 -32
- package/test-projects/express-api/controllers/userController.js +0 -51
- package/test-projects/express-api/index.js +0 -30
- package/test-projects/express-api/middleware/authMiddleware.js +0 -30
- package/test-projects/express-api/models/userRepository.js +0 -25
- package/test-projects/express-api/package.json +0 -18
- package/test-projects/express-api/services/authService.js +0 -17
- package/test-projects/express-api/services/userService.js +0 -28
- package/test-projects/fastapi-app/.ai-dev/ai_context.md +0 -89
- package/test-projects/fastapi-app/.ai-dev/ai_rules.md +0 -47
- package/test-projects/fastapi-app/.ai-dev/architecture.md +0 -39
- package/test-projects/fastapi-app/.ai-dev/cache.json +0 -125
- package/test-projects/fastapi-app/.ai-dev/conventions.md +0 -51
- package/test-projects/fastapi-app/.ai-dev/dependencies.json +0 -244
- package/test-projects/fastapi-app/.ai-dev/entrypoints.md +0 -4
- package/test-projects/fastapi-app/.ai-dev/files.json +0 -154
- package/test-projects/fastapi-app/.ai-dev/graph/knowledge-graph.json +0 -15
- package/test-projects/fastapi-app/.ai-dev/graph/module-graph.json +0 -78
- package/test-projects/fastapi-app/.ai-dev/graph/symbol-graph.json +0 -1724
- package/test-projects/fastapi-app/.ai-dev/graph/symbol-references.json +0 -51
- package/test-projects/fastapi-app/.ai-dev/index-state.json +0 -217
- package/test-projects/fastapi-app/.ai-dev/modules.json +0 -16
- package/test-projects/fastapi-app/.ai-dev/project.json +0 -9
- package/test-projects/fastapi-app/.ai-dev/repo_map.json +0 -298
- package/test-projects/fastapi-app/.ai-dev/repo_map.md +0 -74
- package/test-projects/fastapi-app/.ai-dev/schema.json +0 -5
- package/test-projects/fastapi-app/.ai-dev/summary.md +0 -12
- package/test-projects/fastapi-app/.ai-dev/symbols.json +0 -1
- package/test-projects/fastapi-app/.ai-dev/tech_stack.md +0 -32
- package/test-projects/fastapi-app/.ai-dev/tools.json +0 -10
- package/test-projects/fastapi-app/README.md +0 -118
- package/test-projects/fastapi-app/app/database.py +0 -21
- package/test-projects/fastapi-app/app/dependencies.py +0 -107
- package/test-projects/fastapi-app/app/main.py +0 -47
- package/test-projects/fastapi-app/app/models.py +0 -149
- package/test-projects/fastapi-app/app/routers/auth.py +0 -117
- package/test-projects/fastapi-app/app/routers/posts.py +0 -272
- package/test-projects/fastapi-app/app/schemas.py +0 -191
- package/test-projects/fastapi-app/requirements.txt +0 -10
- package/test-projects/flask-app/.ai-dev/ai_context.md +0 -94
- package/test-projects/flask-app/.ai-dev/ai_rules.md +0 -47
- package/test-projects/flask-app/.ai-dev/architecture.md +0 -49
- package/test-projects/flask-app/.ai-dev/cache.json +0 -157
- package/test-projects/flask-app/.ai-dev/context/features/app.json +0 -25
- package/test-projects/flask-app/.ai-dev/context/flows/routes.json +0 -14
- package/test-projects/flask-app/.ai-dev/conventions.md +0 -51
- package/test-projects/flask-app/.ai-dev/dependencies.json +0 -298
- package/test-projects/flask-app/.ai-dev/entrypoints.md +0 -4
- package/test-projects/flask-app/.ai-dev/files.json +0 -194
- package/test-projects/flask-app/.ai-dev/graph/knowledge-graph.json +0 -60
- package/test-projects/flask-app/.ai-dev/graph/module-graph.json +0 -95
- package/test-projects/flask-app/.ai-dev/graph/symbol-graph.json +0 -1448
- package/test-projects/flask-app/.ai-dev/graph/symbol-references.json +0 -45
- package/test-projects/flask-app/.ai-dev/index-state.json +0 -273
- package/test-projects/flask-app/.ai-dev/modules.json +0 -21
- package/test-projects/flask-app/.ai-dev/project.json +0 -13
- package/test-projects/flask-app/.ai-dev/repo_map.json +0 -400
- package/test-projects/flask-app/.ai-dev/repo_map.md +0 -98
- package/test-projects/flask-app/.ai-dev/summary.md +0 -13
- package/test-projects/flask-app/.ai-dev/symbols.json +0 -1
- package/test-projects/flask-app/.ai-dev/tech_stack.md +0 -32
- package/test-projects/flask-app/.ai-dev/tools.json +0 -10
- package/test-projects/flask-app/README.md +0 -129
- package/test-projects/flask-app/app/__init__.py +0 -46
- package/test-projects/flask-app/app/api/__init__.py +0 -7
- package/test-projects/flask-app/app/api/routes.py +0 -122
- package/test-projects/flask-app/app/auth/__init__.py +0 -7
- package/test-projects/flask-app/app/auth/forms.py +0 -52
- package/test-projects/flask-app/app/auth/routes.py +0 -68
- package/test-projects/flask-app/app/blog/__init__.py +0 -7
- package/test-projects/flask-app/app/blog/forms.py +0 -35
- package/test-projects/flask-app/app/blog/routes.py +0 -140
- package/test-projects/flask-app/app/main/__init__.py +0 -7
- package/test-projects/flask-app/app/main/routes.py +0 -88
- package/test-projects/flask-app/app/models.py +0 -177
- package/test-projects/flask-app/config.py +0 -64
- package/test-projects/flask-app/requirements.txt +0 -10
- package/test-projects/laravel-app/.ai-dev/ai_context.md +0 -97
- package/test-projects/laravel-app/.ai-dev/ai_rules.md +0 -47
- package/test-projects/laravel-app/.ai-dev/architecture.md +0 -60
- package/test-projects/laravel-app/.ai-dev/cache.json +0 -161
- package/test-projects/laravel-app/.ai-dev/context/features/app.json +0 -21
- package/test-projects/laravel-app/.ai-dev/context/flows/.json +0 -9
- package/test-projects/laravel-app/.ai-dev/context/flows/category.json +0 -12
- package/test-projects/laravel-app/.ai-dev/context/flows/comment.json +0 -12
- package/test-projects/laravel-app/.ai-dev/context/flows/post.json +0 -12
- package/test-projects/laravel-app/.ai-dev/context/flows/unnamed.json +0 -9
- package/test-projects/laravel-app/.ai-dev/conventions.md +0 -51
- package/test-projects/laravel-app/.ai-dev/dependencies.json +0 -6
- package/test-projects/laravel-app/.ai-dev/entrypoints.md +0 -4
- package/test-projects/laravel-app/.ai-dev/files.json +0 -199
- package/test-projects/laravel-app/.ai-dev/graph/knowledge-graph.json +0 -98
- package/test-projects/laravel-app/.ai-dev/graph/module-graph.json +0 -30
- package/test-projects/laravel-app/.ai-dev/graph/symbol-graph.json +0 -5
- package/test-projects/laravel-app/.ai-dev/graph/symbol-references.json +0 -1
- package/test-projects/laravel-app/.ai-dev/index-state.json +0 -280
- package/test-projects/laravel-app/.ai-dev/modules.json +0 -29
- package/test-projects/laravel-app/.ai-dev/project.json +0 -17
- package/test-projects/laravel-app/.ai-dev/repo_map.json +0 -419
- package/test-projects/laravel-app/.ai-dev/repo_map.md +0 -106
- package/test-projects/laravel-app/.ai-dev/schema.json +0 -5
- package/test-projects/laravel-app/.ai-dev/summary.md +0 -15
- package/test-projects/laravel-app/.ai-dev/symbols.json +0 -1
- package/test-projects/laravel-app/.ai-dev/tech_stack.md +0 -34
- package/test-projects/laravel-app/.ai-dev/tools.json +0 -10
- package/test-projects/laravel-app/README.md +0 -107
- package/test-projects/laravel-app/app/Http/Controllers/Api/CategoryController.php +0 -88
- package/test-projects/laravel-app/app/Http/Controllers/Api/CommentController.php +0 -56
- package/test-projects/laravel-app/app/Http/Controllers/Api/PostController.php +0 -174
- package/test-projects/laravel-app/app/Http/Controllers/Controller.php +0 -12
- package/test-projects/laravel-app/app/Models/Category.php +0 -34
- package/test-projects/laravel-app/app/Models/Comment.php +0 -51
- package/test-projects/laravel-app/app/Models/Post.php +0 -108
- package/test-projects/laravel-app/app/Models/User.php +0 -85
- package/test-projects/laravel-app/bootstrap/app.php +0 -25
- package/test-projects/laravel-app/composer.json +0 -35
- package/test-projects/laravel-app/routes/api.php +0 -40
- package/test-projects/nestjs-backend/.ai-dev/ai_context.md +0 -111
- package/test-projects/nestjs-backend/.ai-dev/ai_rules.md +0 -52
- package/test-projects/nestjs-backend/.ai-dev/architecture.md +0 -49
- package/test-projects/nestjs-backend/.ai-dev/cache.json +0 -169
- package/test-projects/nestjs-backend/.ai-dev/context/features/src.json +0 -23
- package/test-projects/nestjs-backend/.ai-dev/context/flows/auth.controller.json +0 -14
- package/test-projects/nestjs-backend/.ai-dev/context/flows/auth.json +0 -10
- package/test-projects/nestjs-backend/.ai-dev/context/flows/users..json +0 -10
- package/test-projects/nestjs-backend/.ai-dev/context/flows/users.controller.json +0 -14
- package/test-projects/nestjs-backend/.ai-dev/context/flows/users.json +0 -10
- package/test-projects/nestjs-backend/.ai-dev/conventions.md +0 -52
- package/test-projects/nestjs-backend/.ai-dev/dependencies.json +0 -152
- package/test-projects/nestjs-backend/.ai-dev/entrypoints.md +0 -18
- package/test-projects/nestjs-backend/.ai-dev/files.json +0 -209
- package/test-projects/nestjs-backend/.ai-dev/graph/knowledge-graph.json +0 -132
- package/test-projects/nestjs-backend/.ai-dev/graph/module-graph.json +0 -29
- package/test-projects/nestjs-backend/.ai-dev/graph/symbol-graph.json +0 -304
- package/test-projects/nestjs-backend/.ai-dev/graph/symbol-references.json +0 -5
- package/test-projects/nestjs-backend/.ai-dev/index-state.json +0 -294
- package/test-projects/nestjs-backend/.ai-dev/modules.json +0 -19
- package/test-projects/nestjs-backend/.ai-dev/project.json +0 -18
- package/test-projects/nestjs-backend/.ai-dev/repo_map.json +0 -427
- package/test-projects/nestjs-backend/.ai-dev/repo_map.md +0 -104
- package/test-projects/nestjs-backend/.ai-dev/schema.json +0 -5
- package/test-projects/nestjs-backend/.ai-dev/summary.md +0 -13
- package/test-projects/nestjs-backend/.ai-dev/symbols.json +0 -1
- package/test-projects/nestjs-backend/.ai-dev/tech_stack.md +0 -38
- package/test-projects/nestjs-backend/.ai-dev/tools.json +0 -10
- package/test-projects/nestjs-backend/package.json +0 -22
- package/test-projects/nestjs-backend/src/app.module.ts +0 -8
- package/test-projects/nestjs-backend/src/auth/auth.controller.ts +0 -22
- package/test-projects/nestjs-backend/src/auth/auth.module.ts +0 -11
- package/test-projects/nestjs-backend/src/auth/auth.service.ts +0 -28
- package/test-projects/nestjs-backend/src/auth/dto/login.dto.ts +0 -4
- package/test-projects/nestjs-backend/src/auth/strategies/jwt.strategy.ts +0 -18
- package/test-projects/nestjs-backend/src/main.ts +0 -9
- package/test-projects/nestjs-backend/src/users/users.controller.ts +0 -32
- package/test-projects/nestjs-backend/src/users/users.module.ts +0 -10
- package/test-projects/nestjs-backend/src/users/users.service.ts +0 -42
- package/test-projects/nestjs-backend/tsconfig.json +0 -21
- package/test-projects/python-cli/.ai-dev/ai_context.md +0 -95
- package/test-projects/python-cli/.ai-dev/ai_rules.md +0 -47
- package/test-projects/python-cli/.ai-dev/architecture.md +0 -55
- package/test-projects/python-cli/.ai-dev/cache.json +0 -149
- package/test-projects/python-cli/.ai-dev/context/features/cli.json +0 -16
- package/test-projects/python-cli/.ai-dev/context/flows/list_.json +0 -9
- package/test-projects/python-cli/.ai-dev/context/flows/remove_.json +0 -9
- package/test-projects/python-cli/.ai-dev/conventions.md +0 -51
- package/test-projects/python-cli/.ai-dev/dependencies.json +0 -66
- package/test-projects/python-cli/.ai-dev/entrypoints.md +0 -4
- package/test-projects/python-cli/.ai-dev/files.json +0 -184
- package/test-projects/python-cli/.ai-dev/graph/knowledge-graph.json +0 -83
- package/test-projects/python-cli/.ai-dev/graph/module-graph.json +0 -31
- package/test-projects/python-cli/.ai-dev/graph/symbol-graph.json +0 -358
- package/test-projects/python-cli/.ai-dev/graph/symbol-references.json +0 -11
- package/test-projects/python-cli/.ai-dev/index-state.json +0 -259
- package/test-projects/python-cli/.ai-dev/modules.json +0 -21
- package/test-projects/python-cli/.ai-dev/project.json +0 -15
- package/test-projects/python-cli/.ai-dev/repo_map.json +0 -367
- package/test-projects/python-cli/.ai-dev/repo_map.md +0 -93
- package/test-projects/python-cli/.ai-dev/schema.json +0 -5
- package/test-projects/python-cli/.ai-dev/summary.md +0 -14
- package/test-projects/python-cli/.ai-dev/symbols.json +0 -1
- package/test-projects/python-cli/.ai-dev/tech_stack.md +0 -32
- package/test-projects/python-cli/.ai-dev/tools.json +0 -10
- package/test-projects/python-cli/__init__.py +0 -1
- package/test-projects/python-cli/cli/__init__.py +0 -1
- package/test-projects/python-cli/cli/add_command.py +0 -6
- package/test-projects/python-cli/cli/list_command.py +0 -7
- package/test-projects/python-cli/cli/remove_command.py +0 -6
- package/test-projects/python-cli/main.py +0 -34
- package/test-projects/python-cli/models/__init__.py +0 -2
- package/test-projects/python-cli/models/task.py +0 -19
- package/test-projects/python-cli/models/task_repository.py +0 -44
- package/test-projects/rails-app/.ai-dev/ai_context.md +0 -94
- package/test-projects/rails-app/.ai-dev/ai_rules.md +0 -47
- package/test-projects/rails-app/.ai-dev/architecture.md +0 -49
- package/test-projects/rails-app/.ai-dev/cache.json +0 -193
- package/test-projects/rails-app/.ai-dev/context/features/app.json +0 -24
- package/test-projects/rails-app/.ai-dev/context/features/config.json +0 -13
- package/test-projects/rails-app/.ai-dev/context/flows/application.json +0 -9
- package/test-projects/rails-app/.ai-dev/context/flows/application_.json +0 -9
- package/test-projects/rails-app/.ai-dev/context/flows/comments.json +0 -11
- package/test-projects/rails-app/.ai-dev/context/flows/comments_.json +0 -11
- package/test-projects/rails-app/.ai-dev/context/flows/posts.json +0 -11
- package/test-projects/rails-app/.ai-dev/context/flows/posts_.json +0 -11
- package/test-projects/rails-app/.ai-dev/context/flows/routes.json +0 -9
- package/test-projects/rails-app/.ai-dev/context/flows/users.json +0 -11
- package/test-projects/rails-app/.ai-dev/context/flows/users_.json +0 -11
- package/test-projects/rails-app/.ai-dev/conventions.md +0 -51
- package/test-projects/rails-app/.ai-dev/dependencies.json +0 -6
- package/test-projects/rails-app/.ai-dev/entrypoints.md +0 -4
- package/test-projects/rails-app/.ai-dev/files.json +0 -239
- package/test-projects/rails-app/.ai-dev/graph/knowledge-graph.json +0 -130
- package/test-projects/rails-app/.ai-dev/graph/module-graph.json +0 -27
- package/test-projects/rails-app/.ai-dev/graph/symbol-graph.json +0 -5
- package/test-projects/rails-app/.ai-dev/graph/symbol-references.json +0 -1
- package/test-projects/rails-app/.ai-dev/index-state.json +0 -336
- package/test-projects/rails-app/.ai-dev/modules.json +0 -26
- package/test-projects/rails-app/.ai-dev/project.json +0 -22
- package/test-projects/rails-app/.ai-dev/repo_map.json +0 -486
- package/test-projects/rails-app/.ai-dev/repo_map.md +0 -117
- package/test-projects/rails-app/.ai-dev/schema.json +0 -5
- package/test-projects/rails-app/.ai-dev/summary.md +0 -13
- package/test-projects/rails-app/.ai-dev/symbols.json +0 -1
- package/test-projects/rails-app/.ai-dev/tech_stack.md +0 -32
- package/test-projects/rails-app/.ai-dev/tools.json +0 -10
- package/test-projects/rails-app/Gemfile +0 -38
- package/test-projects/rails-app/README.md +0 -140
- package/test-projects/rails-app/Rakefile +0 -8
- package/test-projects/rails-app/app/controllers/api/comments_controller.rb +0 -75
- package/test-projects/rails-app/app/controllers/api/posts_controller.rb +0 -68
- package/test-projects/rails-app/app/controllers/api/users_controller.rb +0 -54
- package/test-projects/rails-app/app/controllers/application_controller.rb +0 -31
- package/test-projects/rails-app/app/models/comment.rb +0 -34
- package/test-projects/rails-app/app/models/post.rb +0 -36
- package/test-projects/rails-app/app/models/user.rb +0 -28
- package/test-projects/rails-app/app/services/post_service.rb +0 -92
- package/test-projects/rails-app/app/services/user_service.rb +0 -76
- package/test-projects/rails-app/config/application.rb +0 -27
- package/test-projects/rails-app/config/environment.rb +0 -7
- package/test-projects/rails-app/config/routes.rb +0 -15
- package/test-projects/react-app/.ai-dev/ai_context.md +0 -96
- package/test-projects/react-app/.ai-dev/architecture.md +0 -39
- package/test-projects/react-app/.ai-dev/cache.json +0 -153
- package/test-projects/react-app/.ai-dev/context/features/src.json +0 -18
- package/test-projects/react-app/.ai-dev/context/flows/UsersPage.json +0 -14
- package/test-projects/react-app/.ai-dev/context/flows/dashboard.json +0 -9
- package/test-projects/react-app/.ai-dev/context/flows/login.json +0 -9
- package/test-projects/react-app/.ai-dev/context/flows/users.json +0 -9
- package/test-projects/react-app/.ai-dev/dependencies.json +0 -128
- package/test-projects/react-app/.ai-dev/entrypoints.md +0 -4
- package/test-projects/react-app/.ai-dev/files.json +0 -189
- package/test-projects/react-app/.ai-dev/graph/knowledge-graph.json +0 -112
- package/test-projects/react-app/.ai-dev/graph/module-graph.json +0 -31
- package/test-projects/react-app/.ai-dev/graph/symbol-graph.json +0 -868
- package/test-projects/react-app/.ai-dev/graph/symbol-references.json +0 -31
- package/test-projects/react-app/.ai-dev/index-state.json +0 -266
- package/test-projects/react-app/.ai-dev/modules.json +0 -17
- package/test-projects/react-app/.ai-dev/project.json +0 -16
- package/test-projects/react-app/.ai-dev/repo_map.json +0 -391
- package/test-projects/react-app/.ai-dev/repo_map.md +0 -94
- package/test-projects/react-app/.ai-dev/schema.json +0 -5
- package/test-projects/react-app/.ai-dev/summary.md +0 -13
- package/test-projects/react-app/.ai-dev/symbols.json +0 -1
- package/test-projects/react-app/.ai-dev/tools.json +0 -10
- package/test-projects/react-app/package.json +0 -16
- package/test-projects/react-app/src/App.tsx +0 -21
- package/test-projects/react-app/src/context/AuthContext.tsx +0 -41
- package/test-projects/react-app/src/hooks/useAuth.ts +0 -10
- package/test-projects/react-app/src/main.tsx +0 -10
- package/test-projects/react-app/src/pages/DashboardPage.tsx +0 -17
- package/test-projects/react-app/src/pages/LoginPage.tsx +0 -41
- package/test-projects/react-app/src/pages/UsersPage.tsx +0 -36
- package/test-projects/react-app/src/services/userService.ts +0 -37
- package/test-projects/salesforce-cli/.ai-dev/ai_context.md +0 -89
- package/test-projects/salesforce-cli/.ai-dev/ai_rules.md +0 -47
- package/test-projects/salesforce-cli/.ai-dev/architecture.md +0 -39
- package/test-projects/salesforce-cli/.ai-dev/cache.json +0 -125
- package/test-projects/salesforce-cli/.ai-dev/context/features/force-app.json +0 -14
- package/test-projects/salesforce-cli/.ai-dev/context/flows/account.json +0 -9
- package/test-projects/salesforce-cli/.ai-dev/context/flows/opportunity.json +0 -9
- package/test-projects/salesforce-cli/.ai-dev/conventions.md +0 -51
- package/test-projects/salesforce-cli/.ai-dev/dependencies.json +0 -6
- package/test-projects/salesforce-cli/.ai-dev/entrypoints.md +0 -4
- package/test-projects/salesforce-cli/.ai-dev/files.json +0 -154
- package/test-projects/salesforce-cli/.ai-dev/graph/knowledge-graph.json +0 -64
- package/test-projects/salesforce-cli/.ai-dev/graph/module-graph.json +0 -13
- package/test-projects/salesforce-cli/.ai-dev/graph/symbol-graph.json +0 -148
- package/test-projects/salesforce-cli/.ai-dev/graph/symbol-references.json +0 -1
- package/test-projects/salesforce-cli/.ai-dev/index-state.json +0 -217
- package/test-projects/salesforce-cli/.ai-dev/modules.json +0 -12
- package/test-projects/salesforce-cli/.ai-dev/project.json +0 -14
- package/test-projects/salesforce-cli/.ai-dev/repo_map.json +0 -328
- package/test-projects/salesforce-cli/.ai-dev/repo_map.md +0 -80
- package/test-projects/salesforce-cli/.ai-dev/schema.json +0 -5
- package/test-projects/salesforce-cli/.ai-dev/summary.md +0 -13
- package/test-projects/salesforce-cli/.ai-dev/symbols.json +0 -1
- package/test-projects/salesforce-cli/.ai-dev/tech_stack.md +0 -31
- package/test-projects/salesforce-cli/.ai-dev/tools.json +0 -10
- package/test-projects/salesforce-cli/.forceignore +0 -27
- package/test-projects/salesforce-cli/force-app/main/default/classes/AccountController.cls +0 -24
- package/test-projects/salesforce-cli/force-app/main/default/classes/OpportunityController.cls +0 -25
- package/test-projects/salesforce-cli/force-app/main/default/objects/Project__c.object.xml +0 -45
- package/test-projects/salesforce-cli/force-app/main/default/triggers/AccountTrigger.trigger +0 -33
- package/test-projects/salesforce-cli/sfdx-project.json +0 -11
- package/test-projects/spring-boot-app/.ai-dev/ai_context.md +0 -91
- package/test-projects/spring-boot-app/.ai-dev/ai_rules.md +0 -48
- package/test-projects/spring-boot-app/.ai-dev/architecture.md +0 -39
- package/test-projects/spring-boot-app/.ai-dev/cache.json +0 -173
- package/test-projects/spring-boot-app/.ai-dev/context/features/src.json +0 -26
- package/test-projects/spring-boot-app/.ai-dev/context/flows/PostController.json +0 -19
- package/test-projects/spring-boot-app/.ai-dev/context/flows/UserController.json +0 -19
- package/test-projects/spring-boot-app/.ai-dev/context/flows/comment.json +0 -11
- package/test-projects/spring-boot-app/.ai-dev/context/flows/post.json +0 -14
- package/test-projects/spring-boot-app/.ai-dev/context/flows/user.json +0 -14
- package/test-projects/spring-boot-app/.ai-dev/conventions.md +0 -52
- package/test-projects/spring-boot-app/.ai-dev/dependencies.json +0 -326
- package/test-projects/spring-boot-app/.ai-dev/entrypoints.md +0 -4
- package/test-projects/spring-boot-app/.ai-dev/files.json +0 -214
- package/test-projects/spring-boot-app/.ai-dev/graph/knowledge-graph.json +0 -231
- package/test-projects/spring-boot-app/.ai-dev/graph/module-graph.json +0 -22
- package/test-projects/spring-boot-app/.ai-dev/graph/symbol-graph.json +0 -794
- package/test-projects/spring-boot-app/.ai-dev/graph/symbol-references.json +0 -70
- package/test-projects/spring-boot-app/.ai-dev/index-state.json +0 -301
- package/test-projects/spring-boot-app/.ai-dev/modules.json +0 -21
- package/test-projects/spring-boot-app/.ai-dev/project.json +0 -17
- package/test-projects/spring-boot-app/.ai-dev/repo_map.json +0 -461
- package/test-projects/spring-boot-app/.ai-dev/repo_map.md +0 -109
- package/test-projects/spring-boot-app/.ai-dev/schema.json +0 -5
- package/test-projects/spring-boot-app/.ai-dev/summary.md +0 -12
- package/test-projects/spring-boot-app/.ai-dev/symbols.json +0 -1
- package/test-projects/spring-boot-app/.ai-dev/tech_stack.md +0 -32
- package/test-projects/spring-boot-app/.ai-dev/tools.json +0 -10
- package/test-projects/spring-boot-app/.classpath +0 -57
- package/test-projects/spring-boot-app/.factorypath +0 -69
- package/test-projects/spring-boot-app/.project +0 -34
- package/test-projects/spring-boot-app/.settings/org.eclipse.core.resources.prefs +0 -4
- package/test-projects/spring-boot-app/.settings/org.eclipse.jdt.apt.core.prefs +0 -4
- package/test-projects/spring-boot-app/.settings/org.eclipse.jdt.core.prefs +0 -10
- package/test-projects/spring-boot-app/.settings/org.eclipse.m2e.core.prefs +0 -4
- package/test-projects/spring-boot-app/README.md +0 -122
- package/test-projects/spring-boot-app/pom.xml +0 -79
- package/test-projects/spring-boot-app/src/main/java/com/example/demo/DemoApplication.java +0 -12
- package/test-projects/spring-boot-app/src/main/java/com/example/demo/controllers/CommentController.java +0 -89
- package/test-projects/spring-boot-app/src/main/java/com/example/demo/controllers/PostController.java +0 -92
- package/test-projects/spring-boot-app/src/main/java/com/example/demo/controllers/UserController.java +0 -84
- package/test-projects/spring-boot-app/src/main/java/com/example/demo/models/Comment.java +0 -38
- package/test-projects/spring-boot-app/src/main/java/com/example/demo/models/Post.java +0 -56
- package/test-projects/spring-boot-app/src/main/java/com/example/demo/models/User.java +0 -44
- package/test-projects/spring-boot-app/src/main/java/com/example/demo/repositories/CommentRepository.java +0 -21
- package/test-projects/spring-boot-app/src/main/java/com/example/demo/repositories/PostRepository.java +0 -18
- package/test-projects/spring-boot-app/src/main/java/com/example/demo/repositories/UserRepository.java +0 -15
- package/test-projects/spring-boot-app/src/main/java/com/example/demo/services/PostService.java +0 -83
- package/test-projects/spring-boot-app/src/main/java/com/example/demo/services/UserService.java +0 -62
- package/test-projects/spring-boot-app/src/main/resources/application.properties +0 -22
- package/test-projects/spring-boot-app/target/classes/com/example/demo/DemoApplication.class +0 -0
- package/test-projects/spring-boot-app/target/classes/com/example/demo/controllers/CommentController$CommentCreateRequest.class +0 -0
- package/test-projects/spring-boot-app/target/classes/com/example/demo/controllers/CommentController$CommentUpdateRequest.class +0 -0
- package/test-projects/spring-boot-app/target/classes/com/example/demo/controllers/CommentController.class +0 -0
- package/test-projects/spring-boot-app/target/classes/com/example/demo/controllers/PostController$PostCreateRequest.class +0 -0
- package/test-projects/spring-boot-app/target/classes/com/example/demo/controllers/PostController$PostUpdateRequest.class +0 -0
- package/test-projects/spring-boot-app/target/classes/com/example/demo/controllers/PostController.class +0 -0
- package/test-projects/spring-boot-app/target/classes/com/example/demo/controllers/UserController$UserCreateRequest.class +0 -0
- package/test-projects/spring-boot-app/target/classes/com/example/demo/controllers/UserController$UserUpdateRequest.class +0 -0
- package/test-projects/spring-boot-app/target/classes/com/example/demo/controllers/UserController.class +0 -0
- package/test-projects/spring-boot-app/target/classes/com/example/demo/models/Comment.class +0 -0
- package/test-projects/spring-boot-app/target/classes/com/example/demo/models/Post.class +0 -0
- package/test-projects/spring-boot-app/target/classes/com/example/demo/models/User.class +0 -0
- package/test-projects/spring-boot-app/target/classes/com/example/demo/repositories/CommentRepository.class +0 -0
- package/test-projects/spring-boot-app/target/classes/com/example/demo/repositories/PostRepository.class +0 -0
- package/test-projects/spring-boot-app/target/classes/com/example/demo/repositories/UserRepository.class +0 -0
- package/test-projects/spring-boot-app/target/classes/com/example/demo/services/PostService.class +0 -0
- package/test-projects/spring-boot-app/target/classes/com/example/demo/services/UserService.class +0 -0
- package/tests/e2e/run-e2e.sh +0 -88
- /package/{test-projects/django-app/.ai-dev → ai-context}/tools.json +0 -0
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
# Technology Stack
|
|
2
|
-
|
|
3
|
-
**Languages**: Markdown, JSON, Python
|
|
4
|
-
|
|
5
|
-
## Languages
|
|
6
|
-
- Markdown
|
|
7
|
-
- JSON
|
|
8
|
-
- Python
|
|
9
|
-
|
|
10
|
-
## Frameworks
|
|
11
|
-
- None detected
|
|
12
|
-
|
|
13
|
-
## Key Libraries
|
|
14
|
-
- None detected
|
|
15
|
-
|
|
16
|
-
## Development Tools
|
|
17
|
-
- None detected
|
|
18
|
-
|
|
19
|
-
## Package Managers
|
|
20
|
-
- None detected
|
|
21
|
-
|
|
22
|
-
## Testing
|
|
23
|
-
- None detected
|
|
24
|
-
|
|
25
|
-
## Linters
|
|
26
|
-
- None detected
|
|
27
|
-
|
|
28
|
-
## Formatters
|
|
29
|
-
- None detected
|
|
30
|
-
|
|
31
|
-
---
|
|
32
|
-
*Generated by ai-first*
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
# FastAPI Blog
|
|
2
|
-
|
|
3
|
-
A modern, fast blog API built with FastAPI, SQLAlchemy, and Pydantic.
|
|
4
|
-
|
|
5
|
-
## Features
|
|
6
|
-
|
|
7
|
-
- **High Performance**: Built on FastAPI (one of the fastest Python frameworks)
|
|
8
|
-
- **Automatic API Documentation**: Interactive docs at `/docs` (Swagger UI) and `/redoc` (ReDoc)
|
|
9
|
-
- **Type Safety**: Full type hints with Pydantic models
|
|
10
|
-
- **Authentication**: JWT token-based authentication
|
|
11
|
-
- **Database**: SQLAlchemy ORM with SQLite (easily switchable to PostgreSQL)
|
|
12
|
-
- **Modern Python**: Python 3.9+ with async support
|
|
13
|
-
|
|
14
|
-
## Project Structure
|
|
15
|
-
|
|
16
|
-
```
|
|
17
|
-
fastapi-app/
|
|
18
|
-
├── app/
|
|
19
|
-
│ ├── __init__.py
|
|
20
|
-
│ ├── main.py # FastAPI application entry point
|
|
21
|
-
│ ├── database.py # Database configuration
|
|
22
|
-
│ ├── models.py # SQLAlchemy models
|
|
23
|
-
│ ├── schemas.py # Pydantic schemas
|
|
24
|
-
│ ├── dependencies.py # Authentication & dependencies
|
|
25
|
-
│ └── routers/
|
|
26
|
-
│ ├── __init__.py
|
|
27
|
-
│ ├── auth.py # Authentication endpoints
|
|
28
|
-
│ └── posts.py # Blog post endpoints
|
|
29
|
-
├── tests/
|
|
30
|
-
└── requirements.txt
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
## Models
|
|
34
|
-
|
|
35
|
-
### User
|
|
36
|
-
- Authentication with JWT tokens
|
|
37
|
-
- Profile information (bio, full_name)
|
|
38
|
-
- Relationships: posts, comments
|
|
39
|
-
|
|
40
|
-
### Post
|
|
41
|
-
- Blog posts with title, content, slug
|
|
42
|
-
- Publishing workflow (draft → published)
|
|
43
|
-
- Categories and tags
|
|
44
|
-
- View counter
|
|
45
|
-
|
|
46
|
-
### Comment
|
|
47
|
-
- Nested comments (replies)
|
|
48
|
-
- Approval system
|
|
49
|
-
|
|
50
|
-
### Category
|
|
51
|
-
- Post categorization
|
|
52
|
-
- URL-friendly slugs
|
|
53
|
-
|
|
54
|
-
### Tag
|
|
55
|
-
- Post tagging system
|
|
56
|
-
- Many-to-many relationship with posts
|
|
57
|
-
|
|
58
|
-
## API Endpoints
|
|
59
|
-
|
|
60
|
-
### Authentication
|
|
61
|
-
- `POST /api/v1/auth/register` - Register new user
|
|
62
|
-
- `POST /api/v1/auth/token` - Login and get token
|
|
63
|
-
- `GET /api/v1/auth/me` - Get current user
|
|
64
|
-
- `PUT /api/v1/auth/me` - Update profile
|
|
65
|
-
- `POST /api/v1/auth/change-password` - Change password
|
|
66
|
-
|
|
67
|
-
### Posts
|
|
68
|
-
- `GET /api/v1/posts/` - List posts (with filters)
|
|
69
|
-
- `POST /api/v1/posts/` - Create post
|
|
70
|
-
- `GET /api/v1/posts/{slug}` - Get single post
|
|
71
|
-
- `PUT /api/v1/posts/{post_id}` - Update post
|
|
72
|
-
- `DELETE /api/v1/posts/{post_id}` - Delete post
|
|
73
|
-
- `POST /api/v1/posts/{post_id}/publish` - Publish post
|
|
74
|
-
- `GET /api/v1/posts/my/posts` - Get my posts
|
|
75
|
-
|
|
76
|
-
### Filters Available
|
|
77
|
-
- `category_slug` - Filter by category
|
|
78
|
-
- `tag_slug` - Filter by tag
|
|
79
|
-
- `search` - Search in title/content
|
|
80
|
-
- `published_only` - Show only published (default: true)
|
|
81
|
-
|
|
82
|
-
## Setup
|
|
83
|
-
|
|
84
|
-
```bash
|
|
85
|
-
# Install dependencies
|
|
86
|
-
pip install -r requirements.txt
|
|
87
|
-
|
|
88
|
-
# Run the application
|
|
89
|
-
python -m app.main
|
|
90
|
-
|
|
91
|
-
# Or using uvicorn directly
|
|
92
|
-
uvicorn app.main:app --reload
|
|
93
|
-
|
|
94
|
-
# Access API documentation
|
|
95
|
-
# OpenAPI (Swagger UI): http://localhost:8000/docs
|
|
96
|
-
# ReDoc: http://localhost:8000/redoc
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
## Testing with ai-first
|
|
100
|
-
|
|
101
|
-
```bash
|
|
102
|
-
# Generate AI context
|
|
103
|
-
ai-first init --root fastapi-app
|
|
104
|
-
|
|
105
|
-
# Generate repository map
|
|
106
|
-
ai-first map --root fastapi-app
|
|
107
|
-
|
|
108
|
-
# Generate SQLite index
|
|
109
|
-
ai-first index --root fastapi-app
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
## Key Features
|
|
113
|
-
|
|
114
|
-
- **Pydantic v2**: Latest version with better performance
|
|
115
|
-
- **SQLAlchemy 2.0**: Modern ORM syntax
|
|
116
|
-
- **Dependency Injection**: FastAPI's powerful DI system
|
|
117
|
-
- **Automatic Validation**: Request/response validation out of the box
|
|
118
|
-
- **Type Hints**: Full IDE support with autocomplete
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
from sqlalchemy import create_engine
|
|
2
|
-
from sqlalchemy.ext.declarative import declarative_base
|
|
3
|
-
from sqlalchemy.orm import sessionmaker
|
|
4
|
-
|
|
5
|
-
SQLALCHEMY_DATABASE_URL = "sqlite:///./fastapi_app.db"
|
|
6
|
-
|
|
7
|
-
engine = create_engine(
|
|
8
|
-
SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False}
|
|
9
|
-
)
|
|
10
|
-
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
|
11
|
-
|
|
12
|
-
Base = declarative_base()
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
def get_db():
|
|
16
|
-
"""Dependency to get database session."""
|
|
17
|
-
db = SessionLocal()
|
|
18
|
-
try:
|
|
19
|
-
yield db
|
|
20
|
-
finally:
|
|
21
|
-
db.close()
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
from datetime import datetime, timedelta
|
|
2
|
-
from typing import Optional
|
|
3
|
-
from jose import JWTError, jwt
|
|
4
|
-
from passlib.context import CryptContext
|
|
5
|
-
from sqlalchemy.orm import Session
|
|
6
|
-
from fastapi import Depends, HTTPException, status
|
|
7
|
-
from fastapi.security import OAuth2PasswordBearer
|
|
8
|
-
from app import models, schemas
|
|
9
|
-
from app.database import get_db
|
|
10
|
-
|
|
11
|
-
# Security configuration
|
|
12
|
-
SECRET_KEY = "your-secret-key-here-change-in-production"
|
|
13
|
-
ALGORITHM = "HS256"
|
|
14
|
-
ACCESS_TOKEN_EXPIRE_MINUTES = 30
|
|
15
|
-
|
|
16
|
-
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
|
|
17
|
-
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="api/v1/auth/token")
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
def verify_password(plain_password: str, hashed_password: str) -> bool:
|
|
21
|
-
"""Verify a password against its hash."""
|
|
22
|
-
return pwd_context.verify(plain_password, hashed_password)
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
def get_password_hash(password: str) -> str:
|
|
26
|
-
"""Hash a password."""
|
|
27
|
-
return pwd_context.hash(password)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
def get_user(db: Session, username: str) -> Optional[models.User]:
|
|
31
|
-
"""Get user by username."""
|
|
32
|
-
return db.query(models.User).filter(models.User.username == username).first()
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
def get_user_by_email(db: Session, email: str) -> Optional[models.User]:
|
|
36
|
-
"""Get user by email."""
|
|
37
|
-
return db.query(models.User).filter(models.User.email == email).first()
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
def authenticate_user(
|
|
41
|
-
db: Session, username: str, password: str
|
|
42
|
-
) -> Optional[models.User]:
|
|
43
|
-
"""Authenticate a user."""
|
|
44
|
-
user = get_user(db, username)
|
|
45
|
-
if not user:
|
|
46
|
-
return None
|
|
47
|
-
if not verify_password(password, user.hashed_password):
|
|
48
|
-
return None
|
|
49
|
-
return user
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
def create_access_token(data: dict, expires_delta: Optional[timedelta] = None) -> str:
|
|
53
|
-
"""Create JWT access token."""
|
|
54
|
-
to_encode = data.copy()
|
|
55
|
-
if expires_delta:
|
|
56
|
-
expire = datetime.utcnow() + expires_delta
|
|
57
|
-
else:
|
|
58
|
-
expire = datetime.utcnow() + timedelta(minutes=15)
|
|
59
|
-
to_encode.update({"exp": expire})
|
|
60
|
-
encoded_jwt = jwt.encode(to_encode, SECRET_KEY, algorithm=ALGORITHM)
|
|
61
|
-
return encoded_jwt
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
async def get_current_user(
|
|
65
|
-
token: str = Depends(oauth2_scheme), db: Session = Depends(get_db)
|
|
66
|
-
) -> models.User:
|
|
67
|
-
"""Get current authenticated user."""
|
|
68
|
-
credentials_exception = HTTPException(
|
|
69
|
-
status_code=status.HTTP_401_UNAUTHORIZED,
|
|
70
|
-
detail="Could not validate credentials",
|
|
71
|
-
headers={"WWW-Authenticate": "Bearer"},
|
|
72
|
-
)
|
|
73
|
-
|
|
74
|
-
try:
|
|
75
|
-
payload = jwt.decode(token, SECRET_KEY, algorithms=[ALGORITHM])
|
|
76
|
-
username: str = payload.get("sub")
|
|
77
|
-
if username is None:
|
|
78
|
-
raise credentials_exception
|
|
79
|
-
token_data = schemas.TokenData(username=username)
|
|
80
|
-
except JWTError:
|
|
81
|
-
raise credentials_exception
|
|
82
|
-
|
|
83
|
-
user = get_user(db, username=token_data.username)
|
|
84
|
-
if user is None:
|
|
85
|
-
raise credentials_exception
|
|
86
|
-
|
|
87
|
-
return user
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
async def get_current_active_user(
|
|
91
|
-
current_user: models.User = Depends(get_current_user),
|
|
92
|
-
) -> models.User:
|
|
93
|
-
"""Get current active user."""
|
|
94
|
-
if not current_user.is_active:
|
|
95
|
-
raise HTTPException(status_code=400, detail="Inactive user")
|
|
96
|
-
return current_user
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
async def get_current_superuser(
|
|
100
|
-
current_user: models.User = Depends(get_current_active_user),
|
|
101
|
-
) -> models.User:
|
|
102
|
-
"""Get current superuser."""
|
|
103
|
-
if not current_user.is_superuser:
|
|
104
|
-
raise HTTPException(
|
|
105
|
-
status_code=status.HTTP_403_FORBIDDEN, detail="Not enough permissions"
|
|
106
|
-
)
|
|
107
|
-
return current_user
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
from fastapi import FastAPI
|
|
2
|
-
from fastapi.middleware.cors import CORSMiddleware
|
|
3
|
-
from app.database import engine, Base
|
|
4
|
-
from app.routers import auth, posts
|
|
5
|
-
|
|
6
|
-
# Create database tables
|
|
7
|
-
Base.metadata.create_all(bind=engine)
|
|
8
|
-
|
|
9
|
-
# Create FastAPI app
|
|
10
|
-
app = FastAPI(
|
|
11
|
-
title="FastAPI Blog",
|
|
12
|
-
description="A modern blog API built with FastAPI",
|
|
13
|
-
version="1.0.0",
|
|
14
|
-
docs_url="/docs",
|
|
15
|
-
redoc_url="/redoc",
|
|
16
|
-
)
|
|
17
|
-
|
|
18
|
-
# Add CORS middleware
|
|
19
|
-
app.add_middleware(
|
|
20
|
-
CORSMiddleware,
|
|
21
|
-
allow_origins=["*"],
|
|
22
|
-
allow_credentials=True,
|
|
23
|
-
allow_methods=["*"],
|
|
24
|
-
allow_headers=["*"],
|
|
25
|
-
)
|
|
26
|
-
|
|
27
|
-
# Include routers
|
|
28
|
-
app.include_router(auth.router, prefix="/api/v1")
|
|
29
|
-
app.include_router(posts.router, prefix="/api/v1")
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
@app.get("/")
|
|
33
|
-
def read_root():
|
|
34
|
-
"""Root endpoint."""
|
|
35
|
-
return {"message": "Welcome to FastAPI Blog", "docs": "/docs", "version": "1.0.0"}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
@app.get("/health")
|
|
39
|
-
def health_check():
|
|
40
|
-
"""Health check endpoint."""
|
|
41
|
-
return {"status": "healthy"}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if __name__ == "__main__":
|
|
45
|
-
import uvicorn
|
|
46
|
-
|
|
47
|
-
uvicorn.run(app, host="0.0.0.0", port=8000)
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
from sqlalchemy import (
|
|
2
|
-
Column,
|
|
3
|
-
Integer,
|
|
4
|
-
String,
|
|
5
|
-
Boolean,
|
|
6
|
-
DateTime,
|
|
7
|
-
ForeignKey,
|
|
8
|
-
Text,
|
|
9
|
-
Table,
|
|
10
|
-
)
|
|
11
|
-
from sqlalchemy.orm import relationship
|
|
12
|
-
from sqlalchemy.sql import func
|
|
13
|
-
from app.database import Base
|
|
14
|
-
|
|
15
|
-
# Association table for many-to-many relationship
|
|
16
|
-
post_tags = Table(
|
|
17
|
-
"post_tags",
|
|
18
|
-
Base.metadata,
|
|
19
|
-
Column("post_id", Integer, ForeignKey("posts.id")),
|
|
20
|
-
Column("tag_id", Integer, ForeignKey("tags.id")),
|
|
21
|
-
)
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
class User(Base):
|
|
25
|
-
"""User model for authentication and posts."""
|
|
26
|
-
|
|
27
|
-
__tablename__ = "users"
|
|
28
|
-
|
|
29
|
-
id = Column(Integer, primary_key=True, index=True)
|
|
30
|
-
email = Column(String, unique=True, index=True, nullable=False)
|
|
31
|
-
username = Column(String, unique=True, index=True, nullable=False)
|
|
32
|
-
hashed_password = Column(String, nullable=False)
|
|
33
|
-
full_name = Column(String)
|
|
34
|
-
bio = Column(Text)
|
|
35
|
-
is_active = Column(Boolean, default=True)
|
|
36
|
-
is_superuser = Column(Boolean, default=False)
|
|
37
|
-
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
38
|
-
updated_at = Column(DateTime(timezone=True), onupdate=func.now())
|
|
39
|
-
|
|
40
|
-
# Relationships
|
|
41
|
-
posts = relationship("Post", back_populates="author", cascade="all, delete-orphan")
|
|
42
|
-
comments = relationship(
|
|
43
|
-
"Comment", back_populates="author", cascade="all, delete-orphan"
|
|
44
|
-
)
|
|
45
|
-
|
|
46
|
-
def __repr__(self):
|
|
47
|
-
return f"<User(username='{self.username}', email='{self.email}')>"
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
class Post(Base):
|
|
51
|
-
"""Blog post model."""
|
|
52
|
-
|
|
53
|
-
__tablename__ = "posts"
|
|
54
|
-
|
|
55
|
-
id = Column(Integer, primary_key=True, index=True)
|
|
56
|
-
title = Column(String(255), nullable=False)
|
|
57
|
-
slug = Column(String(255), unique=True, index=True, nullable=False)
|
|
58
|
-
content = Column(Text, nullable=False)
|
|
59
|
-
summary = Column(String(500))
|
|
60
|
-
is_published = Column(Boolean, default=False)
|
|
61
|
-
published_at = Column(DateTime(timezone=True))
|
|
62
|
-
view_count = Column(Integer, default=0)
|
|
63
|
-
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
64
|
-
updated_at = Column(DateTime(timezone=True), onupdate=func.now())
|
|
65
|
-
author_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
|
66
|
-
|
|
67
|
-
# Relationships
|
|
68
|
-
author = relationship("User", back_populates="posts")
|
|
69
|
-
comments = relationship(
|
|
70
|
-
"Comment", back_populates="post", cascade="all, delete-orphan"
|
|
71
|
-
)
|
|
72
|
-
tags = relationship("Tag", secondary=post_tags, back_populates="posts")
|
|
73
|
-
category_id = Column(Integer, ForeignKey("categories.id"))
|
|
74
|
-
category = relationship("Category", back_populates="posts")
|
|
75
|
-
|
|
76
|
-
def __repr__(self):
|
|
77
|
-
return f"<Post(title='{self.title}', slug='{self.slug}')>"
|
|
78
|
-
|
|
79
|
-
def publish(self):
|
|
80
|
-
"""Publish the post."""
|
|
81
|
-
from datetime import datetime
|
|
82
|
-
|
|
83
|
-
self.is_published = True
|
|
84
|
-
self.published_at = datetime.utcnow()
|
|
85
|
-
|
|
86
|
-
def unpublish(self):
|
|
87
|
-
"""Unpublish the post."""
|
|
88
|
-
self.is_published = False
|
|
89
|
-
self.published_at = None
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
class Comment(Base):
|
|
93
|
-
"""Comment model for blog posts."""
|
|
94
|
-
|
|
95
|
-
__tablename__ = "comments"
|
|
96
|
-
|
|
97
|
-
id = Column(Integer, primary_key=True, index=True)
|
|
98
|
-
content = Column(Text, nullable=False)
|
|
99
|
-
is_approved = Column(Boolean, default=False)
|
|
100
|
-
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
101
|
-
updated_at = Column(DateTime(timezone=True), onupdate=func.now())
|
|
102
|
-
|
|
103
|
-
# Foreign keys
|
|
104
|
-
post_id = Column(Integer, ForeignKey("posts.id"), nullable=False)
|
|
105
|
-
author_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
|
106
|
-
parent_id = Column(Integer, ForeignKey("comments.id"), nullable=True)
|
|
107
|
-
|
|
108
|
-
# Relationships
|
|
109
|
-
post = relationship("Post", back_populates="comments")
|
|
110
|
-
author = relationship("User", back_populates="comments")
|
|
111
|
-
replies = relationship("Comment", backref="parent", remote_side=[id])
|
|
112
|
-
|
|
113
|
-
def __repr__(self):
|
|
114
|
-
return f"<Comment(id={self.id}, post_id={self.post_id})>"
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
class Category(Base):
|
|
118
|
-
"""Category model for organizing posts."""
|
|
119
|
-
|
|
120
|
-
__tablename__ = "categories"
|
|
121
|
-
|
|
122
|
-
id = Column(Integer, primary_key=True, index=True)
|
|
123
|
-
name = Column(String(100), unique=True, nullable=False)
|
|
124
|
-
slug = Column(String(100), unique=True, index=True, nullable=False)
|
|
125
|
-
description = Column(Text)
|
|
126
|
-
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
127
|
-
|
|
128
|
-
# Relationships
|
|
129
|
-
posts = relationship("Post", back_populates="category")
|
|
130
|
-
|
|
131
|
-
def __repr__(self):
|
|
132
|
-
return f"<Category(name='{self.name}')>"
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
class Tag(Base):
|
|
136
|
-
"""Tag model for posts."""
|
|
137
|
-
|
|
138
|
-
__tablename__ = "tags"
|
|
139
|
-
|
|
140
|
-
id = Column(Integer, primary_key=True, index=True)
|
|
141
|
-
name = Column(String(50), unique=True, nullable=False)
|
|
142
|
-
slug = Column(String(50), unique=True, index=True, nullable=False)
|
|
143
|
-
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
144
|
-
|
|
145
|
-
# Relationships
|
|
146
|
-
posts = relationship("Post", secondary=post_tags, back_populates="tags")
|
|
147
|
-
|
|
148
|
-
def __repr__(self):
|
|
149
|
-
return f"<Tag(name='{self.name}')>"
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
from datetime import timedelta
|
|
2
|
-
from typing import List
|
|
3
|
-
from fastapi import APIRouter, Depends, HTTPException, status
|
|
4
|
-
from sqlalchemy.orm import Session
|
|
5
|
-
from app import models, schemas
|
|
6
|
-
from app.database import get_db
|
|
7
|
-
from app.dependencies import (
|
|
8
|
-
authenticate_user,
|
|
9
|
-
create_access_token,
|
|
10
|
-
get_current_active_user,
|
|
11
|
-
get_password_hash,
|
|
12
|
-
ACCESS_TOKEN_EXPIRE_MINUTES,
|
|
13
|
-
get_user,
|
|
14
|
-
get_user_by_email,
|
|
15
|
-
)
|
|
16
|
-
|
|
17
|
-
router = APIRouter(prefix="/auth", tags=["authentication"])
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
@router.post(
|
|
21
|
-
"/register", response_model=schemas.User, status_code=status.HTTP_201_CREATED
|
|
22
|
-
)
|
|
23
|
-
def register(user: schemas.UserCreate, db: Session = Depends(get_db)):
|
|
24
|
-
"""Register a new user."""
|
|
25
|
-
# Check if username exists
|
|
26
|
-
db_user = get_user(db, username=user.username)
|
|
27
|
-
if db_user:
|
|
28
|
-
raise HTTPException(
|
|
29
|
-
status_code=status.HTTP_400_BAD_REQUEST,
|
|
30
|
-
detail="Username already registered",
|
|
31
|
-
)
|
|
32
|
-
|
|
33
|
-
# Check if email exists
|
|
34
|
-
db_user = get_user_by_email(db, email=user.email)
|
|
35
|
-
if db_user:
|
|
36
|
-
raise HTTPException(
|
|
37
|
-
status_code=status.HTTP_400_BAD_REQUEST, detail="Email already registered"
|
|
38
|
-
)
|
|
39
|
-
|
|
40
|
-
# Create new user
|
|
41
|
-
hashed_password = get_password_hash(user.password)
|
|
42
|
-
db_user = models.User(
|
|
43
|
-
email=user.email,
|
|
44
|
-
username=user.username,
|
|
45
|
-
hashed_password=hashed_password,
|
|
46
|
-
full_name=user.full_name,
|
|
47
|
-
bio=user.bio,
|
|
48
|
-
)
|
|
49
|
-
db.add(db_user)
|
|
50
|
-
db.commit()
|
|
51
|
-
db.refresh(db_user)
|
|
52
|
-
|
|
53
|
-
return db_user
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
@router.post("/token", response_model=schemas.Token)
|
|
57
|
-
def login(form_data: schemas.LoginRequest, db: Session = Depends(get_db)):
|
|
58
|
-
"""Login and get access token."""
|
|
59
|
-
user = authenticate_user(db, form_data.username, form_data.password)
|
|
60
|
-
if not user:
|
|
61
|
-
raise HTTPException(
|
|
62
|
-
status_code=status.HTTP_401_UNAUTHORIZED,
|
|
63
|
-
detail="Incorrect username or password",
|
|
64
|
-
headers={"WWW-Authenticate": "Bearer"},
|
|
65
|
-
)
|
|
66
|
-
|
|
67
|
-
access_token_expires = timedelta(minutes=ACCESS_TOKEN_EXPIRE_MINUTES)
|
|
68
|
-
access_token = create_access_token(
|
|
69
|
-
data={"sub": user.username}, expires_delta=access_token_expires
|
|
70
|
-
)
|
|
71
|
-
|
|
72
|
-
return {"access_token": access_token, "token_type": "bearer"}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
@router.get("/me", response_model=schemas.User)
|
|
76
|
-
def read_users_me(current_user: models.User = Depends(get_current_active_user)):
|
|
77
|
-
"""Get current user information."""
|
|
78
|
-
return current_user
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
@router.put("/me", response_model=schemas.User)
|
|
82
|
-
def update_user_me(
|
|
83
|
-
user_update: schemas.UserUpdate,
|
|
84
|
-
current_user: models.User = Depends(get_current_active_user),
|
|
85
|
-
db: Session = Depends(get_db),
|
|
86
|
-
):
|
|
87
|
-
"""Update current user."""
|
|
88
|
-
update_data = user_update.model_dump(exclude_unset=True)
|
|
89
|
-
|
|
90
|
-
for field, value in update_data.items():
|
|
91
|
-
setattr(current_user, field, value)
|
|
92
|
-
|
|
93
|
-
db.commit()
|
|
94
|
-
db.refresh(current_user)
|
|
95
|
-
|
|
96
|
-
return current_user
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
@router.post("/change-password")
|
|
100
|
-
def change_password(
|
|
101
|
-
old_password: str,
|
|
102
|
-
new_password: str,
|
|
103
|
-
current_user: models.User = Depends(get_current_active_user),
|
|
104
|
-
db: Session = Depends(get_db),
|
|
105
|
-
):
|
|
106
|
-
"""Change user password."""
|
|
107
|
-
from app.dependencies import verify_password, get_password_hash
|
|
108
|
-
|
|
109
|
-
if not verify_password(old_password, current_user.hashed_password):
|
|
110
|
-
raise HTTPException(
|
|
111
|
-
status_code=status.HTTP_400_BAD_REQUEST, detail="Incorrect password"
|
|
112
|
-
)
|
|
113
|
-
|
|
114
|
-
current_user.hashed_password = get_password_hash(new_password)
|
|
115
|
-
db.commit()
|
|
116
|
-
|
|
117
|
-
return {"message": "Password updated successfully"}
|