How sjzar/chatlog works
Overall Architecture – Identify Major Components
• Command-Line Interface (CLI) & Terminal UI: Represented by the main executable (cmd/chatlog) and internal/ui packages (footer, help, infobar, menu, style). This component handles local user interactions.
• HTTP API Service: The HTTP-related code inside internal/chatlog/http exposes REST endpoints (e.g., /api/v1/chatlog, /api/v1/contact, /api/v1/chatroom, /api/v1/session) plus the SSE endpoint for MCP.
• Core Business Logic: Organized under internal/chatlog with supporting packages such as configuration (internal/chatlog/conf), context management (internal/chatlog/ctx), and application-level orchestration (app.go, manager.go).
• Decryption & Key Extraction Modules: Encapsulated under internal/wechat (decrypt, key, process, manager) that handle reading memory/processes and decrypting WeChat data.
• Data Access Layer: Constructed through internal/wechatdb (datasource and repository subpackages) which manage reading from the local WeChat database files.
• MCP Protocol Integration: Under internal/mcp and parts of internal/chatlog/mcp that expose JSON-RPC, SSE, and other communication methods needed for interoperability with AI tools.
• Utility and Support Libraries: Provided in pkg (appver, config, util such as for compression/zstd, dat2img, OS helpers) to support common operations across modules.
• Error Handling: Modules under internal/errors coordinate robust error propagation across HTTP, OS, wechat, and MCP handling.
Mapping Relationships and Interactions
• The main executable (cmd/chatlog) initiates the system and routes to either CLI/Terminal UI or HTTP API interface.
• For CLI/Terminal UI commands (e.g., key extraction, decrypt) the user input flows into the core logic modules which then call on the decryption (internal/wechat/decrypt and key) and database reading (internal/wechatdb) services.
• When running as an HTTP service, incoming REST API requests are handled by the HTTP routing component (internal/chatlog/http/route.go) that delegates to service modules; these then query the local database repositories or perform decryption if needed.
• The MCP component listens for SSE connections (via internal/mcp/sse.go) and coordinates responses using JSON-RPC style endpoints.
• Utility packages in pkg support these functionalities by providing versioning, standardized configuration loading, and OS-specific operations.
Architectural Patterns and Principles
• Modular/Layered Design: Separate packages (cmd for CLI, internal for business logic, pkg for utilities) clearly separate concerns.
• Clear Separation between Presentation (UI/HTTP), Business Logic, and Data Access.
• Use of configuration and context packages for dependency injection and service orchestration.
• Consistent error handling across different components using centralized internal/errors modules.