-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path.cursorrules
More file actions
395 lines (312 loc) · 11.9 KB
/
Copy path.cursorrules
File metadata and controls
395 lines (312 loc) · 11.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
# FormicaX Cursor Rules
# MANDATORY Development Ethos and Implementation Standards
## 🎯 **PROJECT ETHOS ENFORCEMENT**
When implementing ANY feature or component in FormicaX, **ALWAYS** follow these MANDATORY rules:
### **1. CODE COVERAGE FIRST (MANDATORY)**
```bash
# BEFORE implementing any feature:
cargo tarpaulin --out Html --output-dir coverage
# AFTER implementing:
cargo tarpaulin --out Html --output-dir coverage --fail-under 95
```
**Implementation Checklist:**
- [ ] Write unit tests BEFORE implementing the feature
- [ ] Add integration tests for public APIs
- [ ] Include property-based tests with `proptest`
- [ ] Test all error conditions and edge cases
- [ ] Verify coverage > 95% for new code
- [ ] Add benchmarks for performance-critical code
### **2. STOP AND REVIEW (MANDATORY)**
After implementing any significant feature:
**Review Checklist:**
- [ ] **Code Coverage**: Run `cargo tarpaulin` and verify > 95%
- [ ] **No Duplication**: Check for code duplication using `cargo clippy`
- [ ] **Modularity**: Ensure clean separation of concerns
- [ ] **Readability**: Code is self-documenting with clear naming
- [ ] **Performance**: Run benchmarks and verify no regressions
- [ ] **Documentation**: Update examples and documentation
- [ ] **Formatting**: Run `cargo fmt` and ensure all code is formatted
- [ ] **Linting**: Run `cargo clippy --all-targets --all-features -- -D warnings` and ensure zero warnings
### **3. LATEST DEPENDENCIES (MANDATORY)**
```bash
# Check for outdated dependencies
cargo outdated
# Update to latest versions
cargo update
# Verify compatibility
cargo check --all-features
cargo test --all-features
```
**Dependency Rules:**
- [ ] Use latest stable versions from crates.io
- [ ] No pinned versions unless absolutely necessary
- [ ] Regular dependency updates (weekly)
- [ ] Security audit: `cargo audit`
- [ ] Verify no breaking changes after updates
### **4. CLEAN, MODULAR CODE (MANDATORY)**
**Code Quality Standards:**
```rust
// ✅ GOOD: Clean, modular, testable
pub trait ClusteringAlgorithm {
type Config;
fn fit(&mut self, data: &[OHLCV]) -> Result<ClusterResult, FormicaXError>;
}
// ✅ GOOD: Builder pattern for configuration
pub struct KMeansConfig {
k: usize,
variant: KMeansVariant,
parallel: bool,
}
impl KMeansConfig {
pub fn builder() -> KMeansConfigBuilder {
KMeansConfigBuilder::default()
}
}
// ❌ BAD: Duplicated code, hard to test
fn kmeans_algorithm(data: &[OHLCV], k: usize) -> Vec<usize> {
// 100 lines of inline algorithm
}
// ❌ BAD: Outdated dependencies
[dependencies]
serde = "1.0.100" # Pinned old version
```
**Modularity Rules:**
- [ ] **Single Responsibility**: Each module has one clear purpose
- [ ] **Dependency Inversion**: Depend on abstractions, not concretions
- [ ] **Interface Segregation**: Small, focused traits
- [ ] **Open/Closed**: Open for extension, closed for modification
- [ ] **DRY Principle**: No code duplication
- [ ] **SOLID Principles**: Follow all SOLID design principles
## 🔄 **IMPLEMENTATION WORKFLOW**
### **Phase 1: Planning**
1. **Define Requirements**: Clear, testable requirements
2. **Design Interface**: Define traits and public APIs
3. **Plan Tests**: Write test specifications first
4. **Check Dependencies**: Ensure latest versions
### **Phase 2: Implementation**
1. **Write Tests First**: TDD approach
2. **Implement Feature**: Following clean code principles
3. **Run Coverage**: Verify > 95% coverage
4. **Run `cargo fmt` and `cargo clippy`**: Ensure code is formatted and warning-free
5. **Code Review**: Self-review against checklist
### **Phase 3: Validation**
1. **Run All Tests**: `cargo test --all-features`
2. **Check Coverage**: `cargo tarpaulin`
3. **Run Benchmarks**: `cargo bench`
4. **Update Dependencies**: `cargo update`
5. **Security Audit**: `cargo audit`
### **Phase 4: Documentation**
1. **Update Examples**: Add working examples using `examples/csv/`
2. **Update Documentation**: Keep docs in sync with code
3. **Performance Notes**: Document performance characteristics
4. **Migration Guide**: If breaking changes
## 🛠️ **DEVELOPMENT TOOLS CONFIGURATION**
### **Pre-commit Hooks**
```bash
#!/bin/bash
# .git/hooks/pre-commit
echo "Running pre-commit checks..."
# Check code coverage
cargo tarpaulin --out Html --output-dir coverage --fail-under 95
# Check for outdated dependencies
cargo outdated --exit-code 1
# Run security audit
cargo audit
# Check code quality
cargo clippy --all-targets --all-features -- -D warnings
# Run tests
cargo test --all-features
echo "All checks passed!"
```
### **CI/CD Pipeline**
```yaml
# .github/workflows/ci.yml
name: CI
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
# Check for outdated dependencies
- name: Check outdated dependencies
run: cargo outdated --exit-code 1
# Security audit
- name: Security audit
run: cargo audit
# Run tests with coverage
- name: Test with coverage
run: cargo tarpaulin --out Html --output-dir coverage --fail-under 95
# Upload coverage report
- name: Upload coverage
uses: codecov/codecov-action@v3
with:
file: coverage/tarpaulin-report.html
```
## 📊 **QUALITY METRICS DASHBOARD**
**Required Metrics for Every Implementation:**
| Metric | Target | Tool | Frequency |
|--------|--------|------|-----------|
| **Code Coverage** | > 95% | `cargo tarpaulin` | Every commit |
| **Dependency Freshness** | Latest stable | `cargo outdated` | Weekly |
| **Security Issues** | 0 | `cargo audit` | Every commit |
| **Code Quality** | 0 warnings | `cargo clippy` | Every commit |
| **Performance** | No regression | `cargo bench` | Every PR |
| **Documentation** | 100% API coverage | Manual review | Every PR |
## 🚨 **FAILURE MODES AND RECOVERY**
### **Coverage Below 95%**
```bash
# Identify uncovered code
cargo tarpaulin --out Html --output-dir coverage
# Add missing tests
# Re-run until > 95%
cargo tarpaulin --out Html --output-dir coverage --fail-under 95
```
### **Outdated Dependencies**
```bash
# Update dependencies
cargo update
# Check for breaking changes
cargo check --all-features
cargo test --all-features
# If breaking changes, update code or pin version temporarily
```
### **Code Duplication**
```bash
# Use clippy to detect duplication
cargo clippy --all-targets --all-features
# Refactor duplicated code into shared modules
# Update tests to cover shared code
```
## 📝 **IMPLEMENTATION TEMPLATES**
### **New Clustering Algorithm**
```rust
// 1. Define trait implementation
impl ClusteringAlgorithm for NewAlgorithm {
type Config = NewAlgorithmConfig;
fn new(config: Self::Config) -> Self {
// Implementation
}
fn fit(&mut self, data: &[OHLCV]) -> Result<ClusterResult, FormicaXError> {
// Implementation with comprehensive error handling
}
}
// 2. Write tests FIRST
#[cfg(test)]
mod tests {
use super::*;
use proptest::prelude::*;
#[test]
fn test_new_algorithm_basic() {
// Test implementation
}
proptest! {
#[test]
fn test_new_algorithm_properties(data in generate_test_data()) {
// Property-based tests
}
}
}
// 3. Add benchmarks
#[cfg(test)]
mod benches {
use criterion::{black_box, criterion_group, criterion_main, Criterion};
fn bench_new_algorithm(c: &mut Criterion) {
c.bench_function("new_algorithm", |b| {
b.iter(|| {
// Benchmark implementation
})
});
}
}
```
### **New Module Structure**
```
src/clustering/new_algorithm/
├── mod.rs # Public API and trait implementations
├── algorithm.rs # Core algorithm implementation
├── config.rs # Configuration and builder pattern
├── parallel.rs # Parallel implementation (if applicable)
└── tests/ # Comprehensive test suite
├── mod.rs
├── unit_tests.rs
├── integration_tests.rs
└── property_tests.rs
```
## 🎯 **TRADING-SPECIFIC RULES**
### **Trading Implementation Requirements**
- [ ] **95% minimum coverage** for all trading algorithms
- [ ] **100% coverage** for real-time processing paths
- [ ] **Sub-100 microsecond latency** for trading operations
- [ ] **Zero unsafe code** in trading paths
- [ ] **Daily security audits** for trading components
- [ ] **Real-time testing** with market condition simulation
### **Trading Quality Gates**
| Gate | Command | Target | Critical for Trading |
|------|---------|--------|---------------------|
| **Coverage** | `cargo tarpaulin` | > 95% | ✅ CRITICAL |
| **Latency** | `cargo bench` | < 100μs | ✅ CRITICAL |
| **Memory Safety** | `cargo clippy` | 0 unsafe | ✅ CRITICAL |
| **Security** | `cargo audit` | 0 issues | ✅ CRITICAL |
| **Real-time** | Custom tests | No blocking | ✅ CRITICAL |
| **Market Data** | Integration tests | Valid OHLCV | ✅ CRITICAL |
## 🔧 **PERFORMANCE OPTIMIZATION RULES**
### **SIMD and Vectorization**
- [ ] Use AVX2/AVX-512 instructions for 8x-16x speedup
- [ ] Ensure data structures are aligned to cache lines
- [ ] Use FMA operations for improved precision
- [ ] Implement portable SIMD with fallbacks
### **Memory Management**
- [ ] Use zero-copy operations where possible
- [ ] Implement memory pooling for repeated operations
- [ ] Use Structure-of-Arrays (SoA) layout for cache locality
- [ ] Stream large datasets without loading into memory
### **Parallel Processing**
- [ ] Use work-stealing algorithms for load balancing
- [ ] Implement lock-free data structures
- [ ] Optimize for NUMA-aware systems
- [ ] Use parallel iterators for zero-cost abstractions
## 📚 **DOCUMENTATION REQUIREMENTS**
### **Code Documentation**
- [ ] All public APIs must have comprehensive documentation
- [ ] Include working examples using `examples/csv/` data
- [ ] Document performance characteristics and trade-offs
- [ ] Provide migration guides for breaking changes
### **Example Requirements**
- [ ] All examples must use CSV files from `examples/csv/` folder
- [ ] Every public API must have at least one working example
- [ ] Include error handling examples
- [ ] Show performance considerations where applicable
## 🚀 **DEPLOYMENT AND RELEASE RULES**
### **Release Checklist**
- [ ] All tests pass: `cargo test --all-features`
- [ ] Coverage > 95%: `cargo tarpaulin --fail-under 95`
- [ ] No security issues: `cargo audit`
- [ ] Dependencies up to date: `cargo outdated`
- [ ] Performance benchmarks pass: `cargo bench`
- [ ] Documentation complete and accurate
- [ ] Examples tested and working
### **Version Management**
- [ ] Follow semantic versioning (SemVer)
- [ ] Update CHANGELOG.md for all changes
- [ ] Tag releases with descriptive messages
- [ ] Maintain backward compatibility when possible
## ⚠️ **MANDATORY COMPLIANCE**
**These rules are MANDATORY and non-negotiable. Every implementation must follow this ethos to maintain the high quality standards of FormicaX.**
### **Enforcement**
- [ ] Pre-commit hooks must pass all quality gates
- [ ] CI/CD pipeline enforces all rules automatically
- [ ] Code reviews must verify compliance
- [ ] No exceptions without documented justification
### **Consequences of Non-Compliance**
- [ ] Pull requests will be rejected
- [ ] Builds will fail in CI/CD
- [ ] Code will not be merged to main branch
- [ ] Releases will be blocked
**Remember: Quality is not negotiable. Every line of code must follow these standards to maintain FormicaX's reputation for excellence.**
### **MANDATORY Cleanliness and Code Quality Enforcement**
- [ ] Run `cargo fmt` to ensure code is properly formatted before every commit and before merging.
- [ ] Run `cargo clippy --all-targets --all-features -- -D warnings` to ensure zero warnings and enforce code cleanliness before every commit and before merging.