Skip to content

castroy10/spring-dadata

Repository files navigation

Spring Dadata

Java CI with Maven Java Spring Boot Thymeleaf License GitHub issues GitHub stars

🇷🇺 Русская версия

Screenshot

Spring Dadata is a web application designed to integrate and demonstrate the capabilities of the Dadata API. It allows users to search, clean, and enrich address and company data using a clean and responsive web interface.

Features

  • Address Search & Standardization:
    • Cleans and standardizes raw address strings.
    • Displays detailed administrative divisions (region, city, district).
    • Shows geo-coordinates and nearest metro stations.
    • Identifies tax office codes (IFNS, OKATO, OKTMO).
  • Company Search:
    • Search organizations by INN (Taxpayer Identification Number).
    • Retrieves full company details including management, status, and legal address.
    • Displays KPP, OGRN, OKVED, and other statistical codes.
  • UI/UX:
    • Modern and responsive interface built with Thymeleaf and Bootstrap 5.
    • Card-based result layout for better readability.
    • Dynamic search forms for different data types.

Used Technologies

  • Java 21
  • Spring Boot 4+ (Spring Web, Spring MVC)
  • Thymeleaf
  • Maven
  • Docker & Docker Compose
  • Dadata API (RestClient)
  • Lombok

Getting Started

Prerequisites

  • JDK 21+
  • Maven
  • A valid Dadata API Token and Secret key.

Configuration

You need to configure your Dadata credentials in src/main/resources/application.yml or via environment variables:

dadata:
  token: ${DADATA_TOKEN:your_token_here}
  secret: ${DADATA_SECRET:your_secret_here}

Installation & Run

  1. Clone the repository:

    git clone https://github.com/castroy10/spring-dadata.git
    cd spring-dadata
  2. Build the project:

    ./mvnw clean install
  3. Run the application:

    ./mvnw spring-boot:run
  4. Access the app: Open your browser and navigate to http://localhost:8080.

Running with Docker

Using Docker Compose (Recommended)

  1. Build and start the container:

    docker-compose up -d --build
  2. Stop the application:

    docker-compose down

Using Dockerfile directly

  1. Build the image:

    docker build -t spring-dadata .
  2. Run the container:

    docker run -d -p 8080:8080 -e DADATA_TOKEN=your_token -e DADATA_SECRET=your_secret --name spring-dadata spring-dadata

Architecture

Services

  • AddressService: Handles communication with Dadata's "Clean" API to process address data.
  • CompanyService: Interacts with Dadata's "Suggest" API to find organization details by INN. Implements null-safe handling for API responses.

Models

  • Comprehensive DTOs mapping the complex JSON responses from Dadata, including nested structures like Management, Opf, State, and detailed Address components.

Controllers

  • MainController: Manages web routes, handles search form submissions, and populates the Thymeleaf model with search results.

Testing

The project includes comprehensive unit tests covering:

  • Service Layer: Mocking RestClient to test API interactions and edge cases (null responses, empty lists).
  • Controller Layer: Testing web endpoints and view resolution using MockMvc in standalone mode.

To run tests:

./mvnw test

About

Spring Boot application for Dadata API integration

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published