How dennisblokland/nihongobot works
Main Components
• Telegram Bot User Interface: Represents the end-user interacting through the Telegram client.
• App Host & Server Layers: “NihongoBot.AppHost” (and possibly “NihongoBot.Server”) which include the Program.cs entry points. These provide the runtime environments, configuration (e.g., appsettings.json), container orchestration outputs (see aspirate-output/docker-compose.yaml), and overall startup orchestration.
• Application Layer: Found in “NihongoBot.Application” composed of various handlers (e.g., StartCommandHandler, StopCommandHandler, ResetStreakCommandHandler), services (BotService, CommandDispatcher, CallbackDispatcher, HangfireSchedulerService, HiraganaService, JlptVocabApiService), and workers such as “TelegramBotWorker”. This layer manages business logic, command processing, and scheduling.
• Domain Layer: Contained in “NihongoBot.Domain”, includes aggregates like Kana, Question, and User, along with domain enums, base types, and interfaces for domain entities and repositories. This represents the core business logic and rules.
• Infrastructure Layer: “NihongoBot.Infrastructure” is responsible for dependency injection and the implementations of infrastructural concerns such as repository instantiation and service collection extensions.
• Persistence Layer: “NihongoBot.Persistence” covers the database context with EF Core configurations, migrations, and the actual data access logic (using AppDbContext, configuration classes, and JSON-based assets like hiragana.json).
• Shared Components: “NihongoBot.Shared” includes common options and configuration classes for connection strings and application options.
• Tests: Unit tests are organized in the Tests folder verifying the different handlers and services.
Relationships & Interactions
• The Telegram client sends commands/messages to the bot. These are received and processed through the Hosting layer (AppHost/Server) which instantiates the TelegramBotWorker.
• The worker office delegates commands and callbacks to corresponding handlers in the Application layer.
• The Application layer uses services like BotService and dispatcher components to orchestrate command execution. In many cases, these services also interact with domain logic and utilize domain models or aggregates.
• Domain layer – the heart of the business logic – is used by the Repository implementations in the Infrastructure layer via domain interfaces (IDomainEntity, IRepository, etc.).
• Infrastructure and Persistence interact where the Infrastructure layer hosts the concrete implementations of the repository interfaces (e.g., KanaRepository, QuestionRepository, UserRepository), which then access the underlying database via EF Core. Database migrations and configurations are managed here.
• Optional external services (like Hangfire for scheduling) are integrated via the Application’s HangfireSchedulerService.
Architectural Patterns and Design Principles
• Domain Driven Design: Clear separation of Domain, Application, Infrastructure, and Persistence layers.
• Dependency Injection: Seen in Infrastructure with ServiceCollectionExtensions to register dependencies.
• Command & Callback Handling: Usage of command handlers, callback handlers, and corresponding dispatcher logic demonstrates a decoupled command/query pattern.
Relevant Technologies & Components
• .NET Core 9.0 for runtime.
• Entity Framework Core for data persistence and migrations.
• Hangfire for scheduling tasks.
• Telegram Bot API for external integrations.
• Potential use of Docker (as observed from the aspirate-output/docker-compose.yaml) for deployments.
Specific Elements
• Clear labels for each major component (e.g., “Telegram Bot Client”, “AppHost – Entry Point”, “TelegramBotWorker”, “Command Dispatcher”, “Domain Aggregates”, “Infrastructure Repositories”, “EF Core Persistence/DB”).
• External systems like Telegram’s API and potentially Docker deployment lanes.
Detail and Clarity
• Do not shy away from splitting the design into as many components as they logically appear. For example, you may have separate nodes for “Command Handlers”, “Callback Handlers”, “Domain Aggregates (Kana, Question, User)”, and “Repositories”.