|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +OpenShock Common .NET library — shared utilities for the OpenShock ecosystem. Contains two main libraries: **Common** (utilities, validation, crypto, geolocation) and **DynamicLinq** (dynamic LINQ query builder for PostgreSQL/EF Core). |
| 8 | + |
| 9 | +## Build Commands |
| 10 | + |
| 11 | +```bash |
| 12 | +# Build |
| 13 | +dotnet build |
| 14 | + |
| 15 | +# Run all tests |
| 16 | +dotnet test |
| 17 | + |
| 18 | +# Run a single test project |
| 19 | +dotnet test Common.Tests/Common.Tests.csproj |
| 20 | +dotnet test DynamicLinq.Tests/DynamicLinq.Tests.csproj |
| 21 | + |
| 22 | +# CI-style build + test |
| 23 | +dotnet build --configuration Release && dotnet test --configuration Release --no-build |
| 24 | +``` |
| 25 | + |
| 26 | +No separate lint command — warnings are treated as errors in Debug configuration. |
| 27 | + |
| 28 | +## Solution Structure |
| 29 | + |
| 30 | +- **Common/** — Main utility library (NuGet package output) |
| 31 | +- **Common.Tests/** — Unit tests for Common |
| 32 | +- **DynamicLinq/** — Dynamic LINQ expression builder targeting PostgreSQL via EF Core |
| 33 | +- **DynamicLinq.Tests/** — Tests for DynamicLinq (uses Testcontainers with PostgreSQL) |
| 34 | + |
| 35 | +Solution file: `Common.slnx` |
| 36 | + |
| 37 | +## Build Configuration |
| 38 | + |
| 39 | +- .NET 9.0, latest C# language version |
| 40 | +- Nullable reference types enabled globally |
| 41 | +- Central package management via `Directory.Packages.props` |
| 42 | +- `Directory.Build.props` enables implicit usings, XML docs, and treats warnings as errors in Debug |
| 43 | +- GitVersion used in CI for semantic versioning (requires full git history) |
| 44 | + |
| 45 | +## Testing |
| 46 | + |
| 47 | +Uses **TUnit** (not xUnit/NUnit). Test methods use TUnit attributes and async patterns. DynamicLinq tests use **Testcontainers** for real PostgreSQL instances and **Bogus** for test data generation. |
| 48 | + |
| 49 | +## Architecture & Key Patterns |
| 50 | + |
| 51 | +### Common Library Namespaces |
| 52 | +- `Constants` — Domain hard limits (username/password lengths, shocker limits, durations, intensities) |
| 53 | +- `Utils` — `HashingUtils` (BCrypt + legacy PBKDF2, SHA-256 token hashing), `CryptoUtils` (cryptographic RNG), `MathUtils` (Haversine), `LatencyEmulator` (timing-safe operations with Gaussian noise) |
| 54 | +- `Geo` — `Alpha2CountryCode` (value-type struct wrapping ushort), `DistanceLookup` (pre-computed frozen dictionary of country-to-country distances) |
| 55 | +- `Validation` — `CharsetMatchers` for detecting emojis, zalgo text, zero-width spaces, control chars |
| 56 | +- `JsonSerialization` — Custom converters (Unix milliseconds, flag-guarded enum strings) |
| 57 | + |
| 58 | +### DynamicLinq Library |
| 59 | +- `QueryStringTokenizer` — Parses filter strings with quoted values and escape sequences |
| 60 | +- `DBExpressionBuilder` — Converts string filter queries into LINQ expressions (supports `eq`, `neq`, `lt`, `gt`, `lte`, `gte`, `ilike`; multiple filters joined with `and`) |
| 61 | +- `OrderByQueryBuilder` — Dynamic OrderBy/ThenBy from string input |
| 62 | +- Properties marked with `[IgnoreDataMember]` are excluded from query building for security |
| 63 | + |
| 64 | +### Performance Conventions |
| 65 | +- `stackalloc` / `Span<T>` for short-lived buffers |
| 66 | +- `ArrayPool<byte>` for temporary allocations |
| 67 | +- `FrozenDictionary` for immutable lookup tables |
| 68 | +- `CollectionsMarshal` for optimized dictionary operations |
| 69 | +- `GeneratedRegex` for compiled regex patterns |
| 70 | + |
| 71 | +### Security Conventions |
| 72 | +- Password hashing uses BCrypt with SHA-512; PBKDF2 is legacy-only |
| 73 | +- Token hashing uses SHA-256 |
| 74 | +- Timing-safe verification via `LatencyEmulator` sliding window statistics |
| 75 | +- Expression builder hides internal structure in error messages |
| 76 | + |
| 77 | +## License |
| 78 | + |
| 79 | +AGPL-3.0-or-later |
0 commit comments