ntc-dev-kit 1.0.0__py3-none-any.whl
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.
- ntc/__init__.py +5 -0
- ntc/app_creator.py +296 -0
- ntc/cli.py +4 -0
- ntc/cli_enhanced.py +820 -0
- ntc/composer/__init__.py +0 -0
- ntc/composer/main.py +443 -0
- ntc/deployment/__init__.py +0 -0
- ntc/templates/__init__.py +2 -0
- ntc/templates/auth_app/__init__.py +0 -0
- ntc/templates/auth_app/admin.py +24 -0
- ntc/templates/auth_app/apps.py +6 -0
- ntc/templates/auth_app/models.py +30 -0
- ntc/templates/auth_app/serializers.py +101 -0
- ntc/templates/auth_app/urls.py +19 -0
- ntc/templates/auth_app/views.py +175 -0
- ntc/templates/drf_structure/__init__.py +1 -0
- ntc/templates/drf_structure/drf_structure.md +83 -0
- ntc/templates/drf_structure/main.py +389 -0
- ntc/templates/drf_structure/structure.json +126 -0
- ntc/templates/drf_structure/templates/.entry/start_core_backend.sh +37 -0
- ntc/templates/drf_structure/templates/.entry/start_tasks_backend.sh +30 -0
- ntc/templates/drf_structure/templates/CLAUDE.md +194 -0
- ntc/templates/drf_structure/templates/README.md +117 -0
- ntc/templates/drf_structure/templates/apps/app_admin.py +3 -0
- ntc/templates/drf_structure/templates/apps/app_apps.py +6 -0
- ntc/templates/drf_structure/templates/apps/app_models.py +4 -0
- ntc/templates/drf_structure/templates/apps/app_urls.py +8 -0
- ntc/templates/drf_structure/templates/apps/app_views.py +6 -0
- ntc/templates/drf_structure/templates/apps/common_apps.py +6 -0
- ntc/templates/drf_structure/templates/apps/common_models.py +8 -0
- ntc/templates/drf_structure/templates/config/gunicorn_config.py +9 -0
- ntc/templates/drf_structure/templates/config/http.conf +33 -0
- ntc/templates/drf_structure/templates/core/base_model.py +9 -0
- ntc/templates/drf_structure/templates/core/formatter.py +5 -0
- ntc/templates/drf_structure/templates/core/logger.py +8 -0
- ntc/templates/drf_structure/templates/core/pagination.py +6 -0
- ntc/templates/drf_structure/templates/core/response_wrapper.py +7 -0
- ntc/templates/drf_structure/templates/core/services/azure/email/backend.py +108 -0
- ntc/templates/drf_structure/templates/core/services/azure/email/client.py +296 -0
- ntc/templates/drf_structure/templates/core/services/azure/email/notifier.py +102 -0
- ntc/templates/drf_structure/templates/core/services/object_storage.py +285 -0
- ntc/templates/drf_structure/templates/django_project/asgi.py +5 -0
- ntc/templates/drf_structure/templates/django_project/celery.py +8 -0
- ntc/templates/drf_structure/templates/django_project/dev_settings.py +2 -0
- ntc/templates/drf_structure/templates/django_project/django_settings.txt +322 -0
- ntc/templates/drf_structure/templates/django_project/management_command.py +114 -0
- ntc/templates/drf_structure/templates/django_project/prod_settings.py +3 -0
- ntc/templates/drf_structure/templates/django_project/schema.py +7 -0
- ntc/templates/drf_structure/templates/django_project/urls.py +6 -0
- ntc/templates/drf_structure/templates/django_project/wsgi.py +5 -0
- ntc/templates/drf_structure/templates/docker/docker-compose.yml +11 -0
- ntc/templates/drf_structure/templates/knowledge/knowledge_description.md +201 -0
- ntc/templates/drf_structure/templates/knowledge/knowledge_design_pattern.md +722 -0
- ntc/templates/drf_structure/templates/knowledge/knowledge_structure.md +151 -0
- ntc/templates/drf_structure/templates/root/README.md +307 -0
- ntc/templates/drf_structure/templates/root/django_env.txt +98 -0
- ntc/templates/drf_structure/templates/root/django_requirements.txt +24 -0
- ntc/templates/drf_structure/templates/root/gitignore.txt +6 -0
- ntc/templates/drf_structure/templates/root/manage.py +11 -0
- ntc/templates/flutter/.gitignore +44 -0
- ntc/templates/flutter/.knowledge/knowledge_description.md +215 -0
- ntc/templates/flutter/.knowledge/knowledge_design_pattern.md +310 -0
- ntc/templates/flutter/.knowledge/knowledge_structure.md +83 -0
- ntc/templates/flutter/CLAUDE.md +190 -0
- ntc/templates/flutter/__init__.py +0 -0
- ntc/templates/flutter/analysis_options.yaml +9 -0
- ntc/templates/flutter/main.py +187 -0
- ntc/templates/flutter/pubspec.yaml +65 -0
- ntc/templates/flutter/structure.json +51 -0
- ntc/templates/nextjs/.env.example +10 -0
- ntc/templates/nextjs/.gitignore +36 -0
- ntc/templates/nextjs/CLAUDE.md +181 -0
- ntc/templates/nextjs/README.md +94 -0
- ntc/templates/nextjs/__init__.py +0 -0
- ntc/templates/nextjs/knowledge/knowledge_description.md +208 -0
- ntc/templates/nextjs/knowledge/knowledge_design_pattern.md +460 -0
- ntc/templates/nextjs/knowledge/knowledge_structure.md +75 -0
- ntc/templates/nextjs/main.py +224 -0
- ntc/templates/nextjs/package.json +25 -0
- ntc/templates/nextjs/src/app/globals.css +26 -0
- ntc/templates/nextjs/src/app/layout.tsx +59 -0
- ntc/templates/nextjs/src/app/page.tsx +21 -0
- ntc/templates/nextjs/src/components/Header.tsx +16 -0
- ntc/templates/nextjs/src/services/api.ts +81 -0
- ntc/templates/nextjs/src/utils/constants.ts +1 -0
- ntc/templates/nextjs/structure.json +32 -0
- ntc/templates/nextjs/tsconfig.json +27 -0
- ntc/templates/react_admin/.env.example +1 -0
- ntc/templates/react_admin/.gitignore +10 -0
- ntc/templates/react_admin/CLAUDE.md +210 -0
- ntc/templates/react_admin/README.md +72 -0
- ntc/templates/react_admin/__init__.py +0 -0
- ntc/templates/react_admin/index.html +13 -0
- ntc/templates/react_admin/knowledge/knowledge_description.md +202 -0
- ntc/templates/react_admin/knowledge/knowledge_design_pattern.md +448 -0
- ntc/templates/react_admin/knowledge/knowledge_structure.md +97 -0
- ntc/templates/react_admin/main.py +208 -0
- ntc/templates/react_admin/package.json +35 -0
- ntc/templates/react_admin/src/App.tsx +60 -0
- ntc/templates/react_admin/src/components/ProtectedRoute.tsx +16 -0
- ntc/templates/react_admin/src/components/Sidebar.tsx +90 -0
- ntc/templates/react_admin/src/components/TopNav.tsx +44 -0
- ntc/templates/react_admin/src/context/AuthContext.tsx +107 -0
- ntc/templates/react_admin/src/context/ThemeContext.tsx +34 -0
- ntc/templates/react_admin/src/context/WorkspaceContext.tsx +28 -0
- ntc/templates/react_admin/src/hooks/useApi.ts +39 -0
- ntc/templates/react_admin/src/index.css +34 -0
- ntc/templates/react_admin/src/layouts/AuthLayout.tsx +23 -0
- ntc/templates/react_admin/src/layouts/DashboardLayout.tsx +24 -0
- ntc/templates/react_admin/src/main.tsx +5 -0
- ntc/templates/react_admin/src/pages/DashboardPage.tsx +10 -0
- ntc/templates/react_admin/src/pages/auth/LoginPage.tsx +79 -0
- ntc/templates/react_admin/src/pages/auth/RegisterPage.tsx +93 -0
- ntc/templates/react_admin/src/services/api.service.ts +44 -0
- ntc/templates/react_admin/src/services/base.service.ts +193 -0
- ntc/templates/react_admin/structure.json +52 -0
- ntc/templates/react_admin/tsconfig.app.json +25 -0
- ntc/templates/react_admin/tsconfig.json +7 -0
- ntc/templates/react_admin/tsconfig.node.json +19 -0
- ntc/templates/react_admin/vite.config.ts +13 -0
- ntc/templates/react_structure/CLAUDE.md +176 -0
- ntc/templates/react_structure/__init__.py +1 -0
- ntc/templates/react_structure/index.css +21 -0
- ntc/templates/react_structure/index.html +13 -0
- ntc/templates/react_structure/knowledge/knowledge_description.md +170 -0
- ntc/templates/react_structure/knowledge/knowledge_design_pattern.md +411 -0
- ntc/templates/react_structure/knowledge/knowledge_structure.md +74 -0
- ntc/templates/react_structure/main.py +217 -0
- ntc/templates/react_structure/package.json +32 -0
- ntc/templates/react_structure/src/App.tsx +63 -0
- ntc/templates/react_structure/src/components/Header.tsx +51 -0
- ntc/templates/react_structure/src/main.tsx +5 -0
- ntc/templates/react_structure/src/services/api.ts +90 -0
- ntc/templates/react_structure/src/utils/constants.ts +1 -0
- ntc/templates/react_structure/structure.json +65 -0
- ntc/templates/react_structure/tsconfig.app.json +25 -0
- ntc/templates/react_structure/tsconfig.json +7 -0
- ntc/templates/react_structure/tsconfig.node.json +19 -0
- ntc/templates/react_structure/vite.config.ts +12 -0
- ntc/utils/__init__.py +1 -0
- ntc/utils/environment.py +67 -0
- ntc/utils/output.py +41 -0
- ntc_dev_kit-1.0.0.dist-info/METADATA +188 -0
- ntc_dev_kit-1.0.0.dist-info/RECORD +148 -0
- ntc_dev_kit-1.0.0.dist-info/WHEEL +5 -0
- ntc_dev_kit-1.0.0.dist-info/entry_points.txt +2 -0
- ntc_dev_kit-1.0.0.dist-info/licenses/LICENSE +21 -0
- ntc_dev_kit-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
# Architecture Overview - {project_name}
|
|
2
|
+
|
|
3
|
+
This document provides a comprehensive overview of the architecture and technical stack for this NTC-generated Flutter project.
|
|
4
|
+
|
|
5
|
+
## 🏗️ Architecture Overview
|
|
6
|
+
|
|
7
|
+
This is a modern Flutter mobile application built with Dart, Riverpod state management, and a clean architecture pattern designed for cross-platform development.
|
|
8
|
+
|
|
9
|
+
### Core Architecture Principles
|
|
10
|
+
|
|
11
|
+
- **Feature-Based Architecture**: Organized by features for better maintainability
|
|
12
|
+
- **Clean Architecture**: Separation of concerns with layers (presentation, domain, data)
|
|
13
|
+
- **Type Safety**: Dart 3 with null safety for compile-time type checking
|
|
14
|
+
- **State Management**: Riverpod for reactive state management
|
|
15
|
+
- **Dependency Injection**: Riverpod providers for dependency injection
|
|
16
|
+
|
|
17
|
+
## 🛠️ Technical Stack
|
|
18
|
+
|
|
19
|
+
### Flutter Framework
|
|
20
|
+
- **Flutter 3.19+**: Latest Flutter SDK
|
|
21
|
+
- **Dart 3.9+**: Latest Dart language with null safety
|
|
22
|
+
- **Platform Support**: Android, iOS, Web, Windows, macOS, Linux
|
|
23
|
+
|
|
24
|
+
### State Management
|
|
25
|
+
- **Riverpod 2.4+**: Reactive state management
|
|
26
|
+
- **StateNotifier**: For complex stateful logic
|
|
27
|
+
- **ProviderScope**: Root provider scope
|
|
28
|
+
|
|
29
|
+
### Networking & HTTP
|
|
30
|
+
- **Dio 5.4+**: Powerful HTTP client
|
|
31
|
+
- **Connectivity Plus**: Network connectivity monitoring
|
|
32
|
+
- **Flutter Secure Storage**: Secure token storage
|
|
33
|
+
|
|
34
|
+
### Local Storage
|
|
35
|
+
- **Hive 2.2+**: Fast local key-value database
|
|
36
|
+
- **Hive Flutter**: Hive integration for Flutter
|
|
37
|
+
- **Shared Preferences**: Simple key-value storage
|
|
38
|
+
|
|
39
|
+
### Internationalization
|
|
40
|
+
- **Flutter Localizations**: Built-in localization support
|
|
41
|
+
- **Intl**: Internationalization utilities
|
|
42
|
+
|
|
43
|
+
### UI & Theming
|
|
44
|
+
- **Google Fonts**: Custom font integration
|
|
45
|
+
- **Cached Network Image**: Image caching
|
|
46
|
+
- **Material Design 3**: Latest Material Design components
|
|
47
|
+
|
|
48
|
+
### Development Tools
|
|
49
|
+
- **Flutter Lints**: Code linting and style enforcement
|
|
50
|
+
- **Analysis Options**: Custom linting configuration
|
|
51
|
+
|
|
52
|
+
## 📊 Data Flow Architecture
|
|
53
|
+
|
|
54
|
+
### API Communication Flow
|
|
55
|
+
```
|
|
56
|
+
Widget → Riverpod Provider → ApiService → DioClient → Backend API
|
|
57
|
+
↓
|
|
58
|
+
Interceptors
|
|
59
|
+
↓
|
|
60
|
+
Auth Token Injection
|
|
61
|
+
↓
|
|
62
|
+
Error Handling
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### State Management Flow
|
|
66
|
+
```
|
|
67
|
+
Widget → ConsumerWidget → Provider → StateNotifier → State Update → Widget Rebuild
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## 🔐 Authentication Architecture
|
|
71
|
+
|
|
72
|
+
### JWT Token Management
|
|
73
|
+
- Tokens stored in Flutter Secure Storage
|
|
74
|
+
- Automatic token injection via Dio interceptors
|
|
75
|
+
- Token removal on 401 responses
|
|
76
|
+
- Login/logout through API service
|
|
77
|
+
|
|
78
|
+
### Secure Storage
|
|
79
|
+
- Flutter Secure Storage for sensitive data
|
|
80
|
+
- Hive for local data storage
|
|
81
|
+
- Shared Preferences for simple settings
|
|
82
|
+
|
|
83
|
+
## 🌐 API Service Architecture
|
|
84
|
+
|
|
85
|
+
### Dio Client Configuration
|
|
86
|
+
- Base URL from environment variable
|
|
87
|
+
- 30-second timeout
|
|
88
|
+
- JSON content-type headers
|
|
89
|
+
- Request/response interceptors
|
|
90
|
+
- Error handling utilities
|
|
91
|
+
|
|
92
|
+
### Available Methods
|
|
93
|
+
- `get(path, queryParameters)`: GET requests
|
|
94
|
+
- `post(path, data, queryParameters)`: POST requests
|
|
95
|
+
- `put(path, data, queryParameters)`: PUT requests
|
|
96
|
+
- `patch(path, data, queryParameters)`: PATCH requests
|
|
97
|
+
- `delete(path, queryParameters)`: DELETE requests
|
|
98
|
+
|
|
99
|
+
## 📁 Widget Architecture
|
|
100
|
+
|
|
101
|
+
### Widget Hierarchy
|
|
102
|
+
```
|
|
103
|
+
ProviderScope (Root)
|
|
104
|
+
├── MaterialApp
|
|
105
|
+
│ ├── Theme (MaterialApp)
|
|
106
|
+
│ ├── Locale (MaterialApp)
|
|
107
|
+
│ └── HomeScreen
|
|
108
|
+
│ └── [Child Widgets]
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Widget Patterns
|
|
112
|
+
- **ConsumerWidget**: For widgets that need providers
|
|
113
|
+
- **ConsumerStatefulWidget**: For complex stateful widgets
|
|
114
|
+
- **Const Widgets**: For static widgets
|
|
115
|
+
- **StatelessWidget**: For simple stateless widgets
|
|
116
|
+
|
|
117
|
+
## 🔧 Configuration Architecture
|
|
118
|
+
|
|
119
|
+
### Environment Variables
|
|
120
|
+
- `API_BASE_URL`: Backend API base URL
|
|
121
|
+
- `ENV`: Environment (development/staging/production)
|
|
122
|
+
- `SENTRY_DSN`: Sentry DSN for error tracking
|
|
123
|
+
|
|
124
|
+
### Build Configuration
|
|
125
|
+
- **Pubspec.yaml**: Dependencies and Flutter configuration
|
|
126
|
+
- **Analysis Options.yaml**: Linting configuration
|
|
127
|
+
- **Environment**: Build-time environment variables
|
|
128
|
+
|
|
129
|
+
## 🚀 Build Process
|
|
130
|
+
|
|
131
|
+
### Development Build
|
|
132
|
+
- Flutter dev server with hot reload
|
|
133
|
+
- Dart compilation on-the-fly
|
|
134
|
+
- Source maps for debugging
|
|
135
|
+
- Platform-specific debugging
|
|
136
|
+
|
|
137
|
+
### Production Build
|
|
138
|
+
- Dart compilation to native code
|
|
139
|
+
- Code splitting and tree shaking
|
|
140
|
+
- Asset optimization
|
|
141
|
+
- Platform-specific build outputs:
|
|
142
|
+
- Android: APK/AAB
|
|
143
|
+
- iOS: IPA
|
|
144
|
+
- Web: HTML/JS/CSS
|
|
145
|
+
- Desktop: Native executables
|
|
146
|
+
|
|
147
|
+
## 🎯 Performance Considerations
|
|
148
|
+
|
|
149
|
+
### Optimization Strategies
|
|
150
|
+
- Use const widgets where possible
|
|
151
|
+
- Avoid unnecessary rebuilds with Riverpod
|
|
152
|
+
- Use ListView.builder for long lists
|
|
153
|
+
- Optimize images with CachedNetworkImage
|
|
154
|
+
- Implement proper caching strategies
|
|
155
|
+
|
|
156
|
+
### Best Practices
|
|
157
|
+
- Use ConsumerWidget only when needed
|
|
158
|
+
- Keep widgets small and focused
|
|
159
|
+
- Extract reusable widgets
|
|
160
|
+
- Use proper keys for lists
|
|
161
|
+
- Implement lazy loading
|
|
162
|
+
|
|
163
|
+
## 🔒 Security Considerations
|
|
164
|
+
|
|
165
|
+
### Security Measures
|
|
166
|
+
- HTTPS in production
|
|
167
|
+
- Secure storage for tokens
|
|
168
|
+
- Input validation
|
|
169
|
+
- XSS prevention
|
|
170
|
+
- CSRF protection (via backend)
|
|
171
|
+
- Environment variable security
|
|
172
|
+
|
|
173
|
+
### Environment Variable Security
|
|
174
|
+
- Never commit secrets
|
|
175
|
+
- Use build-time environment variables
|
|
176
|
+
- Server-side secrets should not be exposed
|
|
177
|
+
|
|
178
|
+
## 📈 Localization Architecture
|
|
179
|
+
|
|
180
|
+
### Localization Features
|
|
181
|
+
- AppLocalizations for string translations
|
|
182
|
+
- Support for multiple languages (English, Swahili)
|
|
183
|
+
- Locale persistence
|
|
184
|
+
- Language switching
|
|
185
|
+
|
|
186
|
+
### Best Practices
|
|
187
|
+
- Use AppLocalizations for all user-facing strings
|
|
188
|
+
- Support RTL languages if needed
|
|
189
|
+
- Test all language variants
|
|
190
|
+
- Use proper number/date formatting
|
|
191
|
+
|
|
192
|
+
## 🔒 Accessibility Architecture
|
|
193
|
+
|
|
194
|
+
### Accessibility Features
|
|
195
|
+
- Semantic labels
|
|
196
|
+
- Screen reader support
|
|
197
|
+
- Proper touch targets
|
|
198
|
+
- Color contrast compliance
|
|
199
|
+
- Focus management
|
|
200
|
+
|
|
201
|
+
## 📈 Scalability Architecture
|
|
202
|
+
|
|
203
|
+
### Scalability Features
|
|
204
|
+
- Feature-based organization
|
|
205
|
+
- Service layer abstraction
|
|
206
|
+
- Modular file structure
|
|
207
|
+
- Easy integration with new features
|
|
208
|
+
- Support for multiple API endpoints
|
|
209
|
+
|
|
210
|
+
### Future Extensibility
|
|
211
|
+
- Easy addition of new features
|
|
212
|
+
- Integration with Firebase
|
|
213
|
+
- Analytics integration
|
|
214
|
+
- Push notifications
|
|
215
|
+
- Background services
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
# Design Patterns and Coding Conventions - {project_name}
|
|
2
|
+
|
|
3
|
+
This document describes the design patterns and coding conventions used in this NTC-generated Flutter project.
|
|
4
|
+
|
|
5
|
+
## 🎨 Widget Design Patterns
|
|
6
|
+
|
|
7
|
+
### Stateless Widget Pattern
|
|
8
|
+
```dart
|
|
9
|
+
class MyWidget extends StatelessWidget {
|
|
10
|
+
const MyWidget({super.key});
|
|
11
|
+
|
|
12
|
+
@override
|
|
13
|
+
Widget build(BuildContext context) {
|
|
14
|
+
return Container();
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### Consumer Widget Pattern (Riverpod)
|
|
20
|
+
```dart
|
|
21
|
+
class MyWidget extends ConsumerWidget {
|
|
22
|
+
const MyWidget({super.key});
|
|
23
|
+
|
|
24
|
+
@override
|
|
25
|
+
Widget build(BuildContext context, WidgetRef ref) {
|
|
26
|
+
final value = ref.watch(myProvider);
|
|
27
|
+
return Container();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Consumer Stateful Widget Pattern
|
|
33
|
+
```dart
|
|
34
|
+
class MyWidget extends ConsumerStatefulWidget {
|
|
35
|
+
const MyWidget({super.key});
|
|
36
|
+
|
|
37
|
+
@override
|
|
38
|
+
ConsumerState<MyWidget> createState() => _MyWidgetState();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
class _MyWidgetState extends ConsumerState<MyWidget> {
|
|
42
|
+
@override
|
|
43
|
+
Widget build(BuildContext context) {
|
|
44
|
+
return Container();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## 🔧 Service Layer Pattern
|
|
50
|
+
|
|
51
|
+
### API Service Pattern
|
|
52
|
+
```dart
|
|
53
|
+
class ApiService {
|
|
54
|
+
static ApiService? _instance;
|
|
55
|
+
late DioClient _dioClient;
|
|
56
|
+
|
|
57
|
+
ApiService._() {
|
|
58
|
+
_dioClient = DioClient.instance;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
static ApiService get instance {
|
|
62
|
+
_instance ??= ApiService._();
|
|
63
|
+
return _instance!;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
Future<Response> get(String path) async {
|
|
67
|
+
return _dioClient.dio.get(path);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## 📝 Dart Patterns
|
|
73
|
+
|
|
74
|
+
### Type Safety Pattern
|
|
75
|
+
```dart
|
|
76
|
+
// Always use specific types
|
|
77
|
+
String name = 'John';
|
|
78
|
+
int age = 30;
|
|
79
|
+
List<String> items = ['a', 'b'];
|
|
80
|
+
Map<String, int> map = {'key': 1};
|
|
81
|
+
|
|
82
|
+
// Avoid dynamic
|
|
83
|
+
// dynamic value = getValue(); // Avoid
|
|
84
|
+
// String value = getValue(); // Prefer
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Null Safety Pattern
|
|
88
|
+
```dart
|
|
89
|
+
// Use nullable types when needed
|
|
90
|
+
String? name;
|
|
91
|
+
|
|
92
|
+
// Use null-aware operators
|
|
93
|
+
name?.toUpperCase();
|
|
94
|
+
name ?? 'Default';
|
|
95
|
+
|
|
96
|
+
// Use late for late initialization
|
|
97
|
+
late final ApiService _apiService;
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Async Pattern
|
|
101
|
+
```dart
|
|
102
|
+
Future<void> fetchData() async {
|
|
103
|
+
try {
|
|
104
|
+
final response = await apiService.get('/endpoint');
|
|
105
|
+
// Handle response
|
|
106
|
+
} catch (e) {
|
|
107
|
+
// Handle error
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## 🎯 State Management Patterns
|
|
113
|
+
|
|
114
|
+
### Provider Pattern
|
|
115
|
+
```dart
|
|
116
|
+
final myProvider = Provider<int>((ref) {
|
|
117
|
+
return 42;
|
|
118
|
+
});
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### StateNotifier Pattern
|
|
122
|
+
```dart
|
|
123
|
+
class MyNotifier extends StateNotifier<int> {
|
|
124
|
+
MyNotifier() : super(0);
|
|
125
|
+
|
|
126
|
+
void increment() {
|
|
127
|
+
state++;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
final myNotifierProvider = StateNotifierProvider<MyNotifier, int>((ref) {
|
|
132
|
+
return MyNotifier();
|
|
133
|
+
});
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Family Provider Pattern
|
|
137
|
+
```dart
|
|
138
|
+
final myFamilyProvider = Provider.family<int, String>((ref, id) {
|
|
139
|
+
return int.parse(id);
|
|
140
|
+
});
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## 🔄 Async Pattern
|
|
144
|
+
|
|
145
|
+
### Async Widget Pattern
|
|
146
|
+
```dart
|
|
147
|
+
class AsyncWidget extends ConsumerFutureWidget<String> {
|
|
148
|
+
const AsyncWidget({super.key});
|
|
149
|
+
|
|
150
|
+
@override
|
|
151
|
+
Future<String> build(BuildContext context, WidgetRef ref) async {
|
|
152
|
+
return await fetchData();
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
@override
|
|
156
|
+
Widget buildData(BuildContext context, WidgetRef ref, String data) {
|
|
157
|
+
return Text(data);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
@override
|
|
161
|
+
Widget buildError(BuildContext context, WidgetRef ref, Object error, StackTrace? stackTrace) {
|
|
162
|
+
return Text('Error: $error');
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
@override
|
|
166
|
+
Widget buildLoading(BuildContext context, WidgetRef ref) {
|
|
167
|
+
return const CircularProgressIndicator();
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
## 🎨 Layout Pattern
|
|
173
|
+
|
|
174
|
+
### Scaffold Pattern
|
|
175
|
+
```dart
|
|
176
|
+
Scaffold(
|
|
177
|
+
appBar: AppBar(
|
|
178
|
+
title: const Text('Title'),
|
|
179
|
+
),
|
|
180
|
+
body: const Center(
|
|
181
|
+
child: Text('Content'),
|
|
182
|
+
),
|
|
183
|
+
floatingActionButton: FloatingActionButton(
|
|
184
|
+
onPressed: () {},
|
|
185
|
+
child: const Icon(Icons.add),
|
|
186
|
+
),
|
|
187
|
+
)
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## 🎨 Styling Pattern
|
|
191
|
+
|
|
192
|
+
### Theme Pattern
|
|
193
|
+
```dart
|
|
194
|
+
final theme = Theme.of(context);
|
|
195
|
+
final colorScheme = theme.colorScheme;
|
|
196
|
+
final textTheme = theme.textTheme;
|
|
197
|
+
|
|
198
|
+
Text(
|
|
199
|
+
'Hello',
|
|
200
|
+
style: textTheme.titleLarge,
|
|
201
|
+
)
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
## 📦 File Organization Patterns
|
|
205
|
+
|
|
206
|
+
### Feature-Based Structure
|
|
207
|
+
```
|
|
208
|
+
lib/features/
|
|
209
|
+
├── feature_name/
|
|
210
|
+
│ ├── data/ # Data models and repositories
|
|
211
|
+
│ ├── domain/ # Business logic
|
|
212
|
+
│ └── presentation/ # UI components
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
### Type-Based Structure
|
|
216
|
+
```
|
|
217
|
+
lib/
|
|
218
|
+
├── core/ # Core functionality
|
|
219
|
+
├── features/ # Feature modules
|
|
220
|
+
├── services/ # External services
|
|
221
|
+
├── shared/ # Shared components
|
|
222
|
+
├── types/ # Type definitions
|
|
223
|
+
└── l10n/ # Localization
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
## 🔒 Error Handling Patterns
|
|
227
|
+
|
|
228
|
+
### Try-Catch Pattern
|
|
229
|
+
```dart
|
|
230
|
+
Future<void> safeAsyncOperation() async {
|
|
231
|
+
try {
|
|
232
|
+
final result = await apiService.get('/endpoint');
|
|
233
|
+
return result;
|
|
234
|
+
} catch (error) {
|
|
235
|
+
debugPrint('Operation failed: $error');
|
|
236
|
+
rethrow;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
## 🚀 Performance Patterns
|
|
242
|
+
|
|
243
|
+
### Const Pattern
|
|
244
|
+
```dart
|
|
245
|
+
// Use const for static widgets
|
|
246
|
+
const Text('Hello');
|
|
247
|
+
const Icon(Icons.add);
|
|
248
|
+
|
|
249
|
+
// Use const constructors
|
|
250
|
+
const MyWidget();
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
### ListView Builder Pattern
|
|
254
|
+
```dart
|
|
255
|
+
ListView.builder(
|
|
256
|
+
itemCount: items.length,
|
|
257
|
+
itemBuilder: (context, index) {
|
|
258
|
+
return ListTile(title: Text(items[index]));
|
|
259
|
+
},
|
|
260
|
+
)
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
## 📐 Naming Conventions
|
|
264
|
+
|
|
265
|
+
### Widgets
|
|
266
|
+
- **File**: `snake_case.dart` (e.g., `user_profile.dart`)
|
|
267
|
+
- **Widget**: `PascalCase` (e.g., `UserProfile`)
|
|
268
|
+
|
|
269
|
+
### Providers
|
|
270
|
+
- **File**: `snake_case_provider.dart` (e.g., `user_provider.dart`)
|
|
271
|
+
- **Provider**: `camelCaseProvider` (e.g., `userProvider`)
|
|
272
|
+
|
|
273
|
+
### Services
|
|
274
|
+
- **File**: `snake_case_service.dart` (e.g., `api_service.dart`)
|
|
275
|
+
- **Service**: `PascalCase` (e.g., `ApiService`)
|
|
276
|
+
|
|
277
|
+
### Variables
|
|
278
|
+
- **Local**: `camelCase` (e.g., `userName`)
|
|
279
|
+
- **Private**: `_camelCase` (e.g., `_userName`)
|
|
280
|
+
- **Constants**: `UPPER_SNAKE_CASE` (e.g., `API_BASE_URL`)
|
|
281
|
+
|
|
282
|
+
## 🎯 Best Practices
|
|
283
|
+
|
|
284
|
+
### Code Organization
|
|
285
|
+
1. Keep widgets small and focused
|
|
286
|
+
2. Extract reusable logic into providers
|
|
287
|
+
3. Use const constructors where possible
|
|
288
|
+
4. Organize imports (external, internal)
|
|
289
|
+
5. Use relative imports for internal files
|
|
290
|
+
|
|
291
|
+
### Performance
|
|
292
|
+
1. Use const widgets where possible
|
|
293
|
+
2. Avoid unnecessary rebuilds with Riverpod
|
|
294
|
+
3. Use ListView.builder for long lists
|
|
295
|
+
4. Optimize images with CachedNetworkImage
|
|
296
|
+
5. Implement proper caching
|
|
297
|
+
|
|
298
|
+
### Accessibility
|
|
299
|
+
1. Use semantic labels
|
|
300
|
+
2. Provide semantic labels for buttons
|
|
301
|
+
3. Ensure proper contrast
|
|
302
|
+
4. Test with screen readers
|
|
303
|
+
5. Use proper touch targets
|
|
304
|
+
|
|
305
|
+
### Security
|
|
306
|
+
1. Sanitize user input
|
|
307
|
+
2. Use HTTPS in production
|
|
308
|
+
3. Validate data on client and server
|
|
309
|
+
4. Never expose sensitive data
|
|
310
|
+
5. Use environment variables for secrets
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# Project Structure - {project_name}
|
|
2
|
+
|
|
3
|
+
This document describes the complete project structure and organization for AI assistants to understand how to work with this codebase.
|
|
4
|
+
|
|
5
|
+
## 📁 Root Directory Structure
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
{project_name}/
|
|
9
|
+
├── .gitignore # Git ignore patterns
|
|
10
|
+
├── .knowledge/ # AI documentation (this directory)
|
|
11
|
+
├── pubspec.yaml # Flutter dependencies
|
|
12
|
+
├── analysis_options.yaml # Dart linting configuration
|
|
13
|
+
├── README.md # Project documentation
|
|
14
|
+
└── lib/ # Source code
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## 🏗️ Source Directory Structure (`lib/`)
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
lib/
|
|
21
|
+
├── core/ # Core functionality
|
|
22
|
+
│ ├── config/ # Configuration files
|
|
23
|
+
│ │ ├── app_config.dart # App configuration
|
|
24
|
+
│ │ └── environment.dart # Environment configuration
|
|
25
|
+
│ ├── constants/ # Application constants
|
|
26
|
+
│ │ └── app_constants.dart # App-wide constants
|
|
27
|
+
│ ├── network/ # Networking layer
|
|
28
|
+
│ │ └── dio_client.dart # Dio HTTP client
|
|
29
|
+
│ └── utils/ # Utility functions
|
|
30
|
+
├── features/ # Feature-based organization
|
|
31
|
+
│ └── home/ # Home feature
|
|
32
|
+
│ └── presentation/
|
|
33
|
+
│ └── home_screen.dart # Home screen widget
|
|
34
|
+
├── services/ # External services
|
|
35
|
+
│ └── api_service.dart # API service
|
|
36
|
+
├── shared/ # Shared components
|
|
37
|
+
│ ├── theme/ # Theme configuration
|
|
38
|
+
│ │ ├── app_theme.dart # App theme
|
|
39
|
+
│ │ └── theme_provider.dart # Theme provider
|
|
40
|
+
│ └── localization/ # Localization
|
|
41
|
+
│ └── locale_provider.dart # Locale provider
|
|
42
|
+
├── types/ # Type definitions
|
|
43
|
+
├── l10n/ # Localization files
|
|
44
|
+
│ └── app_localizations.dart # App localizations
|
|
45
|
+
└── main.dart # App entry point
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## 🎯 Key Conventions
|
|
49
|
+
|
|
50
|
+
### File Naming
|
|
51
|
+
- **Dart files**: `snake_case.dart` (e.g., `user_profile.dart`)
|
|
52
|
+
- **Widgets**: `PascalCase` (e.g., `UserProfile`)
|
|
53
|
+
- **Providers**: `snake_case_provider.dart` (e.g., `user_provider.dart`)
|
|
54
|
+
- **Services**: `snake_case_service.dart` (e.g., `api_service.dart`)
|
|
55
|
+
|
|
56
|
+
### Import Patterns
|
|
57
|
+
- **Relative imports**: Use relative imports for files within the same package
|
|
58
|
+
- **Package imports**: Use package imports for external dependencies
|
|
59
|
+
- **Core imports**: `import '../core/config/app_config.dart'`
|
|
60
|
+
- **Feature imports**: `import '../features/home/presentation/home_screen.dart'`
|
|
61
|
+
|
|
62
|
+
### Dart Patterns
|
|
63
|
+
- **Type safety**: Always use specific types, avoid `dynamic`
|
|
64
|
+
- **Null safety**: Use Dart 3 null safety features
|
|
65
|
+
- **Const constructors**: Use `const` where possible for performance
|
|
66
|
+
- **Async/await**: Use async/await for asynchronous operations
|
|
67
|
+
|
|
68
|
+
## 🔄 Development Workflow
|
|
69
|
+
|
|
70
|
+
1. **Install dependencies**: `flutter pub get`
|
|
71
|
+
2. **Run development**: `flutter run`
|
|
72
|
+
3. **Build for production**: `flutter build apk` or `flutter build ios`
|
|
73
|
+
4. **Run tests**: `flutter test`
|
|
74
|
+
5. **Run linter**: `flutter analyze`
|
|
75
|
+
|
|
76
|
+
## 📋 Important Notes for AI
|
|
77
|
+
|
|
78
|
+
- **Always use Dart 3+**: This project uses Dart 3 with null safety
|
|
79
|
+
- **Follow the feature structure**: New features go in `lib/features/`
|
|
80
|
+
- **Use Riverpod**: State management is done with Riverpod
|
|
81
|
+
- **Handle errors**: Always handle errors gracefully with user feedback
|
|
82
|
+
- **Use environment variables**: Configuration via `String.fromEnvironment()`
|
|
83
|
+
- **Platform support**: This template supports Android, iOS, Web, Windows, macOS, Linux
|