@smicolon/ai-kit 0.3.2 → 0.4.0

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.
Files changed (155) hide show
  1. package/README.md +73 -40
  2. package/dist/index.js +260 -126
  3. package/package.json +5 -5
  4. package/.claude-plugin/marketplace.json +0 -369
  5. package/packs/architect/CHANGELOG.md +0 -17
  6. package/packs/architect/README.md +0 -58
  7. package/packs/architect/agents/system-architect.md +0 -768
  8. package/packs/architect/commands/diagram-create.md +0 -300
  9. package/packs/better-auth/.mcp.json +0 -14
  10. package/packs/better-auth/CHANGELOG.md +0 -26
  11. package/packs/better-auth/README.md +0 -125
  12. package/packs/better-auth/agents/auth-architect.md +0 -278
  13. package/packs/better-auth/commands/auth-provider-add.md +0 -265
  14. package/packs/better-auth/commands/auth-setup.md +0 -298
  15. package/packs/better-auth/skills/auth-security/SKILL.md +0 -425
  16. package/packs/better-auth/skills/better-auth-patterns/SKILL.md +0 -455
  17. package/packs/dev-loop/CHANGELOG.md +0 -69
  18. package/packs/dev-loop/README.md +0 -155
  19. package/packs/dev-loop/commands/cancel-dev.md +0 -21
  20. package/packs/dev-loop/commands/dev-loop.md +0 -72
  21. package/packs/dev-loop/commands/dev-plan.md +0 -351
  22. package/packs/dev-loop/hooks/hooks.json +0 -15
  23. package/packs/dev-loop/hooks/stop-hook.sh +0 -178
  24. package/packs/dev-loop/scripts/setup-dev-loop.sh +0 -194
  25. package/packs/dev-loop/skills/tdd-planner/SKILL.md +0 -249
  26. package/packs/dev-loop/skills/tdd-planner/references/framework-patterns.md +0 -874
  27. package/packs/dev-loop/skills/tdd-planner/references/good-example.md +0 -260
  28. package/packs/dev-loop/skills/tdd-planner/references/plan-template.md +0 -275
  29. package/packs/django/CHANGELOG.md +0 -39
  30. package/packs/django/README.md +0 -92
  31. package/packs/django/agents/django-architect.md +0 -182
  32. package/packs/django/agents/django-builder.md +0 -250
  33. package/packs/django/agents/django-feature-based.md +0 -420
  34. package/packs/django/agents/django-reviewer.md +0 -253
  35. package/packs/django/agents/django-tester.md +0 -230
  36. package/packs/django/commands/api-endpoint.md +0 -285
  37. package/packs/django/commands/model-create.md +0 -178
  38. package/packs/django/commands/test-generate.md +0 -325
  39. package/packs/django/rules/migrations.md +0 -138
  40. package/packs/django/rules/models.md +0 -167
  41. package/packs/django/rules/serializers.md +0 -126
  42. package/packs/django/rules/services.md +0 -131
  43. package/packs/django/rules/tests.md +0 -140
  44. package/packs/django/rules/views.md +0 -102
  45. package/packs/django/skills/import-convention-enforcer/SKILL.md +0 -226
  46. package/packs/django/skills/import-convention-enforcer/patterns/django-imports.md +0 -343
  47. package/packs/django/skills/migration-safety-checker/SKILL.md +0 -375
  48. package/packs/django/skills/model-entity-validator/SKILL.md +0 -298
  49. package/packs/django/skills/performance-optimizer/SKILL.md +0 -447
  50. package/packs/django/skills/red-phase-verifier/SKILL.md +0 -180
  51. package/packs/django/skills/security-first-validator/SKILL.md +0 -435
  52. package/packs/django/skills/test-coverage-advisor/SKILL.md +0 -394
  53. package/packs/django/skills/test-validity-checker/SKILL.md +0 -194
  54. package/packs/failure-log/CHANGELOG.md +0 -20
  55. package/packs/failure-log/README.md +0 -168
  56. package/packs/failure-log/commands/failure-add.md +0 -106
  57. package/packs/failure-log/commands/failure-list.md +0 -89
  58. package/packs/failure-log/hooks/hooks.json +0 -16
  59. package/packs/failure-log/hooks/scripts/inject-failures.sh +0 -64
  60. package/packs/failure-log/skills/failure-log-manager/SKILL.md +0 -164
  61. package/packs/flutter/CHANGELOG.md +0 -19
  62. package/packs/flutter/README.md +0 -170
  63. package/packs/flutter/agents/flutter-architect.md +0 -166
  64. package/packs/flutter/agents/flutter-builder.md +0 -303
  65. package/packs/flutter/agents/release-manager.md +0 -355
  66. package/packs/flutter/commands/fastlane-setup.md +0 -188
  67. package/packs/flutter/commands/flutter-build.md +0 -90
  68. package/packs/flutter/commands/flutter-deploy.md +0 -133
  69. package/packs/flutter/commands/flutter-test.md +0 -117
  70. package/packs/flutter/commands/signing-setup.md +0 -209
  71. package/packs/flutter/hooks/hooks.json +0 -17
  72. package/packs/flutter/skills/fastlane-knowledge/SKILL.md +0 -193
  73. package/packs/flutter/skills/flutter-architecture/SKILL.md +0 -127
  74. package/packs/flutter/skills/store-publishing/SKILL.md +0 -163
  75. package/packs/hono/CHANGELOG.md +0 -19
  76. package/packs/hono/README.md +0 -143
  77. package/packs/hono/agents/hono-architect.md +0 -240
  78. package/packs/hono/agents/hono-builder.md +0 -285
  79. package/packs/hono/agents/hono-reviewer.md +0 -279
  80. package/packs/hono/agents/hono-tester.md +0 -346
  81. package/packs/hono/commands/middleware-create.md +0 -223
  82. package/packs/hono/commands/project-init.md +0 -306
  83. package/packs/hono/commands/route-create.md +0 -153
  84. package/packs/hono/commands/rpc-client.md +0 -263
  85. package/packs/hono/skills/cloudflare-bindings/SKILL.md +0 -408
  86. package/packs/hono/skills/hono-patterns/SKILL.md +0 -309
  87. package/packs/hono/skills/rpc-typesafe/SKILL.md +0 -388
  88. package/packs/hono/skills/zod-validation/SKILL.md +0 -332
  89. package/packs/nestjs/CHANGELOG.md +0 -29
  90. package/packs/nestjs/README.md +0 -75
  91. package/packs/nestjs/agents/nestjs-architect.md +0 -402
  92. package/packs/nestjs/agents/nestjs-builder.md +0 -301
  93. package/packs/nestjs/agents/nestjs-tester.md +0 -437
  94. package/packs/nestjs/commands/module-create.md +0 -369
  95. package/packs/nestjs/rules/controllers.md +0 -92
  96. package/packs/nestjs/rules/dto.md +0 -124
  97. package/packs/nestjs/rules/entities.md +0 -102
  98. package/packs/nestjs/rules/services.md +0 -106
  99. package/packs/nestjs/skills/barrel-export-manager/SKILL.md +0 -389
  100. package/packs/nestjs/skills/import-convention-enforcer/SKILL.md +0 -365
  101. package/packs/nextjs/CHANGELOG.md +0 -36
  102. package/packs/nextjs/README.md +0 -76
  103. package/packs/nextjs/agents/frontend-tester.md +0 -680
  104. package/packs/nextjs/agents/frontend-visual.md +0 -820
  105. package/packs/nextjs/agents/nextjs-architect.md +0 -331
  106. package/packs/nextjs/agents/nextjs-modular.md +0 -433
  107. package/packs/nextjs/commands/component-create.md +0 -398
  108. package/packs/nextjs/rules/api-routes.md +0 -129
  109. package/packs/nextjs/rules/components.md +0 -106
  110. package/packs/nextjs/rules/hooks.md +0 -132
  111. package/packs/nextjs/skills/accessibility-validator/SKILL.md +0 -445
  112. package/packs/nextjs/skills/import-convention-enforcer/SKILL.md +0 -399
  113. package/packs/nextjs/skills/react-form-validator/SKILL.md +0 -569
  114. package/packs/nuxtjs/CHANGELOG.md +0 -30
  115. package/packs/nuxtjs/README.md +0 -56
  116. package/packs/nuxtjs/agents/frontend-tester.md +0 -680
  117. package/packs/nuxtjs/agents/frontend-visual.md +0 -820
  118. package/packs/nuxtjs/agents/nuxtjs-architect.md +0 -537
  119. package/packs/nuxtjs/commands/component-create.md +0 -223
  120. package/packs/nuxtjs/rules/components.md +0 -101
  121. package/packs/nuxtjs/rules/composables.md +0 -118
  122. package/packs/nuxtjs/rules/server-routes.md +0 -127
  123. package/packs/nuxtjs/skills/accessibility-validator/SKILL.md +0 -183
  124. package/packs/nuxtjs/skills/import-convention-enforcer/SKILL.md +0 -196
  125. package/packs/nuxtjs/skills/veevalidate-form-validator/SKILL.md +0 -190
  126. package/packs/onboard/CHANGELOG.md +0 -22
  127. package/packs/onboard/README.md +0 -103
  128. package/packs/onboard/agents/onboard-guide.md +0 -118
  129. package/packs/onboard/commands/onboard.md +0 -313
  130. package/packs/onboard/skills/onboard-context-provider/SKILL.md +0 -98
  131. package/packs/tanstack-router/CHANGELOG.md +0 -30
  132. package/packs/tanstack-router/README.md +0 -113
  133. package/packs/tanstack-router/agents/tanstack-architect.md +0 -173
  134. package/packs/tanstack-router/agents/tanstack-builder.md +0 -360
  135. package/packs/tanstack-router/agents/tanstack-tester.md +0 -454
  136. package/packs/tanstack-router/commands/form-create.md +0 -313
  137. package/packs/tanstack-router/commands/query-create.md +0 -263
  138. package/packs/tanstack-router/commands/route-create.md +0 -190
  139. package/packs/tanstack-router/commands/table-create.md +0 -413
  140. package/packs/tanstack-router/skills/ai-patterns/SKILL.md +0 -370
  141. package/packs/tanstack-router/skills/db-patterns/SKILL.md +0 -346
  142. package/packs/tanstack-router/skills/devtools-patterns/SKILL.md +0 -415
  143. package/packs/tanstack-router/skills/form-patterns/SKILL.md +0 -425
  144. package/packs/tanstack-router/skills/pacer-patterns/SKILL.md +0 -341
  145. package/packs/tanstack-router/skills/query-patterns/SKILL.md +0 -359
  146. package/packs/tanstack-router/skills/router-patterns/SKILL.md +0 -285
  147. package/packs/tanstack-router/skills/store-patterns/SKILL.md +0 -351
  148. package/packs/tanstack-router/skills/table-patterns/SKILL.md +0 -531
  149. package/packs/tanstack-router/skills/tanstack-conventions/SKILL.md +0 -428
  150. package/packs/tanstack-router/skills/virtual-patterns/SKILL.md +0 -490
  151. package/packs/worktree/CHANGELOG.md +0 -45
  152. package/packs/worktree/README.md +0 -219
  153. package/packs/worktree/commands/wt.md +0 -93
  154. package/packs/worktree/scripts/wt.sh +0 -957
  155. package/packs/worktree/skills/worktree-manager/SKILL.md +0 -113
