Development Guide
This guide helps you set up a local development environment for the TelegramBot API project and understand its architecture and development workflows.Prerequisites
Before starting, ensure you have the following installed:Java Development Kit (JDK)
Version: JDK 21 or higher
The project uses Java 21 features. Earlier versions won’t work.
Maven
Version: Maven 3.9 or higher
Maven wrapper (
mvnw) is included in the project, so local Maven installation is optional.Project Setup
Clone the Repository
Configure Environment Variables
Edit .env file
Open See the Configuration Guide for detailed instructions.
.env and configure the required variables:.env
Running the Application
Option 1: Docker Compose (Recommended)
The easiest way to run the complete stack:- API: http://localhost:8080
- Swagger UI: http://localhost:8080/swagger-ui.html
Docker Compose automatically sets up:
- PostgreSQL database container
- Application container with all dependencies
- Network configuration
- Volume persistence for database data
Option 2: Local Development (Without Docker)
For active development with faster rebuild times:Running Tests
The project includes comprehensive unit and integration tests.Run All Tests
Testcontainers: Integration tests use Testcontainers to spin up a PostgreSQL instance automatically. Docker must be running.
Run Specific Test Classes
Test Structure
The test suite includes:Unit Tests
Unit Tests
Located in
src/test/java/com/acamus/telegrm/application/usecases/RegisterUserUseCaseTest- User registration logicProcessTelegramUpdateUseCaseTest- Telegram message processingSendMessageUseCaseTest- Message sending logic
- Fast execution
- No external dependencies
- Uses Mockito for mocking
Integration Tests
Integration Tests
Located in
src/test/java/com/acamus/telegrm/infrastructure/adapters/ConversationRepositoryAdapterTest- Database operationsTelegrmApplicationTests- Full application context
- Tests real database interactions
- Uses Testcontainers for PostgreSQL
- Extends
BaseIntegrationTest
Base Integration Test
src/test/java/com/acamus/telegrm/BaseIntegrationTest.java
Integration tests take longer to run because they start a real PostgreSQL container.
Project Structure
The project follows Hexagonal Architecture (Ports and Adapters):Key Architectural Principles
Domain Independence
Domain Independence
The
core/ package contains pure business logic with no framework dependencies.- No Spring annotations in domain code
- No JPA entities in the domain
- Domain defines interfaces (ports), infrastructure implements them
This makes the domain easy to test and completely portable.
Dependency Rule
Dependency Rule
Dependencies flow inward:
- Domain depends on nothing
- Application depends on domain
- Infrastructure depends on both
Ports and Adapters
Ports and Adapters
- Ports: Interfaces defined in the domain
- Adapters: Implementations in infrastructure
Database Migrations
The project uses Flyway for database version control.Migration Files
Located insrc/main/resources/db/migration/:
Creating a New Migration
Adding New Features
Follow the hexagonal architecture pattern:Create ports
Define input port (use case interface) in Define output port (dependency interface) in
core/ports/in/:core/ports/out/:Development Tools
Swagger UI
Interactive API documentation at: http://localhost:8080/swagger-ui.htmlConfigure API documentation in
OpenApiConfig.java. All controllers are automatically documented using OpenAPI annotations.Bruno Collection
A pre-configured Bruno collection is included in the project:Database Tools
Connect to PostgreSQL
Connect to PostgreSQL
Docker:GUI Tools:
- DBeaver: Universal database client
- pgAdmin: PostgreSQL-specific
- IntelliJ Database Tools: Built into IntelliJ IDEA Ultimate
- Host:
localhost - Port:
5432 - Database:
telegrmdb - User:
postgres - Password: (from your
.env)
Troubleshooting
Port 8080 already in use
Port 8080 already in use
Another application is using port 8080.Solution:
Database migration failed
Database migration failed
Flyway detected a checksum mismatch or failed migration.Solution:
Tests failing with 'No Docker environment found'
Tests failing with 'No Docker environment found'
Testcontainers requires Docker to be running.Solution:
'Cannot resolve symbol' in IDE
'Cannot resolve symbol' in IDE
IDE hasn’t recognized Lombok-generated code.Solution (IntelliJ):
- Install Lombok plugin
- Enable annotation processing:
- Settings → Build → Compiler → Annotation Processors
- Check “Enable annotation processing”
- Rebuild project
Useful Commands
Next Steps
Architecture Deep Dive
Learn more about hexagonal architecture
API Reference
Explore all available endpoints
Configuration
Review all configuration options
Authentication
Understand the JWT authentication flow