Skip to content

Repository files navigation

Phonebook Application

The Phonebook Application is a RESTful API service developed with Kotlin and the Spring Boot framework, designed for efficient contact management in a digital phonebook. Containerized using Docker for consistent deployment across development, testing, and production environments, the platform provides secure user authentication, comprehensive contact management, and advanced data analytics.

The application leverages PostgreSQL as its primary relational database for structured, ACID-compliant data storage, while implementing session-based authentication via secure HTTP-only cookies. Through its comprehensive RESTful API, users can manage personal contacts, search by name or phone number, and access detailed analytics. The API features * pagination* across all collection endpoints for efficient data loading, aggregate functions for advanced statistics, and database indexing for optimal query performance.

Features

  • Authentication API powered by Spring Security with a custom session-based filter, featuring secure user registration, login, and logout using HTTP-only cookies.
  • Secure Session-Based Authentication implemented with UUID session identifiers stored in SESSION_ID cookie, including automatic session expiration (30 minutes) and cleanup mechanisms.
  • Pagination Support: All collection endpoints support pagination with customizable page size, page number, and sorting parameters for optimal data loading (getAllContactsOfUser, getContactByNumber, getAllOwnersOfPhonebooks, getUserByName).
  • Aggregate Functions & Analytics: Advanced SQL aggregation queries for business intelligence:
    • Total contacts count per user (COUNT(*));
    • Unique phone numbers statistics (COUNT(DISTINCT number));
    • Name and number length analytics (MIN, MAX, AVG);
    • User statistics by role (GROUP BY);
    • Active session tracking (COUNT with WHERE conditions);
  • Database Performance Optimization: Strategic indexing on frequently queried columns:
    • idx_users_session_id - fast session lookup;
    • idx_contacts_phonebook_id - optimized JOIN operations;
    • idx_contacts_name - quick contact search by name;
    • idx_contacts_number - efficient phone number lookup;
  • Audit Trail System: Automated tracking of user registration and deletion operations stored in dedicated user_audit table for compliance and monitoring purposes.
  • Containerized Deployment with Docker: Seamlessly build and run the entire ecosystem — including the Spring Boot application and PostgreSQL database — using Docker and Docker Compose for consistent, "one-command" environment setup.
  • CRUD operations available through RESTful API endpoints for the following collections:
    • Contacts
    • Users
  • Database Versioning: Automated schema migrations and version control using Flyway.
  • Modern Development with Kotlin: Leverage Kotlin's concise syntax, null safety, and data classes to enhance code readability, reduce boilerplate, and improve maintainability.
  • Streamlined setup and build processes using Gradle.

Requirements

The following configurations are required to launch the project:

  • Java Platform (JDK): 25
  • Gradle: 9.2.0
  • Spring Boot: 4.0.2
  • Docker: 29.1.3
  • Kotlin: 2.3.0
  • PostgreSQL: 17

Getting Started

  1. Clone the repository:
    git clone https://github.com/Bohdan100/phonebook-api
    cd phonebook-api
    
  2. Build and Run the Application Using Docker in Terminal:
    docker-compose up -d --build app
    
  3. Make your HTTPS requests using the following endpoints (e.g., via Postman), for authentification:

1. Authentication Endpoints

    {
      "name": "Admin", 
      "email": "admin@example.com",
      "password": "secret12345678",
      "role": "ADMIN"
     }

User Registration Request Body:

  {
   "name": "User",
   "email": "user@example.com",
   "password": "secret123456"
   }

Important:

After successful authentication, you receive a valid SESSION_ID cookie (HTTP-only, expires after 30 minutes). Include this cookie automatically for all subsequent requests.


2. Contacts Endpoints


3. Users Endpoints


  • Audit Trail:
    • The user_audit table automatically tracks:
      • User registration events (REGISTER operation).
      • User deletion events (DELETE operation).
      • Timestamps and user identification for compliance.

About

Kotlin Spring Boot API for digital contact management. Features secure session-based authentication and full CRUD operations (add, update, view, delete). Utilizes PostgreSQL for reliable data storage and Docker containerization. Built with Spring Boot, Kotlin, PostgreSQL, Flyway, Docker, and Gradle.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages