# CLAUDE.md This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. ## Repository Overview This is the **live-forum** server repository, a live streaming forum platform with three main components: 1. **webapi/** - Main API service (.NET 8 Web API) for the forum application 2. **crawler/** - Python-based data crawlers for ByteDance live streaming platforms 3. **admin/** - Backend admin panel (ZrAdminNetCore framework, .NET 8 + Vue) ## Build and Run Commands ### WebAPI (Forum API) ```bash # Navigate to solution directory cd webapi/LiveForum # Restore dependencies dotnet restore LiveForum.sln # Build dotnet build LiveForum.sln # Run in development mode dotnet run --project LiveForum.WebApi # Run in release mode dotnet run --project LiveForum.WebApi --configuration Release ``` The API runs on `http://*:8080` by default (configured in appsettings.json). ### Crawler (Python) ```bash # Commerce crawler cd crawler/commerce pip install -r requirements.txt playwright install chromium # Login (opens browser for manual login) python main.py login # Fetch data python main.py fetch-daren python main.py daemon # Daemon mode for scheduled crawling # Entertainment crawler cd crawler/entertainment pip install -r requirements.txt playwright install chromium python main.py login python main.py crawl python main.py daemon # Daemon mode ``` ### Admin Panel ```bash # Backend (.NET) cd admin/ZrAdminNetCore dotnet restore ZRAdmin.sln dotnet run --project ZR.Admin.WebApi # Frontend (Vue) cd admin/ZrAdminNetCore/ZR.Vue npm install npm run dev ``` ## Architecture ### WebAPI Solution Structure ``` webapi/LiveForum/ ├── LiveForum.WebApi # Controllers, Background Services, Program.cs entry point ├── LiveForum.Service # Business logic implementation ├── LiveForum.IService # Service interfaces ├── LiveForum.Model # DTOs, Entities, Enums ├── LiveForum.Code # Infrastructure (JWT, Redis, Middleware, Utilities) ├── LiveForum.Repository # Data access layer └── LiveForum # Core shared library ``` ### Key Technologies - **ORM**: FreeSql (SQL Server) - **DI Container**: Autofac (with property injection for services) - **Caching**: Redis (StackExchange.Redis) - **Background Jobs**: Hangfire (SQL Server storage) - **Configuration**: AgileConfig (remote config center with hot reload) - **Logging**: Serilog (console + file sinks) - **Authentication**: JWT tokens - **WeChat**: SKIT.FlurlHttpClient.Wechat.Api - **File Storage**: Tencent COS ### Service Registration Pattern Services in `LiveForum.Service` are automatically registered via Autofac assembly scanning: ```csharp autofac.RegisterAssemblyTypes(Assembly.Load("LiveForum.Service")) .AsImplementedInterfaces() .PropertiesAutowired() .InstancePerLifetimeScope(); ``` Exceptions: `SensitiveWordService` and `WechatApiClientManager` are registered as singletons in Program.cs. ### Background Services - `LikeMessageConsumer` - Processes like notifications from Redis - `CommentReplyMessageConsumer` - Processes comment reply notifications - `CustomMessageConsumer` - Custom message processing - `LikeBatchSyncService` - Batch syncs likes to database - `ViewBatchSyncService` - Batch syncs view counts - `FlowerBatchSyncService` - Batch syncs flower (gift) counts ### Scheduled Jobs (Hangfire) - `streamer-flower-reset` - Resets streamer flower counts monthly (1st day, 3 AM) ## Configuration Configuration sources (priority order): 1. AgileConfig (remote, supports hot reload) 2. appsettings.json Key configuration sections: - `ConnectionStrings:LiveForumConnection` - SQL Server connection - `Redis:Configuration` - Redis connection string - `JwtTokenConfig` - JWT secret, issuer, audience, expiration - `Wechat` - WeChat Mini Program AppId/AppSecret - `TENCENT_COS` - Tencent COS storage settings - `SensitiveWord` - Sensitive word filtering configuration ## API Endpoints Access Swagger UI at: `http://localhost:8080/swagger` Main controller areas: - `/api/Auth` - Authentication (WeChat login) - `/api/Posts` - Posts CRUD - `/api/PostComments` - Comments - `/api/UsersInfo` - User profiles - `/api/UserFollow` - Follow relationships - `/api/Streamers` - Streamer data - `/api/Flowers` - Gift/flower system - `/api/Messages` - Notifications - `/api/Search` - Search functionality ## Crawler Structure Both crawlers share similar architecture: ``` crawler/{commerce,entertainment}/ ├── config/settings.py # Configuration ├── core/ │ ├── cookie_manager.py # Cookie persistence │ ├── browser_login.py # Playwright browser automation │ └── api_client.py # API calls with cookies ├── services/ │ └── crawler_service.py # Data fetching logic ├── data/ # Output JSON files ├── logs/ # Log files └── main.py # CLI entry point ``` Cookies are saved to `data/cookies.json` after manual browser login.