Controtto
Okay, I understand. I will do my best to translate English text into Chinese, and when presented with Go code, I will attempt to analyze it from the perspective of Domain-Driven Design (DDD) and Clean Architecture principles. **Specifically, when analyzing Go code, I will look for:** * **DDD Aspects:** * **Ubiquitous Language:** Is the code using terminology that aligns with the business domain? Are the names of variables, functions, and types meaningful to domain experts? * **Entities:** Are there well-defined entities with identity and behavior? * **Value Objects:** Are there immutable value objects representing domain concepts? * **Aggregates:** Are aggregates used to enforce consistency and manage transactions? Are aggregate roots clearly defined? * **Domain Services:** Are domain services used to encapsulate complex domain logic that doesn't naturally belong to an entity or value object? * **Repositories:** Are repositories used to abstract data access and persistence? * **Domain Events:** Are domain events used to decouple different parts of the system and react to changes in the domain? * **Bounded Contexts:** (If applicable) Is the code organized into bounded contexts with clear boundaries and responsibilities? * **Clean Architecture Aspects:** * **Dependency Inversion Principle (DIP):** Are high-level modules not dependent on low-level modules? Are abstractions used to decouple layers? * **Interface Segregation Principle (ISP):** Are interfaces small and focused, avoiding unnecessary dependencies? * **Single Responsibility Principle (SRP):** Do classes/modules have a single, well-defined responsibility? * **Layers:** Are there distinct layers (e.g., presentation, application, domain, infrastructure)? * **Use Cases/Interactors:** Are use cases clearly defined and implemented as interactors? * **Entities (Domain Layer):** Is the core business logic (entities and domain rules) independent of frameworks and infrastructure? * **Frameworks & Drivers (Outer Layer):** Are frameworks and infrastructure concerns kept separate from the core business logic? * **Testability:** Is the code easily testable, with clear separation of concerns? **My analysis will be strict and critical.** I will point out potential violations of these principles and suggest improvements. I will also consider the trade-offs involved in applying these principles, as strict adherence is not always practical or beneficial. **Important Considerations:** * **Context is Key:** My analysis will be limited by the information you provide. The more context you give me about the domain, the requirements, and the overall architecture, the better I can assess the code. * **Subjectivity:** DDD and Clean Architecture are not rigid rules, but rather guidelines. There is room for interpretation and different approaches. My analysis will reflect my understanding of these principles, which may differ from yours. * **Code Completeness:** I can only analyze the code you provide. I cannot infer the entire system architecture or domain model from a small snippet. **Example:** If you provide me with the following Go code: ```go package main import "fmt" type User struct { ID int Name string Email string } func SaveUser(db *sql.DB, user User) error { _, err := db.Exec("INSERT INTO users (name, email) VALUES (?, ?)", user.Name, user.Email) return err } func main() { // ... database connection ... user := User{Name: "John Doe", Email: "john.doe@example.com"} err := SaveUser(db, user) if err != nil { fmt.Println("Error saving user:", err) } } ``` I might respond with something like: "This code has several potential issues from a DDD and Clean Architecture perspective: * **Lack of Domain Layer:** The `User` struct is directly coupled to the database. It should be part of a dedicated domain layer, separate from infrastructure concerns. * **Anemic Domain Model:** The `User` struct only contains data and lacks behavior. Consider adding methods to the `User` struct that encapsulate domain logic related to users. * **Direct Database Access:** The `SaveUser` function directly interacts with the database. This violates the Dependency Inversion Principle. A repository interface should be used to abstract data access. * **Missing Repository:** There is no repository interface or implementation to handle user persistence. * **No Use Case:** The `main` function directly calls the `SaveUser` function. This should be encapsulated in a use case or interactor. To improve this code, consider: 1. Creating a `domain` package with the `User` entity and any related value objects. 2. Defining a `UserRepository` interface in the `domain` package. 3. Implementing the `UserRepository` interface in an `infrastructure` package, using a database connection. 4. Creating an `application` package with a `CreateUser` use case that uses the `UserRepository` to persist the user. This would result in a more decoupled, testable, and maintainable codebase that adheres to DDD and Clean Architecture principles." **Now, please provide me with the text you want me to translate or the Go code you want me to analyze.**
README
📊 Controtto
一个自托管的、使用 Go、HTMX 构建且没有 JavaScript 的损益追踪器。Controtto 跟踪您的交易,将其保存在 sqlite 文件中,并返回各种计算结果,包括:
- 平均购买价格
- 当前资产价值
- 交易历史
- 导入/导出交易(参见 示例)
- 利润与损失
为了获取资产的价格,Controtto 主要依赖于 4 个 API(参见代码)。
- Binance - 公共 API,无需 token。
- BingX - 公共 API,无需 token。
- Alpha Vantage - 股票,免费但速率限制较短。(获取 token 并设置
CONTROTTO_AVANTAGE_TOKEN) - Tiingo - 股票、加密货币和外汇。(创建 帐户/token 并设置
CONTROTTO_TIINGO_TOKEN)
演示
您也可以在 demo.contre.io 上查看演示,数据库每小时重置一次。

所有配置都在 .env 文件中设置,并作为环境变量传递。可以使用变量 CONTROTTO_PORT 和 CONTROTTO_DB_PATH。
# 安装依赖
go mod tidy
# 设置 .env
mv .env.example .env
# 导入环境变量
. <(cat .env | grep -v -e '^$' | grep -v "#" | awk '{}')
构建并运行
go run ./cmd/main.go # go build ./cmd/main.go 仅用于构建
开发环境
go install github.com/cosmtrek/air@latest # 下载 air
air -c air.toml
并访问 localhost:3000
使用 Podman 运行
容器镜像 在 Docker 的公共注册表上可用。
如果您想使用 Docker,只需将 podman 替换为 docker。
mkdir data
podman container run --rm -p 8000:8000 -v $(pwd)/data:/data contre95/controtto
运行测试
go test -cover ./...
# 预期结果
# ? controtto/cmd [no test files]
# ? controtto/src/app/managing [no test files]
# ? controtto/src/domain/pnl [no test files]
# ? controtto/src/gateways/markets [no test files]
# ? controtto/src/gateways/sqlite [no test files]
# ? controtto/src/presenters [no test files]
# ok controtto/src/app/querying 0.003s coverage: 40.7% of statements
TODO
- 更多测试
- 日志记录和指标的包装器也会很好。
- 添加帐户以跟踪总净值。
- 删除所有 CSS 并使用自定义
style.css+ Tailwind CDN。
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。