@softspark/ai-toolkit 1.2.1 → 1.3.0
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.
- package/AGENTS.md +5 -29
- package/CHANGELOG.md +21 -0
- package/README.md +114 -17
- package/app/.claude-plugin/plugin.json +1 -1
- package/app/ARCHITECTURE.md +35 -19
- package/app/agents/ai-engineer.md +47 -5
- package/app/agents/fact-checker.md +1 -1
- package/app/agents/llm-ops-engineer.md +2 -2
- package/app/agents/{mcp-server-architect.md → mcp-specialist.md} +124 -18
- package/app/agents/mcp-testing-engineer.md +2 -2
- package/app/agents/nlp-engineer.md +1 -1
- package/app/agents/orchestrator.md +3 -4
- package/app/agents/project-planner.md +1 -1
- package/app/agents/technical-researcher.md +71 -21
- package/app/hooks/commit-quality.sh +53 -0
- package/app/hooks/governance-capture.sh +77 -0
- package/app/hooks/guard-config.sh +46 -0
- package/app/hooks/mcp-health.sh +53 -0
- package/app/hooks/pre-compact-save.sh +34 -0
- package/app/hooks/session-context.sh +60 -0
- package/app/hooks.json +60 -0
- package/app/mcp-templates/README.md +105 -0
- package/app/mcp-templates/brave-search.json +13 -0
- package/app/mcp-templates/cloudflare.json +14 -0
- package/app/mcp-templates/context7.json +10 -0
- package/app/mcp-templates/custom-template.json +13 -0
- package/app/mcp-templates/datadog.json +15 -0
- package/app/mcp-templates/docker.json +10 -0
- package/app/mcp-templates/fetch.json +10 -0
- package/app/mcp-templates/filesystem.json +10 -0
- package/app/mcp-templates/git.json +10 -0
- package/app/mcp-templates/github.json +13 -0
- package/app/mcp-templates/google-drive.json +15 -0
- package/app/mcp-templates/google-maps.json +13 -0
- package/app/mcp-templates/grafana.json +14 -0
- package/app/mcp-templates/linear.json +13 -0
- package/app/mcp-templates/memory.json +10 -0
- package/app/mcp-templates/notion.json +13 -0
- package/app/mcp-templates/postgres.json +10 -0
- package/app/mcp-templates/puppeteer.json +10 -0
- package/app/mcp-templates/redis.json +13 -0
- package/app/mcp-templates/sentry.json +14 -0
- package/app/mcp-templates/sequential-thinking.json +10 -0
- package/app/mcp-templates/slack.json +14 -0
- package/app/mcp-templates/sqlite.json +10 -0
- package/app/mcp-templates/supabase.json +14 -0
- package/app/mcp-templates/vercel.json +13 -0
- package/app/plugins/research-pack/README.md +1 -1
- package/app/plugins/research-pack/plugin.json +1 -1
- package/app/rules/claude-toolkit-rules.md +1 -1
- package/app/rules/common/coding-style.md +52 -0
- package/app/rules/common/git-workflow.md +45 -0
- package/app/rules/common/performance.md +49 -0
- package/app/rules/common/security.md +59 -0
- package/app/rules/common/testing.md +53 -0
- package/app/rules/cpp/coding-style.md +55 -0
- package/app/rules/cpp/frameworks.md +55 -0
- package/app/rules/cpp/patterns.md +57 -0
- package/app/rules/cpp/security.md +61 -0
- package/app/rules/cpp/testing.md +58 -0
- package/app/rules/csharp/coding-style.md +54 -0
- package/app/rules/csharp/frameworks.md +60 -0
- package/app/rules/csharp/patterns.md +61 -0
- package/app/rules/csharp/security.md +60 -0
- package/app/rules/csharp/testing.md +58 -0
- package/app/rules/dart/coding-style.md +61 -0
- package/app/rules/dart/frameworks.md +59 -0
- package/app/rules/dart/patterns.md +62 -0
- package/app/rules/dart/security.md +60 -0
- package/app/rules/dart/testing.md +60 -0
- package/app/rules/golang/coding-style.md +50 -0
- package/app/rules/golang/frameworks.md +56 -0
- package/app/rules/golang/patterns.md +52 -0
- package/app/rules/golang/security.md +61 -0
- package/app/rules/golang/testing.md +54 -0
- package/app/rules/java/coding-style.md +56 -0
- package/app/rules/java/frameworks.md +54 -0
- package/app/rules/java/patterns.md +59 -0
- package/app/rules/java/security.md +60 -0
- package/app/rules/java/testing.md +55 -0
- package/app/rules/kotlin/coding-style.md +56 -0
- package/app/rules/kotlin/frameworks.md +54 -0
- package/app/rules/kotlin/patterns.md +54 -0
- package/app/rules/kotlin/security.md +62 -0
- package/app/rules/kotlin/testing.md +56 -0
- package/app/rules/php/coding-style.md +53 -0
- package/app/rules/php/frameworks.md +57 -0
- package/app/rules/php/patterns.md +63 -0
- package/app/rules/php/security.md +61 -0
- package/app/rules/php/testing.md +60 -0
- package/app/rules/python/coding-style.md +52 -0
- package/app/rules/python/frameworks.md +53 -0
- package/app/rules/python/patterns.md +53 -0
- package/app/rules/python/security.md +58 -0
- package/app/rules/python/testing.md +52 -0
- package/app/rules/ruby/coding-style.md +56 -0
- package/app/rules/ruby/frameworks.md +56 -0
- package/app/rules/ruby/patterns.md +61 -0
- package/app/rules/ruby/security.md +61 -0
- package/app/rules/ruby/testing.md +63 -0
- package/app/rules/rust/coding-style.md +52 -0
- package/app/rules/rust/frameworks.md +59 -0
- package/app/rules/rust/patterns.md +58 -0
- package/app/rules/rust/security.md +64 -0
- package/app/rules/rust/testing.md +54 -0
- package/app/rules/swift/coding-style.md +55 -0
- package/app/rules/swift/frameworks.md +63 -0
- package/app/rules/swift/patterns.md +63 -0
- package/app/rules/swift/security.md +63 -0
- package/app/rules/swift/testing.md +60 -0
- package/app/rules/typescript/coding-style.md +51 -0
- package/app/rules/typescript/frameworks.md +51 -0
- package/app/rules/typescript/patterns.md +51 -0
- package/app/rules/typescript/security.md +55 -0
- package/app/rules/typescript/testing.md +52 -0
- package/app/skills/app-builder/SKILL.md +1 -1
- package/app/skills/brand-voice/SKILL.md +92 -0
- package/app/skills/council/SKILL.md +133 -0
- package/app/skills/introspect/SKILL.md +125 -0
- package/bin/ai-toolkit.js +103 -2
- package/kb/reference/agents-catalog.md +10 -13
- package/kb/reference/architecture-overview.md +29 -6
- package/kb/reference/commands-catalog.md +4 -4
- package/kb/reference/competitive-features-implementation.md +677 -0
- package/kb/reference/extension-api.md +175 -0
- package/kb/reference/hooks-catalog.md +90 -14
- package/kb/reference/language-rules.md +167 -0
- package/kb/reference/manifest-install.md +165 -0
- package/kb/reference/mcp-templates.md +110 -0
- package/kb/reference/skills-catalog.md +9 -6
- package/llms-full.txt +1511 -59
- package/llms.txt +8 -3
- package/package.json +2 -2
- package/scripts/inject_hook_cli.py +330 -0
- package/scripts/install.py +241 -7
- package/scripts/install_steps/ai_tools.py +63 -1
- package/scripts/install_steps/detect_language.py +50 -0
- package/scripts/install_steps/install_state.py +117 -0
- package/scripts/mcp_manager.py +206 -0
- package/app/agents/mcp-expert.md +0 -228
- package/app/agents/rag-engineer.md +0 -201
- package/app/agents/research-synthesizer.md +0 -138
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
---
|
|
2
|
+
language: common
|
|
3
|
+
category: coding-style
|
|
4
|
+
version: "1.0.0"
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Universal Coding Style
|
|
8
|
+
|
|
9
|
+
## Principles
|
|
10
|
+
- KISS: simplest solution that works. Clever code is a liability.
|
|
11
|
+
- DRY: extract when you repeat 3+ times, not before.
|
|
12
|
+
- YAGNI: do not build features "just in case."
|
|
13
|
+
- Prefer immutability: use `const`, `final`, `val`, `let` by default.
|
|
14
|
+
- Fail fast: validate inputs at boundaries, return early on errors.
|
|
15
|
+
|
|
16
|
+
## Naming
|
|
17
|
+
- Use descriptive names that reveal intent (`remainingRetries`, not `r`).
|
|
18
|
+
- Boolean variables/functions: prefix with `is`, `has`, `can`, `should`.
|
|
19
|
+
- Functions: verb + noun (`fetchUser`, `calculateTotal`, `validateInput`).
|
|
20
|
+
- Avoid abbreviations unless universally understood (`id`, `url`, `http`).
|
|
21
|
+
- Collections use plural nouns (`users`, `orderItems`).
|
|
22
|
+
|
|
23
|
+
## Functions
|
|
24
|
+
- Max 20-30 lines per function. If longer, extract.
|
|
25
|
+
- Max 3 parameters. Beyond that, use an options/config object.
|
|
26
|
+
- Single responsibility: one function does one thing.
|
|
27
|
+
- Pure functions preferred: same input, same output, no side effects.
|
|
28
|
+
- Avoid boolean parameters: use separate functions or enums.
|
|
29
|
+
|
|
30
|
+
## File Organization
|
|
31
|
+
- One primary concept per file (class, module, component).
|
|
32
|
+
- Group imports: stdlib, external, internal, relative.
|
|
33
|
+
- Constants at top, public API before private helpers.
|
|
34
|
+
- Keep files under 300 lines. Split when they grow.
|
|
35
|
+
|
|
36
|
+
## Comments
|
|
37
|
+
- Code should be self-documenting. Comment *why*, not *what*.
|
|
38
|
+
- Delete commented-out code. That is what version control is for.
|
|
39
|
+
- Use TODO/FIXME with ticket references: `// TODO(PROJ-123): migrate to v2`.
|
|
40
|
+
- Document public APIs with doc comments (JSDoc, docstrings, etc.).
|
|
41
|
+
|
|
42
|
+
## Formatting
|
|
43
|
+
- Use project formatter (Prettier, Black, gofmt, rustfmt). No manual formatting debates.
|
|
44
|
+
- Consistent indentation: follow project convention (spaces vs tabs, width).
|
|
45
|
+
- Max line length: 80-120 characters depending on language convention.
|
|
46
|
+
- Trailing commas in multi-line structures (where language supports).
|
|
47
|
+
|
|
48
|
+
## Anti-Patterns to Avoid
|
|
49
|
+
- God classes/modules with 500+ lines and multiple responsibilities.
|
|
50
|
+
- Deep nesting (>3 levels): use early returns and extract functions.
|
|
51
|
+
- Magic numbers/strings: use named constants.
|
|
52
|
+
- Mutable global state: use dependency injection instead.
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
---
|
|
2
|
+
language: common
|
|
3
|
+
category: git-workflow
|
|
4
|
+
version: "1.0.0"
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Git Workflow Rules
|
|
8
|
+
|
|
9
|
+
## Commit Messages
|
|
10
|
+
- Use conventional commits: `feat:`, `fix:`, `docs:`, `refactor:`, `test:`, `chore:`.
|
|
11
|
+
- First line: imperative mood, max 72 chars (`feat: add user registration endpoint`).
|
|
12
|
+
- Body (optional): explain *why*, not *what*. The diff shows what.
|
|
13
|
+
- Reference tickets: `fix: prevent duplicate orders (PROJ-456)`.
|
|
14
|
+
|
|
15
|
+
## Commit Practices
|
|
16
|
+
- Commit small, atomic changes. One commit = one logical change.
|
|
17
|
+
- Never commit: secrets, `.env` files, build artifacts, large binaries.
|
|
18
|
+
- Never commit broken code to `main`. Use feature branches.
|
|
19
|
+
- Squash fixup commits before merging to keep history clean.
|
|
20
|
+
|
|
21
|
+
## Branching
|
|
22
|
+
- `main` is always deployable. Protect it with required reviews and CI.
|
|
23
|
+
- Feature branches: `feat/user-registration`, `fix/order-total-calc`.
|
|
24
|
+
- Delete branches after merge. Stale branches are clutter.
|
|
25
|
+
- Rebase feature branches on main before PR to keep linear history.
|
|
26
|
+
|
|
27
|
+
## Pull Requests
|
|
28
|
+
- Keep PRs small: <400 lines changed. Split large features into stacked PRs.
|
|
29
|
+
- PR title follows conventional commit format.
|
|
30
|
+
- Include: summary, test plan, and screenshots/recordings for UI changes.
|
|
31
|
+
- Require at least one approval before merge.
|
|
32
|
+
|
|
33
|
+
## Code Review
|
|
34
|
+
- Review for: correctness, security, performance, readability.
|
|
35
|
+
- Approve with comments if nits only. Block for: bugs, security, missing tests.
|
|
36
|
+
- Respond to reviews within 24 hours. Do not let PRs rot.
|
|
37
|
+
|
|
38
|
+
## Tags and Releases
|
|
39
|
+
- Use semantic versioning: MAJOR.MINOR.PATCH.
|
|
40
|
+
- Tag releases: `git tag v1.2.3`. Automate changelog from commits.
|
|
41
|
+
|
|
42
|
+
## Recovery
|
|
43
|
+
- Use `git stash` for WIP, not unfinished commits.
|
|
44
|
+
- Prefer `git revert` over `git reset --hard` on shared branches.
|
|
45
|
+
- Never force-push to `main` or shared branches.
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
---
|
|
2
|
+
language: common
|
|
3
|
+
category: performance
|
|
4
|
+
version: "1.0.0"
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Universal Performance Rules
|
|
8
|
+
|
|
9
|
+
## Mindset
|
|
10
|
+
- Profile before optimizing. Measure, do not guess.
|
|
11
|
+
- Premature optimization is the root of all evil. Ship correct first, fast second.
|
|
12
|
+
- Set performance budgets and test against them in CI.
|
|
13
|
+
|
|
14
|
+
## Database
|
|
15
|
+
- Fix N+1 queries: use JOINs, eager loading, or batch fetching.
|
|
16
|
+
- Add indexes for columns used in WHERE, ORDER BY, and JOIN clauses.
|
|
17
|
+
- Use EXPLAIN/ANALYZE to verify query plans. Avoid full table scans.
|
|
18
|
+
- Paginate all list endpoints. Never return unbounded result sets.
|
|
19
|
+
- Use connection pooling. Never open a new connection per request.
|
|
20
|
+
|
|
21
|
+
## Caching
|
|
22
|
+
- Cache at the right layer: CDN > reverse proxy > application > database.
|
|
23
|
+
- Set explicit TTLs. Stale cache is worse than no cache.
|
|
24
|
+
- Cache immutable or slowly-changing data. Avoid caching user-specific mutable data.
|
|
25
|
+
- Use cache-aside pattern: check cache, fetch on miss, populate cache.
|
|
26
|
+
- Include cache invalidation strategy before adding any cache.
|
|
27
|
+
|
|
28
|
+
## I/O and Network
|
|
29
|
+
- Async/non-blocking for I/O-bound work. Thread pools for CPU-bound work.
|
|
30
|
+
- Batch operations where possible: bulk inserts, batch API calls.
|
|
31
|
+
- Set timeouts on all external calls: HTTP, database, message queues.
|
|
32
|
+
- Use streaming for large payloads instead of loading everything into memory.
|
|
33
|
+
|
|
34
|
+
## Memory
|
|
35
|
+
- Preallocate collections when size is known.
|
|
36
|
+
- Use streaming/iterators for large datasets instead of loading all into memory.
|
|
37
|
+
- Watch for memory leaks: unclosed connections, growing caches, event listener accumulation.
|
|
38
|
+
- Avoid unnecessary copies/clones of large data structures.
|
|
39
|
+
|
|
40
|
+
## API Performance
|
|
41
|
+
- Compress responses (gzip/brotli). Return only requested fields.
|
|
42
|
+
- Use HTTP/2 or HTTP/3 where supported.
|
|
43
|
+
- Implement request deduplication for identical concurrent requests.
|
|
44
|
+
- Return 202 Accepted for long-running operations, process async.
|
|
45
|
+
|
|
46
|
+
## Monitoring
|
|
47
|
+
- Track p50, p95, p99 latencies, not just averages.
|
|
48
|
+
- Alert on latency regressions, not just errors.
|
|
49
|
+
- Log slow queries (>100ms) and slow endpoints (>500ms).
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
---
|
|
2
|
+
language: common
|
|
3
|
+
category: security
|
|
4
|
+
version: "1.0.0"
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Universal Security Rules
|
|
8
|
+
|
|
9
|
+
## Input Validation
|
|
10
|
+
- Validate ALL input at API boundaries. Trust nothing from clients.
|
|
11
|
+
- Use allowlists over denylists: define what IS valid, reject everything else.
|
|
12
|
+
- Validate type, length, format, and range for every input field.
|
|
13
|
+
- Sanitize output for the target context (HTML, SQL, shell, URL).
|
|
14
|
+
|
|
15
|
+
## Authentication
|
|
16
|
+
- Hash passwords with bcrypt, scrypt, or argon2. Never MD5/SHA for passwords.
|
|
17
|
+
- Use constant-time comparison for tokens and secrets.
|
|
18
|
+
- Implement rate limiting on auth endpoints (login, register, password reset).
|
|
19
|
+
- Enforce MFA for admin and sensitive operations.
|
|
20
|
+
|
|
21
|
+
## Authorization
|
|
22
|
+
- Check permissions on every request, not just at the UI level.
|
|
23
|
+
- Use principle of least privilege: default deny, explicitly grant.
|
|
24
|
+
- Validate resource ownership: user can only access their own data.
|
|
25
|
+
- Never rely on client-side authorization checks.
|
|
26
|
+
|
|
27
|
+
## Secrets Management
|
|
28
|
+
- Never hardcode secrets in source code. Use environment variables or vaults.
|
|
29
|
+
- Rotate secrets regularly. Automate rotation where possible.
|
|
30
|
+
- Use different secrets per environment (dev/staging/prod).
|
|
31
|
+
- Add `.env` to `.gitignore`. Use `.env.example` as a template.
|
|
32
|
+
|
|
33
|
+
## SQL Injection Prevention
|
|
34
|
+
- Always use parameterized queries or ORM query builders.
|
|
35
|
+
- Never concatenate user input into SQL strings.
|
|
36
|
+
- Validate and cast types before using in queries.
|
|
37
|
+
|
|
38
|
+
## XSS Prevention
|
|
39
|
+
- Escape all dynamic content rendered in HTML.
|
|
40
|
+
- Use Content Security Policy (CSP) headers.
|
|
41
|
+
- Set `HttpOnly` and `Secure` flags on authentication cookies.
|
|
42
|
+
- Avoid `innerHTML`, `eval()`, and `dangerouslySetInnerHTML`.
|
|
43
|
+
|
|
44
|
+
## API Security
|
|
45
|
+
- Use HTTPS everywhere. No exceptions.
|
|
46
|
+
- Implement rate limiting and request throttling.
|
|
47
|
+
- Set CORS headers explicitly. Never use `*` in production.
|
|
48
|
+
- Return generic error messages to clients. Log details server-side.
|
|
49
|
+
- Use security headers: HSTS, X-Content-Type-Options, X-Frame-Options.
|
|
50
|
+
|
|
51
|
+
## Dependencies
|
|
52
|
+
- Audit dependencies regularly (`npm audit`, `pip-audit`, `cargo audit`).
|
|
53
|
+
- Pin dependency versions. Use lockfiles.
|
|
54
|
+
- Remove unused dependencies. Each dependency is an attack surface.
|
|
55
|
+
|
|
56
|
+
## Logging
|
|
57
|
+
- Never log passwords, tokens, credit cards, or PII.
|
|
58
|
+
- Log security events: failed logins, permission denials, input validation failures.
|
|
59
|
+
- Use structured logging with correlation IDs for traceability.
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
---
|
|
2
|
+
language: common
|
|
3
|
+
category: testing
|
|
4
|
+
version: "1.0.0"
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Universal Testing Rules
|
|
8
|
+
|
|
9
|
+
## Test Structure
|
|
10
|
+
- Use Arrange-Act-Assert (AAA) pattern in every test.
|
|
11
|
+
- One logical assertion per test. Multiple `assert` calls are fine if testing one behavior.
|
|
12
|
+
- Test names describe behavior: `test_returns_404_when_user_not_found`.
|
|
13
|
+
- Keep tests independent: no shared mutable state between tests.
|
|
14
|
+
|
|
15
|
+
## Test Organization
|
|
16
|
+
- Mirror source structure: `src/auth/login.ts` -> `tests/auth/login.test.ts`.
|
|
17
|
+
- Separate unit, integration, and e2e tests into distinct directories or markers.
|
|
18
|
+
- Shared fixtures go in `conftest.py`, `test-utils.ts`, or equivalent.
|
|
19
|
+
|
|
20
|
+
## What to Test
|
|
21
|
+
- Test behavior, not implementation. Tests should survive refactors.
|
|
22
|
+
- Cover: happy path, error cases, edge cases, boundary values.
|
|
23
|
+
- New code: 100% coverage. Overall project: >70%.
|
|
24
|
+
- Critical paths (auth, payments, data mutations): always tested.
|
|
25
|
+
|
|
26
|
+
## What NOT to Test
|
|
27
|
+
- Framework internals (ORM save, HTTP library send).
|
|
28
|
+
- Trivial getters/setters with no logic.
|
|
29
|
+
- Third-party library correctness.
|
|
30
|
+
- Private methods directly: test through public API.
|
|
31
|
+
|
|
32
|
+
## Mocking
|
|
33
|
+
- Mock at boundaries: HTTP clients, databases, file systems, clocks.
|
|
34
|
+
- Prefer fakes over mocks when logic is complex.
|
|
35
|
+
- Never mock the thing you are testing.
|
|
36
|
+
- Reset mocks between tests to prevent leakage.
|
|
37
|
+
|
|
38
|
+
## Test Quality
|
|
39
|
+
- Tests must be deterministic: no flaky tests allowed.
|
|
40
|
+
- Tests must be fast: unit tests <100ms each, test suite <60s.
|
|
41
|
+
- Avoid `sleep` in tests: use polling, events, or test clocks.
|
|
42
|
+
- Do not test implementation details (private methods, internal state).
|
|
43
|
+
|
|
44
|
+
## Coverage
|
|
45
|
+
- Measure coverage but do not chase 100%: focus on critical paths.
|
|
46
|
+
- Coverage gaps in error handling and edge cases are worse than gaps in happy paths.
|
|
47
|
+
- New PRs must not decrease overall coverage.
|
|
48
|
+
|
|
49
|
+
## Test Data
|
|
50
|
+
- Use factories/builders to create test data, not raw constructors.
|
|
51
|
+
- Keep test data minimal: only set fields relevant to the test.
|
|
52
|
+
- Do not share mutable test data across tests.
|
|
53
|
+
- Use realistic but not real data (no production data in tests).
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
---
|
|
2
|
+
language: cpp
|
|
3
|
+
category: coding-style
|
|
4
|
+
version: "1.0.0"
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# C++ Coding Style
|
|
8
|
+
|
|
9
|
+
## Naming
|
|
10
|
+
- PascalCase: classes, structs, enums, type aliases, concepts.
|
|
11
|
+
- camelCase or snake_case: functions, methods, variables (be consistent per project).
|
|
12
|
+
- UPPER_SNAKE: macros, compile-time constants.
|
|
13
|
+
- Prefix member variables with `m_` or suffix with `_` (pick one convention).
|
|
14
|
+
- Namespace names: lowercase, short (`namespace io`, `namespace util`).
|
|
15
|
+
|
|
16
|
+
## Modern C++ (17/20/23)
|
|
17
|
+
- Use `auto` for iterator types and complex template deductions.
|
|
18
|
+
- Use `std::optional<T>` instead of sentinel values or pointers for optional returns.
|
|
19
|
+
- Use `std::variant` over union types. Use `std::visit` for dispatch.
|
|
20
|
+
- Use `std::string_view` for non-owning string parameters.
|
|
21
|
+
- Use structured bindings: `auto [key, value] = *map.begin();`.
|
|
22
|
+
- Use `constexpr` for compile-time evaluation. Prefer over macros.
|
|
23
|
+
|
|
24
|
+
## Memory Management
|
|
25
|
+
- Use RAII exclusively. Every resource acquisition is an initialization.
|
|
26
|
+
- Use `std::unique_ptr` for exclusive ownership (default choice).
|
|
27
|
+
- Use `std::shared_ptr` only when ownership is genuinely shared.
|
|
28
|
+
- Never use raw `new`/`delete`. Use `std::make_unique` / `std::make_shared`.
|
|
29
|
+
- Use `std::span<T>` (C++20) for non-owning views over contiguous data.
|
|
30
|
+
|
|
31
|
+
## Functions
|
|
32
|
+
- Pass small types by value. Pass large types by `const&`.
|
|
33
|
+
- Use `[[nodiscard]]` on functions whose return value must not be ignored.
|
|
34
|
+
- Use `noexcept` on functions that do not throw (move constructors, destructors).
|
|
35
|
+
- Limit function parameters to 4. Use structs for configuration objects.
|
|
36
|
+
- Use trailing return types for complex template return deductions.
|
|
37
|
+
|
|
38
|
+
## Includes and Dependencies
|
|
39
|
+
- Use `#pragma once` or include guards. Prefer `#pragma once` for simplicity.
|
|
40
|
+
- Order: corresponding header, C++ stdlib, third-party, project headers.
|
|
41
|
+
- Forward-declare in headers when possible to reduce compile times.
|
|
42
|
+
- Minimize header dependencies. Use the Pimpl idiom for ABI stability.
|
|
43
|
+
|
|
44
|
+
## Avoid
|
|
45
|
+
- Raw pointers for ownership. Use smart pointers.
|
|
46
|
+
- C-style casts. Use `static_cast`, `dynamic_cast`, `const_cast`.
|
|
47
|
+
- Macros for constants or functions. Use `constexpr` and templates.
|
|
48
|
+
- `using namespace std;` in headers. Acceptable in .cpp files with caution.
|
|
49
|
+
- `std::endl` -- use `'\n'` (endl flushes the buffer unnecessarily).
|
|
50
|
+
|
|
51
|
+
## Formatting
|
|
52
|
+
- Use clang-format with a committed `.clang-format` file.
|
|
53
|
+
- Use clang-tidy for static analysis and automated modernization.
|
|
54
|
+
- Max line length: 100-120 characters.
|
|
55
|
+
- Braces: use Allman or K&R consistently per project.
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
---
|
|
2
|
+
language: cpp
|
|
3
|
+
category: frameworks
|
|
4
|
+
version: "1.0.0"
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# C++ Frameworks
|
|
8
|
+
|
|
9
|
+
## CMake
|
|
10
|
+
- Use modern CMake (3.14+): target-based, not directory-based.
|
|
11
|
+
- Use `target_link_libraries` with `PUBLIC`/`PRIVATE`/`INTERFACE` visibility.
|
|
12
|
+
- Use `FetchContent` for dependency management. Avoid manual submodule vendoring.
|
|
13
|
+
- Set `CMAKE_CXX_STANDARD 20` (or 23) at the project level.
|
|
14
|
+
- Use `target_compile_options` for per-target flags, not global `add_compile_options`.
|
|
15
|
+
- Export targets with `install(TARGETS ... EXPORT ...)` for library consumers.
|
|
16
|
+
|
|
17
|
+
## Boost
|
|
18
|
+
- Use Boost.Asio for async networking and I/O.
|
|
19
|
+
- Use `boost::beast` for HTTP/WebSocket built on Asio.
|
|
20
|
+
- Use `boost::json` or `nlohmann/json` for JSON parsing.
|
|
21
|
+
- Prefer C++ stdlib equivalents when available (e.g., `std::optional` over `boost::optional`).
|
|
22
|
+
- Link only the Boost libraries you actually use. Many are header-only.
|
|
23
|
+
|
|
24
|
+
## Qt
|
|
25
|
+
- Use signals and slots for event-driven communication.
|
|
26
|
+
- Use `QObject` parent-child ownership for automatic memory management.
|
|
27
|
+
- Use `QML` for declarative UI. Keep business logic in C++ backend.
|
|
28
|
+
- Use `QThread` with worker objects (moveToThread), not subclassing QThread.
|
|
29
|
+
- Use smart pointers for non-QObject resources. QObject children are auto-deleted.
|
|
30
|
+
|
|
31
|
+
## gRPC
|
|
32
|
+
- Define services in `.proto` files. Generate C++ stubs with `protoc`.
|
|
33
|
+
- Use async server with `CompletionQueue` for high-throughput services.
|
|
34
|
+
- Use `grpc::ClientContext` for per-call deadlines and metadata.
|
|
35
|
+
- Use interceptors for logging, auth, and metrics.
|
|
36
|
+
- Set deadlines on every RPC call to prevent hanging.
|
|
37
|
+
|
|
38
|
+
## Networking (Asio)
|
|
39
|
+
- Use `io_context` as the event loop. Run from one or more threads.
|
|
40
|
+
- Use `co_await` (C++20 coroutines) with Asio for clean async code.
|
|
41
|
+
- Use `strand` for serializing access to shared state across handlers.
|
|
42
|
+
- Use `steady_timer` for timeouts and periodic tasks.
|
|
43
|
+
- Handle errors via `error_code` parameter, not exceptions, in async callbacks.
|
|
44
|
+
|
|
45
|
+
## Database
|
|
46
|
+
- Use `libpq` (PostgreSQL) or `SOCI` for database access.
|
|
47
|
+
- Use prepared statements exclusively. Never concatenate SQL strings.
|
|
48
|
+
- Use connection pooling for multi-threaded server applications.
|
|
49
|
+
- Use `SQLite` via `sqlite3` C API with RAII wrappers for embedded use cases.
|
|
50
|
+
|
|
51
|
+
## Package Management
|
|
52
|
+
- Use `vcpkg` or `Conan 2` for dependency management.
|
|
53
|
+
- Pin dependency versions in `vcpkg.json` or `conanfile.py`.
|
|
54
|
+
- Use CI caching for build artifacts and dependency downloads.
|
|
55
|
+
- Prefer pre-built binary packages for CI speed.
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
---
|
|
2
|
+
language: cpp
|
|
3
|
+
category: patterns
|
|
4
|
+
version: "1.0.0"
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# C++ Patterns
|
|
8
|
+
|
|
9
|
+
## Error Handling
|
|
10
|
+
- Use exceptions for truly exceptional conditions. Use return types for expected failures.
|
|
11
|
+
- Use `std::expected<T, E>` (C++23) or `Result<T, E>` pattern for recoverable errors.
|
|
12
|
+
- Use `std::error_code` / `std::error_category` for system-level errors.
|
|
13
|
+
- Use `noexcept` on functions that must not throw (destructors, move operations).
|
|
14
|
+
- Catch by `const&`. Never catch by value (slicing) or pointer.
|
|
15
|
+
|
|
16
|
+
## RAII Patterns
|
|
17
|
+
- Wrap every resource (memory, file, lock, socket) in an RAII type.
|
|
18
|
+
- Use `std::lock_guard` or `std::scoped_lock` for mutex management.
|
|
19
|
+
- Use `std::unique_lock` when deferred locking or condition variables are needed.
|
|
20
|
+
- Use `std::fstream` (auto-closes) instead of `fopen`/`fclose`.
|
|
21
|
+
- Write custom RAII wrappers for C library resources (file descriptors, handles).
|
|
22
|
+
|
|
23
|
+
## Smart Pointer Patterns
|
|
24
|
+
- `unique_ptr`: default ownership model. Transfer with `std::move`.
|
|
25
|
+
- `shared_ptr`: use only for genuinely shared ownership graphs.
|
|
26
|
+
- `weak_ptr`: break cycles in `shared_ptr` graphs. Use `lock()` to access.
|
|
27
|
+
- Factory functions should return `unique_ptr`. Let callers upgrade to `shared_ptr`.
|
|
28
|
+
- Never pass smart pointers by reference. Pass `T&` or `T*` to non-owning consumers.
|
|
29
|
+
|
|
30
|
+
## Concurrency
|
|
31
|
+
- Use `std::thread` with `std::jthread` (C++20) for auto-joining threads.
|
|
32
|
+
- Use `std::mutex` + `std::scoped_lock` for shared data protection.
|
|
33
|
+
- Use `std::atomic<T>` for lock-free single-variable synchronization.
|
|
34
|
+
- Use `std::condition_variable` for producer-consumer patterns.
|
|
35
|
+
- Use `std::async` / `std::future` for simple parallel computation.
|
|
36
|
+
- Use `std::counting_semaphore` (C++20) for resource pool limiting.
|
|
37
|
+
|
|
38
|
+
## Template Patterns
|
|
39
|
+
- Use CRTP for compile-time polymorphism (static dispatch).
|
|
40
|
+
- Use `concepts` (C++20) to constrain template parameters with clear error messages.
|
|
41
|
+
- Use `if constexpr` for compile-time branching in templates.
|
|
42
|
+
- Use variadic templates and fold expressions for parameter packs.
|
|
43
|
+
- Prefer `constexpr` functions over template metaprogramming when possible.
|
|
44
|
+
|
|
45
|
+
## Design Patterns
|
|
46
|
+
- Use `std::variant` + `std::visit` for type-safe visitor pattern.
|
|
47
|
+
- Use `std::function` for type-erased callbacks and strategy pattern.
|
|
48
|
+
- Use Pimpl idiom (`unique_ptr<Impl>`) for ABI stability and compilation firewall.
|
|
49
|
+
- Use Builder pattern with method chaining for complex object construction.
|
|
50
|
+
- Use `std::move` semantics in move constructors for efficient resource transfer.
|
|
51
|
+
|
|
52
|
+
## Anti-Patterns
|
|
53
|
+
- Raw `new`/`delete`: use smart pointers and containers.
|
|
54
|
+
- Returning raw pointers from factory functions: return `unique_ptr`.
|
|
55
|
+
- `const_cast` to remove constness: redesign the interface.
|
|
56
|
+
- Deep inheritance hierarchies: prefer composition and templates.
|
|
57
|
+
- Premature optimization over readability: profile first, optimize second.
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
---
|
|
2
|
+
language: cpp
|
|
3
|
+
category: security
|
|
4
|
+
version: "1.0.0"
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# C++ Security
|
|
8
|
+
|
|
9
|
+
## Buffer Overflow Prevention
|
|
10
|
+
- Use `std::string`, `std::vector`, `std::array` instead of C arrays and `char[]`.
|
|
11
|
+
- Use `std::span` (C++20) for safe, bounds-checked views over contiguous data.
|
|
12
|
+
- Never use `strcpy`, `strcat`, `sprintf`. Use `std::string` operations or `snprintf`.
|
|
13
|
+
- Enable `-D_FORTIFY_SOURCE=2` in release builds for runtime buffer checks.
|
|
14
|
+
- Use `at()` for bounds-checked container access in untrusted input paths.
|
|
15
|
+
|
|
16
|
+
## Memory Safety
|
|
17
|
+
- Use smart pointers exclusively. Zero raw `new`/`delete` in application code.
|
|
18
|
+
- Enable AddressSanitizer (`-fsanitize=address`) in development and CI builds.
|
|
19
|
+
- Enable UndefinedBehaviorSanitizer (`-fsanitize=undefined`) in test builds.
|
|
20
|
+
- Use `-fstack-protector-strong` for stack buffer overflow detection.
|
|
21
|
+
- Use Valgrind for memory leak detection in integration tests.
|
|
22
|
+
|
|
23
|
+
## Integer Safety
|
|
24
|
+
- Check for overflow before arithmetic on untrusted integers.
|
|
25
|
+
- Use `std::numeric_limits<T>::max()` for boundary checks.
|
|
26
|
+
- Use unsigned types only for bit manipulation. Prefer signed for arithmetic.
|
|
27
|
+
- Use `static_cast` explicitly. Never rely on implicit narrowing conversions.
|
|
28
|
+
- Enable `-Wconversion` and `-Wsign-conversion` warnings.
|
|
29
|
+
|
|
30
|
+
## Input Validation
|
|
31
|
+
- Validate all external input: file data, network packets, command-line arguments.
|
|
32
|
+
- Use `std::stoi` / `std::stol` with exception handling for string-to-number conversion.
|
|
33
|
+
- Set maximum sizes for dynamic allocations based on untrusted input.
|
|
34
|
+
- Validate file paths to prevent directory traversal (`../`).
|
|
35
|
+
- Use allowlist validation for format specifiers and command strings.
|
|
36
|
+
|
|
37
|
+
## Secure Coding
|
|
38
|
+
- Use `std::fill` or `explicit_bzero()` to zero sensitive memory before deallocation.
|
|
39
|
+
- Use constant-time comparison for secrets (avoid timing side-channels).
|
|
40
|
+
- Use `mlock()` to prevent sensitive memory from being swapped to disk.
|
|
41
|
+
- Compile with `-fPIE -pie` for position-independent executables (ASLR).
|
|
42
|
+
- Enable `-Werror` in CI to prevent warnings from becoming vulnerabilities.
|
|
43
|
+
|
|
44
|
+
## Dependencies
|
|
45
|
+
- Audit third-party C libraries for known CVEs before inclusion.
|
|
46
|
+
- Use `vcpkg` or `Conan` with pinned versions for reproducible builds.
|
|
47
|
+
- Prefer well-maintained libraries with active security response teams.
|
|
48
|
+
- Minimize C library usage. Prefer C++ standard library equivalents.
|
|
49
|
+
|
|
50
|
+
## Concurrency Safety
|
|
51
|
+
- Use `std::mutex` with `std::scoped_lock` for all shared data access.
|
|
52
|
+
- Use `std::atomic` for lock-free single-variable operations.
|
|
53
|
+
- Enable ThreadSanitizer (`-fsanitize=thread`) in test builds for race detection.
|
|
54
|
+
- Avoid `volatile` for synchronization. It does not provide atomicity or ordering.
|
|
55
|
+
- Use RAII lock guards. Never manually `lock()`/`unlock()`.
|
|
56
|
+
|
|
57
|
+
## Compiler Hardening
|
|
58
|
+
- Enable all warnings: `-Wall -Wextra -Wpedantic`.
|
|
59
|
+
- Use `-D_GLIBCXX_ASSERTIONS` for debug iterator and container checks.
|
|
60
|
+
- Use `-fno-exceptions` only when exception safety is not required.
|
|
61
|
+
- Link with `-Wl,-z,relro,-z,now` for full RELRO (GOT hardening).
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
---
|
|
2
|
+
language: cpp
|
|
3
|
+
category: testing
|
|
4
|
+
version: "1.0.0"
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# C++ Testing
|
|
8
|
+
|
|
9
|
+
## Framework
|
|
10
|
+
- Use GoogleTest (gtest) as the primary test framework.
|
|
11
|
+
- Use GoogleMock (gmock) for mocking interfaces and virtual classes.
|
|
12
|
+
- Use Catch2 as a lightweight alternative (header-only, BDD-style).
|
|
13
|
+
- Use CTest for test discovery and execution via CMake.
|
|
14
|
+
|
|
15
|
+
## File Naming
|
|
16
|
+
- Test files: `foo_test.cpp` or `test_foo.cpp` in a dedicated `tests/` directory.
|
|
17
|
+
- Mirror source directory structure in test directory.
|
|
18
|
+
- One test file per source file or logical component.
|
|
19
|
+
- Use `CMakeLists.txt` with `add_test()` to register tests.
|
|
20
|
+
|
|
21
|
+
## Structure (GoogleTest)
|
|
22
|
+
- Use `TEST(SuiteName, TestName)` for simple tests.
|
|
23
|
+
- Use `TEST_F(FixtureName, TestName)` for tests sharing setup/teardown.
|
|
24
|
+
- Use `SetUp()` / `TearDown()` in fixtures for per-test initialization.
|
|
25
|
+
- Keep tests focused: one logical assertion per test case.
|
|
26
|
+
|
|
27
|
+
## Assertions
|
|
28
|
+
- Use `EXPECT_*` (non-fatal) by default. Use `ASSERT_*` only when continuation is meaningless.
|
|
29
|
+
- `EXPECT_EQ`, `EXPECT_NE`, `EXPECT_LT`, `EXPECT_GT` for comparisons.
|
|
30
|
+
- `EXPECT_TRUE`, `EXPECT_FALSE` for boolean conditions.
|
|
31
|
+
- `EXPECT_THROW(expr, ExceptionType)` for exception testing.
|
|
32
|
+
- `EXPECT_THAT(value, matcher)` with gmock matchers for complex assertions.
|
|
33
|
+
|
|
34
|
+
## Parameterized Tests
|
|
35
|
+
- Use `INSTANTIATE_TEST_SUITE_P` with `testing::Values(...)` for value-parameterized tests.
|
|
36
|
+
- Use `testing::Combine()` for multi-dimensional parameterization.
|
|
37
|
+
- Use `TYPED_TEST_SUITE` for type-parameterized tests across template types.
|
|
38
|
+
- Prefer parameterized tests over copy-pasting similar test bodies.
|
|
39
|
+
|
|
40
|
+
## Mocking (GoogleMock)
|
|
41
|
+
- Define mock classes: `MOCK_METHOD(ReturnType, MethodName, (Args), (Qualifiers))`.
|
|
42
|
+
- Use `EXPECT_CALL(mock, Method(matchers)).WillOnce(Return(value))`.
|
|
43
|
+
- Use `NiceMock<T>` to suppress uninteresting call warnings.
|
|
44
|
+
- Use `StrictMock<T>` to fail on any unexpected call.
|
|
45
|
+
- Use dependency injection (constructor) to pass mock objects.
|
|
46
|
+
|
|
47
|
+
## Build Integration
|
|
48
|
+
- Use `FetchContent` or `find_package` to integrate gtest in CMake.
|
|
49
|
+
- Enable `BUILD_TESTING` option to conditionally include tests.
|
|
50
|
+
- Use `ctest --output-on-failure` for CI runs.
|
|
51
|
+
- Use sanitizers in test builds: `-fsanitize=address,undefined`.
|
|
52
|
+
|
|
53
|
+
## Best Practices
|
|
54
|
+
- Test edge cases: empty input, max values, null pointers, boundary conditions.
|
|
55
|
+
- Use RAII test fixtures for resource cleanup (no manual teardown).
|
|
56
|
+
- Avoid testing private methods directly. Test through public API.
|
|
57
|
+
- Use `valgrind` or ASan/UBSan in CI to detect memory errors.
|
|
58
|
+
- Keep tests fast: mock I/O and external dependencies.
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
---
|
|
2
|
+
language: csharp
|
|
3
|
+
category: coding-style
|
|
4
|
+
version: "1.0.0"
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# C# Coding Style
|
|
8
|
+
|
|
9
|
+
## Naming
|
|
10
|
+
- PascalCase: classes, structs, enums, interfaces, methods, properties, events.
|
|
11
|
+
- camelCase: local variables, parameters, private fields.
|
|
12
|
+
- Prefix interfaces with `I`: `IUserRepository`, `IDisposable`.
|
|
13
|
+
- Prefix private fields with `_`: `private readonly ILogger _logger;`.
|
|
14
|
+
- UPPER_SNAKE: not conventional in C#. Use PascalCase for constants.
|
|
15
|
+
|
|
16
|
+
## Nullable Reference Types
|
|
17
|
+
- Enable `<Nullable>enable</Nullable>` in all projects.
|
|
18
|
+
- Use `string?` only when null is semantically meaningful.
|
|
19
|
+
- Use `!` (null-forgiving) operator sparingly -- only when compiler cannot infer.
|
|
20
|
+
- Use `??` (null-coalescing) and `?.` (null-conditional) for safe navigation.
|
|
21
|
+
- Use `required` modifier (C# 11) on properties that must be set at initialization.
|
|
22
|
+
|
|
23
|
+
## Records and Types
|
|
24
|
+
- Use `record` for immutable value objects and DTOs.
|
|
25
|
+
- Use `record struct` for small, stack-allocated value types.
|
|
26
|
+
- Use `init` properties for immutable-after-construction objects.
|
|
27
|
+
- Use `with` expressions for non-destructive mutation of records.
|
|
28
|
+
- Use primary constructors (C# 12) for concise class definitions.
|
|
29
|
+
|
|
30
|
+
## Pattern Matching
|
|
31
|
+
- Use `is` pattern for type checks: `if (obj is string s)`.
|
|
32
|
+
- Use `switch` expressions for exhaustive matching over enums/types.
|
|
33
|
+
- Use property patterns: `user is { Age: > 18, Role: "admin" }`.
|
|
34
|
+
- Use relational patterns: `size is > 0 and < 100`.
|
|
35
|
+
- Use list patterns (C# 11): `numbers is [1, 2, .., var last]`.
|
|
36
|
+
|
|
37
|
+
## Async/Await
|
|
38
|
+
- Suffix async methods with `Async`: `GetUserAsync()`.
|
|
39
|
+
- Return `Task<T>` or `ValueTask<T>`, never `void` (except event handlers).
|
|
40
|
+
- Use `await` with `ConfigureAwait(false)` in library code.
|
|
41
|
+
- Use `CancellationToken` parameters in all async public APIs.
|
|
42
|
+
- Prefer `ValueTask<T>` when synchronous completion is common.
|
|
43
|
+
|
|
44
|
+
## File Organization
|
|
45
|
+
- One type per file. File name matches type name.
|
|
46
|
+
- Use file-scoped namespaces (C# 10): `namespace MyApp.Services;`.
|
|
47
|
+
- Order members: fields, constructors, properties, public methods, private methods.
|
|
48
|
+
- Use `global using` directives in a single `GlobalUsings.cs` file.
|
|
49
|
+
|
|
50
|
+
## Formatting
|
|
51
|
+
- Use `.editorconfig` with C# style rules committed to the repository.
|
|
52
|
+
- Use `dotnet format` for automated formatting.
|
|
53
|
+
- Use Roslyn analyzers for compile-time style enforcement.
|
|
54
|
+
- Max line length: 120 characters.
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
---
|
|
2
|
+
language: csharp
|
|
3
|
+
category: frameworks
|
|
4
|
+
version: "1.0.0"
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# C# Frameworks
|
|
8
|
+
|
|
9
|
+
## ASP.NET Core
|
|
10
|
+
- Use minimal APIs for simple endpoints. Use controllers for complex APIs.
|
|
11
|
+
- Use `[ApiController]` attribute for automatic model validation and error responses.
|
|
12
|
+
- Use `Results.Ok()`, `Results.NotFound()` for typed HTTP results.
|
|
13
|
+
- Use endpoint filters / middleware for cross-cutting concerns.
|
|
14
|
+
- Use `IHostedService` / `BackgroundService` for long-running background tasks.
|
|
15
|
+
- Map routes with `app.MapGet()`, `app.MapPost()` for minimal API style.
|
|
16
|
+
|
|
17
|
+
## Entity Framework Core
|
|
18
|
+
- Use code-first migrations: `dotnet ef migrations add`, `dotnet ef database update`.
|
|
19
|
+
- Use `DbContext` with scoped lifetime (one per request).
|
|
20
|
+
- Use `AsNoTracking()` for read-only queries. Use `AsTracking()` only for updates.
|
|
21
|
+
- Use `Include()` / `ThenInclude()` for eager loading related entities.
|
|
22
|
+
- Use shadow properties for audit fields (`CreatedAt`, `UpdatedAt`).
|
|
23
|
+
- Use `HasQueryFilter()` for soft-delete and multi-tenancy global filters.
|
|
24
|
+
|
|
25
|
+
## Blazor
|
|
26
|
+
- Use Blazor Server for internal tools. Use Blazor WASM for public-facing SPAs.
|
|
27
|
+
- Use `@inject` for dependency injection in components.
|
|
28
|
+
- Use `EventCallback<T>` for parent-child component communication.
|
|
29
|
+
- Use `CascadingValue` for deeply shared state (theme, auth).
|
|
30
|
+
- Use `StateContainer` pattern with events for cross-component state management.
|
|
31
|
+
|
|
32
|
+
## SignalR
|
|
33
|
+
- Use strongly-typed hubs: `Hub<IClientMethods>` for compile-time safety.
|
|
34
|
+
- Use `HubContext<T>` for sending messages from outside hubs.
|
|
35
|
+
- Use groups for targeted broadcasting: `Groups.AddToGroupAsync()`.
|
|
36
|
+
- Configure automatic reconnection on the client side.
|
|
37
|
+
|
|
38
|
+
## MassTransit / Messaging
|
|
39
|
+
- Use MassTransit for message bus abstraction over RabbitMQ/Azure Service Bus.
|
|
40
|
+
- Define messages as `record` types for immutability.
|
|
41
|
+
- Use consumers (`IConsumer<T>`) for message handling.
|
|
42
|
+
- Use sagas for long-running, multi-step workflows with state.
|
|
43
|
+
- Use retry and circuit breaker policies for transient failures.
|
|
44
|
+
|
|
45
|
+
## Logging
|
|
46
|
+
- Use `ILogger<T>` via DI. Never instantiate loggers manually.
|
|
47
|
+
- Use structured logging: `_logger.LogInformation("User {UserId} logged in", userId)`.
|
|
48
|
+
- Use Serilog with sinks for structured, centralized logging.
|
|
49
|
+
- Use log scopes for request correlation: `using (_logger.BeginScope(...))`.
|
|
50
|
+
|
|
51
|
+
## Configuration
|
|
52
|
+
- Use `appsettings.json` + environment-specific overrides + environment variables.
|
|
53
|
+
- Bind configuration sections to strongly-typed classes with `IOptions<T>`.
|
|
54
|
+
- Use `IOptionsMonitor<T>` for configuration that changes at runtime.
|
|
55
|
+
- Validate configuration at startup with `ValidateDataAnnotations()`.
|
|
56
|
+
|
|
57
|
+
## Health Checks
|
|
58
|
+
- Use `app.MapHealthChecks("/health")` for liveness probes.
|
|
59
|
+
- Register custom health checks for database, cache, and external service dependencies.
|
|
60
|
+
- Use `AspNetCore.HealthChecks.*` NuGet packages for common checks.
|