@@ -1,226 +0,0 @@
1
- ---
2
- name: django-import-enforcer
3
- description: Automatically validate and fix Django import patterns to use absolute modular imports with aliases. Use when writing imports, creating new Python files, modifying existing files, or seeing import statements in code.
4
- ---
5
-
6
- # Import Convention Enforcer
7
-
8
- Enforces Smicolon's absolute modular import pattern for Django projects.
9
-
10
- ## Activation Triggers
11
-
12
- This skill activates when:
13
- - Writing or modifying Python files
14
- - Creating models, services, views, or serializers
15
- - Mentioning "import", "add", "create", or "refactor"
16
- - Reviewing or fixing code
17
-
18
- ## Django Import Pattern (MANDATORY)
19
-
20
- ### ✅ CORRECT Pattern
21
- ```python
22
- # Absolute modular imports with app-prefixed aliases
23
- import users.models as _users_models
24
- import users.services as _users_services
25
- import users.serializers as _users_serializers
26
- import core.utils as _core_utils
27
-
28
- # Usage - clear which app each import is from
29
- user = _users_models.User.objects.get(id=user_id)
30
- result = _users_services.UserService.create_user(data)
31
- serializer = _users_serializers.UserSerializer(user)
32
- token = _core_utils.generate_token()
33
- ```
34
-
35
- ### Pattern Rule
36
- ```
37
- import {app}.{module} as _{app}_{module}
38
- ```
39
-
40
- ### ❌ WRONG Patterns
41
- ```python
42
- # Relative imports - NEVER USE
43
- from .models import User
44
- from ..services import UserService
45
-
46
- # Direct class imports - NEVER USE
47
- from users.models import User
48
- from users.services import UserService
49
-
50
- # Relative module imports - NEVER USE
51
- import .models as models
52
- from . import models
53
- ```
54
-
55
- ## Validation Process
56
-
57
- ### Step 1: Detect Import Violations
58
-
59
- Scan Python code for:
60
-
61
- **Violation Type 1: Relative imports**
62
- ```python
63
- from .models import User # ❌
64
- from ..services import UserService # ❌
65
- ```
66
-
67
- **Violation Type 2: Direct class imports**
68
- ```python
69
- from users.models import User # ❌
70
- ```
71
-
72
- **Violation Type 3: Missing alias**
73
- ```python
74
- import users.models # ❌ (no alias)
75
- ```
76
-
77
- ### Step 2: Auto-Fix Violations
78
-
79
- **Before (Violation):**
80
- ```python
81
- from .models import User, Profile
82
- from users.services import UserService
83
- ```
84
-
85
- **After (Corrected):**
86
- ```python
87
- import users.models as _users_models
88
- import users.services as _users_services
89
-
90
- # Update usage
91
- user = _users_models.User.objects.get(...)
92
- profile = _users_models.Profile.objects.get(...)
93
- result = _users_services.UserService.create_user(...)
94
- ```
95
-
96
- ### Step 3: Explain the Fix
97
-
98
- Report to developer:
99
- > **Import Pattern Violation Fixed**
100
- >
101
- > Changed relative/direct imports to absolute modular imports with app-prefixed aliases:
102
- > - `from .models import User` → `import users.models as _users_models`
103
- > - Usage: `user = _users_models.User.objects.get(...)`
104
- >
105
- > **Why**: Absolute imports with aliases:
106
- > - ✅ Clear module boundaries
107
- > - ✅ Easier to refactor
108
- > - ✅ No circular dependency issues
109
- > - ✅ Consistent across entire codebase
110
-
111
- ### Step 4: Verify All Imports
112
-
113
- Check the entire file to ensure ALL imports follow the pattern:
114
-
115
- ```python
116
- import uuid
117
- import users.models as _users_models # ✅
118
- import users.services as _users_services # ✅
119
- import features.auth.models as _auth_models # ✅
120
- from rest_framework import serializers # ✅ Third-party is fine
121
- from django.db import models # ✅ Django imports are fine
122
- ```
123
-
124
- ## Common Scenarios
125
-
126
- ### Creating New Model File
127
-
128
- **User writes:**
129
- ```python
130
- # users/models.py
131
- from django.db import models
132
- from .base import BaseModel # ❌ WRONG
133
- ```
134
-
135
- **Auto-fix to:**
136
- ```python
137
- # users/models.py
138
- from django.db import models
139
- import users.models.base as _users_base # ✅ CORRECT
140
-
141
- class User(_users_base.BaseModel):
142
- pass
143
- ```
144
-
145
- ### Creating New Service
146
-
147
- **User writes:**
148
- ```python
149
- # users/services.py
150
- from .models import User # ❌ WRONG
151
- from .serializers import UserSerializer # ❌ WRONG
152
- ```
153
-
154
- **Auto-fix to:**
155
- ```python
156
- # users/services.py
157
- import users.models as _users_models # ✅ CORRECT
158
- import users.serializers as _users_serializers # ✅ CORRECT
159
-
160
- class UserService:
161
- def create_user(self, data):
162
- user = _users_models.User.objects.create(**data)
163
- serializer = _users_serializers.UserSerializer(user)
164
- return serializer.data
165
- ```
166
-
167
- ### Cross-App Imports
168
-
169
- **User writes:**
170
- ```python
171
- # orders/services.py
172
- from users.models import User # ❌ WRONG
173
- from products.models import Product # ❌ WRONG
174
- ```
175
-
176
- **Auto-fix to:**
177
- ```python
178
- # orders/services.py
179
- import users.models as _user_models # ✅ CORRECT
180
- import products.models as _product_models # ✅ CORRECT
181
-
182
- class OrderService:
183
- def create_order(self, user_id, product_id):
184
- user = _user_models.User.objects.get(id=user_id)
185
- product = _product_models.Product.objects.get(id=product_id)
186
- ```
187
-
188
- ## Barrel Exports (Optional)
189
-
190
- For cleaner imports, suggest barrel exports in `__init__.py`:
191
-
192
- ```python
193
- # users/models/__init__.py
194
- from users.models.user import User
195
- from users.models.profile import Profile
196
-
197
- __all__ = ['User', 'Profile']
198
- ```
199
-
200
- Then allow:
201
- ```python
202
- import users.models as _users_models
203
-
204
- user = _users_models.User.objects.get(...) # Clean!
205
- ```
206
-
207
- ## Success Criteria
208
-
209
- ✅ All Python files use absolute modular imports with aliases
210
- ✅ Zero relative imports in codebase
211
- ✅ Zero direct class imports from same project
212
- ✅ Consistent `_alias` naming pattern
213
- ✅ Developers understand WHY (explained every time)
214
-
215
- ## Behavior
216
-
217
- **Proactive enforcement:**
218
- - Check imports without being asked
219
- - Fix violations immediately
220
- - Explain why the pattern is required
221
- - Update all related usage in the file
222
-
223
- **Never:**
224
- - Require explicit "check imports" request
225
- - Wait for code review
226
- - Just warn without fixing
@@ -1,343 +0,0 @@
1
- # Django Import Patterns Reference
2
-
3
- Complete guide to Smicolon's Django import patterns.
4
-
5
- ## Core Pattern: Absolute Modular Imports with Aliases
6
-
7
- ### Standard Form
8
-
9
- ```python
10
- import {app}.{module} as _{app}_{module}
11
- ```
12
-
13
- ### Examples
14
-
15
- ```python
16
- import users.models as _users_models
17
- import users.services as _users_services
18
- import users.serializers as _users_serializers
19
- import users.views as _users_views
20
- import users.utils as _users_utils
21
- ```
22
-
23
- ## Usage After Import
24
-
25
- ```python
26
- import users.models as _users_models
27
-
28
- # Access classes through the alias
29
- user = _users_models.User.objects.get(id=user_id)
30
- profile = _users_models.Profile.objects.create(user=user)
31
- ```
32
-
33
- ## Cross-App Imports
34
-
35
- When importing from different apps, each alias is unique:
36
-
37
- ```python
38
- # orders/services.py
39
- import users.models as _users_models
40
- import products.models as _products_models
41
- import orders.models as _orders_models
42
-
43
- class OrderService:
44
- def create_order(self, user_id, product_id):
45
- user = _users_models.User.objects.get(id=user_id)
46
- product = _products_models.Product.objects.get(id=product_id)
47
- order = _orders_models.Order.objects.create(user=user, product=product)
48
- return order
49
- ```
50
-
51
- ## Nested Module Imports
52
-
53
- For sub-modules, include the full path:
54
-
55
- ```python
56
- # ✅ CORRECT
57
- import users.models.user as _user_models
58
- import users.models.profile as _profile_models
59
- import users.services.auth as _auth_services
60
-
61
- # Usage
62
- user = _user_models.User.objects.get(...)
63
- profile = _profile_models.Profile.objects.get(...)
64
- token = _auth_services.AuthService.generate_token(...)
65
- ```
66
-
67
- ## Third-Party and Django Imports
68
-
69
- Standard imports for framework and libraries:
70
-
71
- ```python
72
- # Django imports - use standard form
73
- from django.db import models
74
- from django.contrib.auth import get_user_model
75
- from rest_framework import serializers, viewsets
76
- from rest_framework.permissions import IsAuthenticated
77
-
78
- # Third-party - use standard form
79
- import uuid
80
- from typing import List, Optional
81
- import pandas as pd
82
-
83
- # Project imports - use modular pattern with app prefix
84
- import users.models as _users_models
85
- import users.services as _users_services
86
- ```
87
-
88
- ## Complete File Example
89
-
90
- ```python
91
- # users/views.py
92
- import uuid
93
- from typing import Optional
94
-
95
- from django.db import transaction
96
- from rest_framework import viewsets, status
97
- from rest_framework.decorators import action
98
- from rest_framework.permissions import IsAuthenticated
99
- from rest_framework.response import Response
100
-
101
- import users.models as _users_models
102
- import users.serializers as _users_serializers
103
- import users.services as _users_services
104
- import core.permissions as _core_permissions
105
-
106
-
107
- class UserViewSet(viewsets.ModelViewSet):
108
- """User management endpoints."""
109
-
110
- queryset = _users_models.User.objects.all()
111
- serializer_class = _users_serializers.UserSerializer
112
- permission_classes = [IsAuthenticated, _core_permissions.IsOwnerOrAdmin]
113
-
114
- def create(self, request):
115
- """Create new user."""
116
- user = _users_services.UserService.create_user(request.data)
117
- serializer = self.get_serializer(user)
118
- return Response(serializer.data, status=status.HTTP_201_CREATED)
119
-
120
- @action(detail=True, methods=['post'])
121
- def activate(self, request, pk=None):
122
- """Activate user account."""
123
- user = self.get_object()
124
- _users_services.UserService.activate_user(user)
125
- return Response({'status': 'activated'})
126
- ```
127
-
128
- ## Import Order
129
-
130
- Follow this order for clean organization:
131
-
132
- ```python
133
- # 1. Standard library
134
- import uuid
135
- import json
136
- from typing import List, Optional
137
-
138
- # 2. Django imports
139
- from django.db import models, transaction
140
- from django.contrib.auth import get_user_model
141
-
142
- # 3. Third-party
143
- from rest_framework import serializers
144
- import pandas as pd
145
-
146
- # 4. Project imports (app-prefixed pattern)
147
- import users.models as _users_models
148
- import users.services as _users_services
149
- import core.utils as _core_utils
150
- ```
151
-
152
- ## Common Mistakes and Fixes
153
-
154
- ### Mistake 1: Relative Imports
155
-
156
- ```python
157
- # ❌ WRONG
158
- from .models import User
159
- from ..services import UserService
160
- from . import models
161
-
162
- # ✅ CORRECT
163
- import users.models as _users_models
164
- import users.services as _users_services
165
- ```
166
-
167
- ### Mistake 2: Direct Class Imports
168
-
169
- ```python
170
- # ❌ WRONG
171
- from users.models import User, Profile
172
- from users.services import UserService
173
-
174
- # ✅ CORRECT
175
- import users.models as _users_models
176
- import users.services as _users_services
177
-
178
- # Usage
179
- user = _users_models.User.objects.get(...)
180
- _users_services.UserService.create_user(...)
181
- ```
182
-
183
- ### Mistake 3: No Alias
184
-
185
- ```python
186
- # ❌ WRONG
187
- import users.models
188
- import users.services
189
-
190
- # ✅ CORRECT
191
- import users.models as _users_models
192
- import users.services as _users_services
193
- ```
194
-
195
- ### Mistake 4: Inconsistent Aliases
196
-
197
- ```python
198
- # ❌ WRONG (inconsistent naming)
199
- import users.models as user_models
200
- import products.models as prod_models
201
- import orders.models as m
202
-
203
- # ✅ CORRECT (consistent pattern)
204
- import users.models as _user_models
205
- import products.models as _product_models
206
- import orders.models as _order_models
207
- ```
208
-
209
- ## Alias Naming Conventions
210
-
211
- ### Pattern Rule
212
-
213
- Always use app-prefixed aliases for clarity:
214
-
215
- ```python
216
- import {app}.{module} as _{app}_{module}
217
- ```
218
-
219
- ### Examples
220
-
221
- ```python
222
- # In users/services.py
223
- import users.models as _users_models
224
- import users.serializers as _users_serializers
225
- ```
226
-
227
- ```python
228
- # In orders/services.py - clear which app each import is from
229
- import users.models as _users_models
230
- import products.models as _products_models
231
- import orders.models as _orders_models
232
- ```
233
-
234
- ### Common Module Types
235
-
236
- ```python
237
- import {app}.models as _{app}_models
238
- import {app}.services as _{app}_services
239
- import {app}.serializers as _{app}_serializers
240
- import {app}.views as _{app}_views
241
- import {app}.utils as _{app}_utils
242
- import {app}.permissions as _{app}_permissions
243
- import {app}.forms as _{app}_forms
244
- ```
245
-
246
- ## Feature-Based Architecture
247
-
248
- For large projects using feature-based structure:
249
-
250
- ```python
251
- # features/authentication/services.py
252
- import features.authentication.models as _auth_models
253
- import features.authentication.serializers as _auth_serializers
254
- import features.users.models as _users_models
255
- import shared.utils as _shared_utils
256
-
257
- class AuthService:
258
- def login(self, credentials):
259
- user = _users_models.User.objects.get(...)
260
- token = _auth_models.AuthToken.objects.create(user=user)
261
- return _auth_serializers.TokenSerializer(token).data
262
- ```
263
-
264
- ## Why This Pattern?
265
-
266
- ### Benefits
267
-
268
- 1. **Clear Module Boundaries**
269
- - Immediately see which module/app classes come from
270
- - `_models.User` vs `_user_models.User` vs `_product_models.User`
271
-
272
- 2. **Refactoring Safety**
273
- - Change class names without updating imports everywhere
274
- - Move classes between files easily
275
- - Barrel exports simplify refactoring
276
-
277
- 3. **No Circular Dependencies**
278
- - Absolute imports avoid circular dependency issues
279
- - Clear dependency graph
280
-
281
- 4. **Scales to Large Projects**
282
- - Works perfectly with 100+ apps
283
- - Consistent across entire codebase
284
- - New developers learn pattern once
285
-
286
- 5. **IDE Support**
287
- - Better autocomplete
288
- - Click-through to module works
289
- - Refactoring tools work better
290
-
291
- ### Comparison
292
-
293
- ```python
294
- # Relative imports - unclear origin
295
- from .models import User # Where is this file?
296
- from ..services import UserService # How many levels up?
297
-
298
- # Direct imports - verbose and breaks encapsulation
299
- from users.models.user import User
300
- from users.models.profile import Profile
301
- from users.models.organization import Organization
302
- # ... 20 more imports
303
-
304
- # Modular with app-prefixed aliases - perfect balance
305
- import users.models as _users_models
306
- import orders.models as _orders_models
307
- # Clear! No namespace conflicts, easy to identify source
308
- ```
309
-
310
- ## Edge Cases
311
-
312
- ### Circular Import Prevention
313
-
314
- ```python
315
- # users/models.py
316
- import users.services as _users_services # ❌ May cause circular import
317
-
318
- # Solution: Import inside method
319
- class User(models.Model):
320
- def some_method(self):
321
- import users.services as _users_services # ✅ Deferred import
322
- return _users_services.UserService.do_something()
323
- ```
324
-
325
- ### Type Hints
326
-
327
- ```python
328
- from __future__ import annotations # Enable forward references
329
- import users.models as _users_models
330
-
331
- def process_user(user: _users_models.User) -> None:
332
- """Process user."""
333
- pass
334
- ```
335
-
336
- ## Enforcement
337
-
338
- This pattern is enforced by:
339
- 1. **user-prompt-submit-hook.sh** - Reminds conventions before every prompt
340
- 2. **import-convention-enforcer skill** - Auto-fixes violations when code is written
341
- 3. **django-reviewer agent** - Checks compliance during code review
342
-
343
- All three work together to ensure 100% compliance.