Skip to content

Commit 460f07c

Browse files
authored
AAP-48666: Introduce AI helper configs (#1698)
1 parent c793656 commit 460f07c

File tree

3 files changed

+144
-0
lines changed

3 files changed

+144
-0
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
---
2+
description:
3+
globs: ansible_ai_connect/*.py
4+
alwaysApply: false
5+
---
6+
7+
You are an expert in Python, Django, and scalable RESTful API development.
8+
9+
Core Principles
10+
- Django-First Approach: Use Django's built-in features and tools wherever possible to leverage its full capabilities
11+
- Code Quality: Prioritize readability and maintainability; follow Django's coding style guide (PEP 8 compliance)
12+
- Naming Conventions: Use descriptive variable and function names; adhere to naming conventions (lowercase with underscores for functions and variables, uppercase with underscores for constants and PascalCase where each word starts with an uppercase without spaces, underscores or other separaters with all other letters lowercase for class names)
13+
- Modular Architecture: Structure your project in a modular way using Django apps to promote reusability and separation of concerns
14+
- Performance Awareness: Always consider scalability and performance implications in your design decisions
15+
16+
Project Structure
17+
18+
Application Structure
19+
app_name/
20+
├── tests/ # Unit test files
21+
├── migrations/ # Database migration files (if applicable)
22+
├── admin.py # Django admin configuration (if applicable)
23+
├── apps.py # App configuration (if applicable)
24+
├── models.py # Database models (if applicable)
25+
├── managers.py # Custom model managers (if applicable)
26+
├── signals.py # Django signals (if applicable)
27+
├── tasks.py # Celery tasks (if applicable)
28+
└── __init__.py # Package initialization
29+
30+
Configuration Structure
31+
config/
32+
├── settings/
33+
│ ├── base.py # Base settings
34+
│ ├── development.py # Development settings
35+
│ └── production.py # Production settings
36+
├── urls.py # Main URL configuration
37+
└── wsgi.py # WSGI configuration
38+
39+
Django/Python Development Guidelines
40+
41+
Views and API Design
42+
- Use Class-Based Views: Leverage Django's class-based views (CBVs) with DRF's APIViews
43+
- RESTful Design: Follow RESTful principles strictly with proper HTTP methods and status codes
44+
- Keep Views Light: Focus views on request handling; keep business logic in models, managers, and services
45+
- Consistent Response Format: Use unified response structure for both success and error cases
46+
47+
Models and Database
48+
- ORM First: Leverage Django's ORM for database interactions; avoid raw SQL queries unless necessary for performance
49+
- Business Logic in Models: Keep business logic in models and custom managers
50+
- Query Optimization: Use select_related and prefetch_related for related object fetching
51+
- Database Indexing: Implement proper database indexing for frequently queried fields
52+
- Transactions: Use transaction.atomic() for data consistency in critical operations
53+
54+
Serializers and Validation
55+
- DRF Serializers: Use Django REST Framework serializers for data validation and serialization
56+
- Custom Validation: Implement custom validators for complex business rules
57+
- Field-Level Validation: Use serializer field validation for input sanitization
58+
- Nested Serializers: Properly handle nested relationships with appropriate serializers
59+
60+
Authentication and Permissions
61+
- JWT Authentication: Use djangorestframework_simplejwt for JWT token-based authentication
62+
- Custom Permissions: Implement granular permission classes for different user roles
63+
- Security Best Practices: Implement proper CSRF protection, CORS configuration, and input sanitization
64+
65+
URL Configuration
66+
- URL Patterns: Use urlpatterns to define clean URL patterns with each path() mapping routes to views
67+
- Nested Routing: Use include() for modular URL organization
68+
- API Versioning: Implement proper API versioning strategy (URL-based versioning recommended)
69+
70+
Performance and Scalability
71+
72+
Query Optimization
73+
- N+1 Problem Prevention: Always use select_related and prefetch_related appropriately
74+
- Query Monitoring: Monitor query counts and execution time in development
75+
- Database Connection Pooling: Implement connection pooling for high-traffic applications
76+
77+
Response Optimization
78+
- Pagination: Standardize pagination across all list endpoints
79+
- Field Selection: Allow clients to specify required fields to reduce payload size
80+
- Compression: Enable response compression for large payloads
81+
82+
Error Handling and Logging
83+
84+
Unified Error Responses
85+
{
86+
"code": "error_code",
87+
"message": "Error description",
88+
"detail": {}
89+
}
90+
91+
Exception Handling
92+
- Custom Exception Handler: Implement global exception handling for consistent error responses
93+
- Django Signals: Use Django signals to decouple error handling and post-model activities
94+
- Proper HTTP Status Codes: Use appropriate HTTP status codes (400, 401, 403, 404, 422, 500, etc.)
95+
96+
Logging Strategy
97+
- Structured Logging: Implement structured logging for API monitoring and debugging
98+
- Request/Response Logging: Log API calls with execution time, user info, and response status
99+
- Performance Monitoring: Log slow queries and performance bottlenecks
100+

.cursor/rules/typescript-react.mdc

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
description:
3+
globs: aap_chatbot/src/*,ansible_ai_connect_admin_portal/src/*,ansible_ai_connect_chatbot/src/*
4+
alwaysApply: false
5+
---
6+
You are a Senior Front-End Developer and an Expert in ReactJS, JavaScript, TypeScript, HTML, CSS and modern UI/UX frameworks (e.g., Bootstrap, Patternfly). You are thoughtful, give nuanced answers, and are brilliant at reasoning. You carefully provide accurate, factual, thoughtful answers, and are a genius at reasoning.
7+
8+
- Follow the user’s requirements carefully & to the letter.
9+
- First think step-by-step - describe your plan for what to build in pseudocode, written out in great detail.
10+
- Confirm, then write code!
11+
- Always write correct, best practice, DRY principle (Dont Repeat Yourself), bug free, fully functional and working code also it should be aligned to listed rules down below at Code Implementation Guidelines .
12+
- Focus on easy and readability code, over being performant.
13+
- Fully implement all requested functionality.
14+
- Leave NO todo’s, placeholders or missing pieces.
15+
- Ensure code is complete! Verify thoroughly finalised.
16+
- Include all required imports, and ensure proper naming of key components.
17+
- Be concise Minimize any other prose.
18+
- If you think there might not be a correct answer, you say so.
19+
- If you do not know the answer, say so, instead of guessing.
20+
21+
### Coding Environment
22+
The user asks questions about the following coding languages:
23+
- ReactJS
24+
- Node.js
25+
- JavaScript
26+
- TypeScript
27+
- Bootstrap
28+
- Patternfly
29+
- axios
30+
- HTML
31+
- CSS
32+
33+
### Code Implementation Guidelines
34+
Follow these rules when you write code:
35+
- Use early returns whenever possible to make the code more readable.
36+
- Always use Patternfly classes for styling HTML elements; avoid using CSS or tags.
37+
- Use “class:” instead of the tertiary operator in class tags whenever possible.
38+
- Use descriptive variable and function/const names. Also, event functions should be named with a “handle” prefix, like “handleClick” for onClick and “handleKeyDown” for onKeyDown.
39+
- Implement accessibility features on elements. For example, a tag should have a tabindex=“0”, aria-label, on:click, and on:keydown, and similar attributes.
40+
- Use consts instead of functions, for example, “const toggle = () =>”. Also, define a type if possible.

.github/pull_request_template.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
Jira Issue: <https://issues.redhat.com/browse/AAP-NNNN>
33
<!-- This PR does not need a corresponding Jira item. -->
44

5+
<!-- Provide a model name or remove the lines if AI assistant wasn't used. -->
6+
Assisted-by: <name of code assistant if applicable>
7+
Generated by: <name of code assistant if applicable>
8+
59
## Description
610
<!-- Describe the changes introduced in the PR below, including any relevant motivation, context, and technical/design decisions -->
711

0 commit comments

Comments
 (0)