Commit ·
c119a7b
1
Parent(s): 5a20d88
chore: update BEST-PRACTICES
Browse files- BEST-PRACTICES.md +2 -1
- docs/project-conventions.md +46 -46
BEST-PRACTICES.md
CHANGED
|
@@ -9,7 +9,8 @@ alwaysApply: true
|
|
| 9 |
- Run `make lint` and `make test` after every change. `lint` in particular can be run very frequently.
|
| 10 |
- When user starts a prompt with `QQ:` or `Question:`, just answer the question or prompt without producing code.
|
| 11 |
- Prefer small testable steps, after each step give a summary to the user and summarize the next step
|
| 12 |
-
-
|
|
|
|
| 13 |
|
| 14 |
## Prohibited actions
|
| 15 |
|
|
|
|
| 9 |
- Run `make lint` and `make test` after every change. `lint` in particular can be run very frequently.
|
| 10 |
- When user starts a prompt with `QQ:` or `Question:`, just answer the question or prompt without producing code.
|
| 11 |
- Prefer small testable steps, after each step give a summary to the user and summarize the next step
|
| 12 |
+
- Maintain strict separation of concerns: Business logic MUST reside in the core library (`src/folio/`), not in interface layers (`src/focli/`). Interface layers should only handle user interaction, command parsing, and result presentation.
|
| 13 |
+
- Use `.docs/` for temporary documentation such as project plans or logs
|
| 14 |
|
| 15 |
## Prohibited actions
|
| 16 |
|
docs/project-conventions.md
CHANGED
|
@@ -11,9 +11,30 @@ This document outlines the key coding conventions for the Folio project. These c
|
|
| 11 |
|
| 12 |
- **Web Framework**: Dash (Python)
|
| 13 |
- **Data Processing**: Pandas, NumPy
|
| 14 |
-
- **Financial Data**: Yahoo Finance API
|
| 15 |
- **Testing**: Pytest
|
| 16 |
-
- **Linting**:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
## Core Conventions
|
| 19 |
|
|
@@ -329,50 +350,29 @@ def is_valid_ticker(ticker: str) -> bool:
|
|
| 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 |
-
2. **Follow the Boy Scout Rule**: Leave the code cleaner than you found it.
|
| 358 |
-
|
| 359 |
-
3. **Don't Repeat Yourself (DRY)**: Extract repeated code into reusable functions.
|
| 360 |
-
|
| 361 |
-
4. **You Aren't Gonna Need It (YAGNI)**: Don't add functionality until it's necessary.
|
| 362 |
-
|
| 363 |
-
5. **Optimize After Measuring**: Profile code to identify actual bottlenecks before optimizing.
|
| 364 |
-
|
| 365 |
-
6. **Use Consistent Formatting**: Use Black, Flake8, and isort to maintain consistent code style.
|
| 366 |
-
|
| 367 |
-
7. **Imports at Top**: Always place all imports at the top of the file.
|
| 368 |
-
|
| 369 |
-
8. **No Unused Code**: Remove commented-out code and unused imports/variables.
|
| 370 |
-
|
| 371 |
-
9. **Configuration Over Hardcoding**: Use configuration files for values that might change.
|
| 372 |
-
|
| 373 |
-
10. **Log with Context**: Include relevant information in log messages.
|
| 374 |
-
|
| 375 |
-
11. **Make Small, Focused Changes**: Don't modify unrelated code when implementing a feature or fixing a bug.
|
| 376 |
|
| 377 |
## Benefits of Following These Conventions
|
| 378 |
|
|
|
|
| 11 |
|
| 12 |
- **Web Framework**: Dash (Python)
|
| 13 |
- **Data Processing**: Pandas, NumPy
|
| 14 |
+
- **Financial Data**: Yahoo Finance API
|
| 15 |
- **Testing**: Pytest
|
| 16 |
+
- **Linting**: Ruff
|
| 17 |
+
|
| 18 |
+
## Principles
|
| 19 |
+
1. **Follow the Boy Scout Rule**: Leave the code cleaner than you found it.
|
| 20 |
+
|
| 21 |
+
2. **Don't Repeat Yourself (DRY)**: Extract repeated code into reusable functions.
|
| 22 |
+
|
| 23 |
+
3. **You Aren't Gonna Need It (YAGNI)**: Don't add functionality until it's necessary.
|
| 24 |
+
|
| 25 |
+
4. **Optimize After Measuring**: Profile code to identify actual bottlenecks before optimizing.
|
| 26 |
+
|
| 27 |
+
5. **Use Consistent Formatting**: Use Black, Flake8, and isort to maintain consistent code style.
|
| 28 |
+
|
| 29 |
+
6. **Imports at Top**: Always place all imports at the top of the file.
|
| 30 |
+
|
| 31 |
+
7. **No Unused Code**: Remove commented-out code and unused imports/variables.
|
| 32 |
+
|
| 33 |
+
8. **Configuration Over Hardcoding**: Use configuration files for values that might change.
|
| 34 |
+
|
| 35 |
+
9. **Log with Context**: Include relevant information in log messages.
|
| 36 |
+
|
| 37 |
+
10. **Make Small, Focused Changes**: Don't modify unrelated code when implementing a feature or fixing a bug.
|
| 38 |
|
| 39 |
## Core Conventions
|
| 40 |
|
|
|
|
| 350 |
)
|
| 351 |
```
|
| 352 |
|
| 353 |
+
### 11. Maintain Separation of Concerns
|
| 354 |
+
Business logic MUST reside in the core library (`src/folio/`), not in interface layers (`src/focli/`).
|
| 355 |
+
```python
|
| 356 |
+
# ❌ Bad: Business logic in CLI layer
|
| 357 |
+
# src/focli/utils.py
|
| 358 |
+
def calculate_position_value_with_price_change(position_group, price_change):
|
| 359 |
+
# Business logic for calculating position value
|
| 360 |
+
return new_value
|
| 361 |
+
|
| 362 |
+
# ✅ Good: Business logic in core library
|
| 363 |
+
# src/folio/portfolio_value.py
|
| 364 |
+
def calculate_position_value_with_price_change(position_group, price_change):
|
| 365 |
+
# Business logic for calculating position value
|
| 366 |
+
return new_value
|
| 367 |
+
|
| 368 |
+
# src/focli/commands/position.py
|
| 369 |
+
def handle_position_command(args):
|
| 370 |
+
# Only handle user interaction and call core library
|
| 371 |
+
result = portfolio_value.calculate_position_value_with_price_change(
|
| 372 |
+
position_group, price_change
|
| 373 |
+
)
|
| 374 |
+
# Format and display result
|
| 375 |
+
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 376 |
|
| 377 |
## Benefits of Following These Conventions
|
| 378 |
|