# AI APP — 编码规范 ## 后端 C# (.NET 10) - 主构造函数:`public class Service(DbContext db) { }` - 静态方法必须标记 `static` - 集合表达式:`[]` / `[..src]` - `TryGetValue` 替代 `GetValueOrDefault` - 空 catch 必须指定异常类型 - DTO 用 `record` 类型 - `private static readonly` 缓存可复用对象 - 本地函数优于 `Func` 赋值 - file-scoped namespace、global using、target-typed `new()`、`Nullable=enable` - Minimal API 扩展方法模式:`public static class XxxEndpoints { }` - AI 请求用 `HttpClient` 直连,不引入第三方 AI SDK - **文件命名 snake_case**:`auth_service.cs`、`auth_endpoints.cs` ## 前端 Flutter (Dart) -前端用sqlite存储信息,不用shared_preferences - 用 Riverpod 管理所有状态和页面跳转 ## 运行与测试 - 测试时自行启动后端,通过浏览器 DevTools 发送请求验证 - Flutter 用 `flutter run` 连模拟器/真机