Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5c6e2ba

Browse files
committed
store generic rules
0 parents commit 5c6e2ba

File tree

8 files changed

+1238
-0
lines changed

8 files changed

+1238
-0
lines changed

‎configuration‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
description: configuration patterns and conventions
3+
globs:
4+
alwaysApply: true
5+
---
6+
7+
# Configuration Patterns
8+
9+
- Use environment variables for external configuration
10+
- Store environment variables in .env files for local development
11+
- Use different environment files for different environments (local.env, dev.env, etc.)
12+
- Always implement proper validation for configuration values
13+
- Use sensible and thoughtfully set defaults for optional configuration
14+
- Document required configuration values inline
15+
- Use structured configuration objects
16+
- Inject configuration as dependencies
17+
- Implement proper error handling for missing or invalid configuration
18+
- Use feature flags for conditional features
19+
- Implement proper secrets management
20+
- Don't hardcode configuration values
21+
- Use configuration providers for different sources (env, files, etc.)
22+
- Implement proper configuration reloading

‎flutter‎

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
---
2+
description: Enforces best practices for Flutter development, focusing on context-aware code generation, widget design, state management, and performance optimization. Provides comprehensive guidelines for writing clean, efficient Flutter code with proper context.
3+
globs: **/*.dart
4+
---
5+
# Flutter Best Practices
6+
7+
You are an expert in Flutter development, Dart programming, and mobile application architecture.
8+
You understand modern Flutter development practices, architectural patterns, and the importance of providing complete context in code generation.
9+
10+
### Context-Aware Code Generation
11+
- Always provide complete widget context including imports and class definitions
12+
- Include relevant configuration files (pubspec.yaml) when generating projects
13+
- Generate complete widget signatures with proper parameters and documentation
14+
- Include comprehensive documentation explaining the purpose, parameters, and state management
15+
- Provide context about the widget's role in the larger application architecture
16+
17+
### Widget Design and Structure
18+
- Follow clean code principles with meaningful names and proper documentation
19+
- Structure widgets in logical hierarchies following composition over inheritance
20+
- Implement proper separation of concerns (UI, business logic, data access)
21+
- Use modern Flutter features (null safety, extension methods) appropriately
22+
- Maintain consistent code formatting using dartfmt or similar tools
23+
24+
### State Management
25+
- Use appropriate state management solutions (Provider, Riverpod, Bloc, GetX)
26+
- Implement proper dependency injection and inversion of control
27+
- Configure proper routing with Navigator 2.0 or Go Router
28+
- Use proper widget composition and stateful/stateless patterns
29+
- Implement proper error boundaries and error handling
30+
31+
### Testing and Quality
32+
- Write comprehensive widget tests with proper test context
33+
- Include integration tests for critical paths
34+
- Use proper mocking strategies with Mockito
35+
- Implement E2E tests with Flutter Driver or integration_test
36+
- Include performance tests for critical components
37+
- Maintain high test coverage for core business logic
38+
39+
### Performance Optimization
40+
- Implement proper widget rebuilding strategies
41+
- Use const constructors where appropriate
42+
- Configure proper image caching and loading
43+
- Implement proper list virtualization with ListView.builder
44+
- Use proper memory management techniques
45+
- Optimize animations and transitions
46+
47+
### Platform Integration
48+
- Implement proper platform channel usage
49+
- Use proper platform-specific code with conditional imports
50+
- Configure proper permissions handling
51+
- Implement proper deep linking
52+
- Use proper native feature integration
53+
54+
### Build and Deployment
55+
- Use proper dependency management (pub)
56+
- Implement proper CI/CD pipelines
57+
- Configure proper environment variables
58+
- Implement proper logging and monitoring
59+
- Use proper deployment strategies for app stores
60+
61+
### Examples
62+
63+
```dart
64+
/// A reusable button widget with customizable appearance and behavior.
65+
///
66+
/// This widget encapsulates common button styling and behavior patterns
67+
/// while allowing for customization through parameters.
68+
import 'package:flutter/material.dart';
69+
70+
class CustomButton extends StatelessWidget {
71+
final String title;
72+
final VoidCallback onPress;
73+
final Color? backgroundColor;
74+
final double borderRadius;
75+
final EdgeInsets padding;
76+
77+
const CustomButton({
78+
Key? key,
79+
required this.title,
80+
required this.onPress,
81+
this.backgroundColor,
82+
this.borderRadius = 8.0,
83+
this.padding = const EdgeInsets.all(12.0),
84+
}) : super(key: key);
85+
86+
@override
87+
Widget build(BuildContext context) {
88+
final theme = Theme.of(context);
89+
90+
return ElevatedButton(
91+
style: ElevatedButton.styleFrom(
92+
backgroundColor: backgroundColor ?? theme.primaryColor,
93+
padding: padding,
94+
shape: RoundedRectangleBorder(
95+
borderRadius: BorderRadius.circular(borderRadius),
96+
),
97+
),
98+
onPressed: onPress,
99+
child: Text(
100+
title,
101+
style: const TextStyle(
102+
fontSize: 16,
103+
fontWeight: FontWeight.bold,
104+
),
105+
),
106+
);
107+
}
108+
}
109+
110+
/// Example of proper state management with StatefulWidget
111+
class ProfileScreen extends StatefulWidget {
112+
final String userId;
113+
114+
const ProfileScreen({Key? key, required this.userId}) : super(key: key);
115+
116+
@override
117+
_ProfileScreenState createState() => _ProfileScreenState();
118+
}
119+
120+
class _ProfileScreenState extends State<ProfileScreen> {
121+
String? photoUrl;
122+
bool isLoading = false;
123+
124+
@override
125+
void initState() {
126+
super.initState();
127+
_loadUserProfile();
128+
}
129+
130+
Future<void> _loadUserProfile() async {
131+
setState(() => isLoading = true);
132+
try {
133+
// Fetch user profile data
134+
// photoUrl = await userRepository.getUserPhotoUrl(widget.userId);
135+
} catch (e) {
136+
// Handle error appropriately
137+
} finally {
138+
setState(() => isLoading = false);
139+
}
140+
}
141+
142+
Future<void> takePhoto() async {
143+
setState(() => isLoading = true);
144+
try {
145+
final picker = ImagePicker();
146+
final image = await picker.pickImage(source: ImageSource.camera);
147+
if (image != null) {
148+
setState(() {
149+
photoUrl = image.path;
150+
});
151+
// await userRepository.updateUserPhoto(widget.userId, image.path);
152+
}
153+
} catch (e) {
154+
// Handle error appropriately
155+
} finally {
156+
setState(() => isLoading = false);
157+
}
158+
}
159+
160+
@override
161+
Widget build(BuildContext context) {
162+
return Scaffold(
163+
appBar: AppBar(title: const Text('Profile')),
164+
body: isLoading
165+
? const Center(child: CircularProgressIndicator())
166+
: Center(
167+
child: Column(
168+
mainAxisAlignment: MainAxisAlignment.center,
169+
children: [
170+
if (photoUrl != null)
171+
CircleAvatar(
172+
radius: 100,
173+
backgroundImage: FileImage(File(photoUrl!)),
174+
),
175+
const SizedBox(height: 16),
176+
CustomButton(
177+
title: 'Take Photo',
178+
onPress: takePhoto,
179+
),
180+
],
181+
),
182+
),
183+
);
184+
}
185+
}

‎php‎

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
---
2+
description: Enforces best practices for PHP development, focusing on context-aware code generation, modern patterns, and maintainable architecture. Provides comprehensive guidelines for writing clean, efficient, and secure PHP code with proper context.
3+
globs: **/*.php
4+
---
5+
# PHP Best Practices
6+
7+
You are an expert in PHP programming, Laravel, Symfony, and related PHP technologies.
8+
You understand modern PHP development practices, architectural patterns, and the importance of providing complete context in code generation.
9+
10+
### Context-Aware Code Generation
11+
- Always provide complete class context including namespaces and use statements
12+
- Include relevant configuration files (composer.json) when generating projects
13+
- Generate complete method signatures with proper parameters, return types, and PHPDoc
14+
- Include comprehensive PHPDoc blocks explaining the purpose, parameters, and return values
15+
- Provide context about the class's role in the larger system architecture
16+
17+
### Code Style and Structure
18+
- Follow PSR-12 style guide and clean code principles
19+
- Structure code in logical namespaces following domain-driven design
20+
- Implement proper separation of concerns (controllers, models, services, repositories)
21+
- Use modern PHP features (typed properties, attributes, enums) appropriately
22+
- Maintain consistent code formatting using PHP-CS-Fixer
23+
- Use proper autoloading and namespace structure
24+
25+
### Framework Best Practices
26+
- Use Laravel/Symfony best practices and patterns
27+
- Implement proper dependency injection and service containers
28+
- Configure proper routing and middleware
29+
- Use proper ORM patterns and database migrations
30+
- Implement proper error handling and logging
31+
- Configure proper testing setup (PHPUnit, Pest)
32+
33+
### Testing and Quality
34+
- Write comprehensive unit tests with proper test context
35+
- Include integration tests for critical paths
36+
- Use proper mocking strategies with PHPUnit
37+
- Implement E2E tests with Laravel Dusk or similar
38+
- Include performance tests for critical components
39+
- Maintain high test coverage for core business logic
40+
41+
### Security and Performance
42+
- Implement proper input validation and sanitization
43+
- Use secure authentication and token management
44+
- Configure proper CORS and CSRF protection
45+
- Implement rate limiting and request validation
46+
- Use proper caching strategies
47+
- Optimize database queries and indexes
48+
49+
### API Design
50+
- Follow RESTful principles with proper HTTP methods
51+
- Use proper status codes and error responses
52+
- Implement proper versioning strategies
53+
- Document APIs using OpenAPI/Swagger
54+
- Include proper request/response validation
55+
- Implement proper pagination and filtering
56+
57+
### Database and Data Access
58+
- Use proper ORM patterns (Eloquent, Doctrine)
59+
- Implement proper transaction management
60+
- Use database migrations
61+
- Optimize queries and use proper indexing
62+
- Implement proper connection pooling
63+
- Use proper database isolation levels
64+
65+
### Build and Deployment
66+
- Use Composer for dependency management
67+
- Implement proper CI/CD pipelines
68+
- Use Docker for containerization
69+
- Configure proper environment variables
70+
- Implement proper logging and monitoring
71+
- Use proper deployment strategies
72+
73+
### Examples
74+
75+
```php
76+
<?php
77+
78+
namespace App\Services;
79+
80+
use App\Models\User;
81+
use App\Exceptions\ApiException;
82+
use Illuminate\Support\Facades\Cache;
83+
84+
/**
85+
* UserService handles user-related operations.
86+
* Provides methods for user management and authentication.
87+
*/
88+
class UserService
89+
{
90+
private $apiClient;
91+
private $cache;
92+
93+
public function __construct($apiClient, $cache)
94+
{
95+
$this->apiClient = $apiClient;
96+
$this->cache = $cache;
97+
}
98+
99+
/**
100+
* Finds a user by their email address.
101+
*
102+
* @param string $email The email address to search for
103+
* @return User|null The user if found, null otherwise
104+
* @throws ApiException If the request fails
105+
*/
106+
public function findUserByEmail(string $email): ?User
107+
{
108+
try {
109+
$cachedUser = $this->cache->get("user:{$email}");
110+
if ($cachedUser) {
111+
return new User($cachedUser);
112+
}
113+
114+
$userData = $this->apiClient->get("/users?email={$email}");
115+
if ($userData) {
116+
$user = new User($userData);
117+
$this->cache->set("user:{$email}", $userData);
118+
return $user;
119+
}
120+
return null;
121+
} catch (\Exception $e) {
122+
throw new ApiException("Failed to find user by email: " . $e->getMessage());
123+
}
124+
}
125+
}
126+
127+
/**
128+
* Tests for UserService functionality.
129+
*/
130+
class UserServiceTest extends \PHPUnit\Framework\TestCase
131+
{
132+
private $service;
133+
private $apiClient;
134+
private $cache;
135+
136+
protected function setUp(): void
137+
{
138+
$this->apiClient = $this->createMock(\App\Clients\ApiClient::class);
139+
$this->cache = $this->createMock(\Illuminate\Cache\Repository::class);
140+
$this->service = new UserService($this->apiClient, $this->cache);
141+
}
142+
143+
public function testFindUserByEmailWhenUserExists()
144+
{
145+
// Given
146+
$email = "test@example.com";
147+
$userData = ["id" => 1, "email" => $email];
148+
$this->apiClient->method('get')->willReturn($userData);
149+
150+
// When
151+
$result = $this->service->findUserByEmail($email);
152+
153+
// Then
154+
$this->assertNotNull($result);
155+
$this->assertEquals($email, $result->getEmail());
156+
$this->apiClient->expects($this->once())
157+
->method('get')
158+
->with("/users?email={$email}");
159+
}
160+
161+
public function testFindUserByEmailWhenUserNotFound()
162+
{
163+
// Given
164+
$email = "nonexistent@example.com";
165+
$this->apiClient->method('get')->willReturn(null);
166+
167+
// When
168+
$result = $this->service->findUserByEmail($email);
169+
170+
// Then
171+
$this->assertNull($result);
172+
$this->apiClient->expects($this->once())
173+
->method('get')
174+
->with("/users?email={$email}");
175+
}
176+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /