This document defines the current architectural boundaries of the project and the allowed dependency directions.
routers/,middlewares/,start.py
- Delivery/interface layer.
- Accepts Telegram updates, validates context, calls application services.
services/
- Application layer.
- Contains use-case orchestration and cross-module workflows.
- Depends on domain models and repository/service interfaces.
shared/domain/
- Domain layer.
- Contains entities/enums/value semantics for business rules.
- Must not depend on Telegram SDK or DB adapters.
db/,shared/infrastructure/database/,other/integrations
- Infrastructure/adapters.
- DB repositories, SQLAlchemy models/migrations, external API clients.
interface (routers/middlewares) -> application (services) -> domain (shared/domain)
interface/application -> infrastructure adapters (db/other) through service/repository abstractions
- Routers stay thin.
- No complex business logic in handlers.
- Handlers delegate to
services/or focused helper modules.
- Domain is framework-agnostic.
- No aiogram imports in
shared/domain/. - No direct SQLAlchemy model usage in domain entities.
- Infrastructure is replaceable.
- DB and external integrations should be isolated in
db/andother/. - Public behavior should be testable via fakes/mocks.
- Cross-cutting concerns belong to middlewares/services.
- User resolution, throttling, app context wiring should not be duplicated in routers.
The codebase is in transition and still contains legacy couplings. They are allowed temporarily but should be reduced iteratively with tests.