Thanks to visit codestin.com
Credit goes to github.com

Skip to content

NullPoint3rDev/feature-flags-microservice

Repository files navigation

Feature Flags Microservice

Java Spring Boot Spring Data JPA H2 Gradle Docker JUnit 5 License: MIT

REST API for managing feature flags — create and evaluate flags by key, with validation, duplicate detection, and one-command run via Docker Compose.

FeaturesArchitectureQuick StartAPITech Stack


✨ Features

Feature Description
Create flags POST /api/flags with key, optional description and status; returns 201 with full flag payload.
Get by key GET /api/flags/{key} returns the flag or 404 if not found.
Unique keys Duplicate key on create returns 409 Conflict; DB unique index on flagKey.
Bean Validation Request DTOs validated with Jakarta Validation; blank or invalid key yields 400.
JPA persistence Flags stored in H2 (in-memory by default); schema via Hibernate DDL; easy to switch to PostgreSQL.
Status lifecycle Enum-based status: CREATED, ENABLED, DISABLED; default CREATED when omitted.
Docker Compose Single command builds and runs the app; no local JDK required.
Tests Unit tests for service (Mockito); slice tests for controller (@WebMvcTest).
Actuator Health and info endpoints for monitoring.

🏗 Architecture

flowchart LR
    subgraph Client
        C[HTTP Client]
    end
    subgraph "Spring Boot :8081"
        REST[REST API]
        REST --> Svc[FlagService]
        Svc --> Repo[FlagRepository]
    end
    subgraph "H2"
        DB[(flags table)]
    end
    C -->|"GET /api/flags/:key"| REST
    C -->|"POST /api/flags"| REST
    Repo --> DB
Loading

Flow: Clients create flags via POST /api/flags (JSON body). Service checks uniqueness, persists via JPA, returns 201 or 409. GET /api/flags/{key} reads from the repository and returns 200 or 404.


🚀 Quick Start

With Docker Compose (recommended)

git clone https://github.com/NullPoint3rDev/feature-flags-microservice.git
cd feature-flags-microservice
docker compose up --build

API base: http://localhost:8081

# Create a flag
curl -X POST http://localhost:8081/api/flags \
  -H "Content-Type: application/json" \
  -d '{"key": "dark-mode", "description": "Dark theme toggle", "status": "CREATED"}'

# Get flag by key
curl http://localhost:8081/api/flags/dark-mode

Local (Gradle + JDK 21)

./gradlew bootRun

Runs on http://localhost:8081. H2 console (if enabled): http://localhost:8081/h2-console.


📡 API

Method Path Description
POST /api/flags Create a flag. Body: { "key": "string", "description": "optional", "status": "CREATED|ENABLED|DISABLED" }. Returns 201 or 409 (duplicate key), 400 (validation).
GET /api/flags/{key} Get flag by key. Returns 200 + JSON or 404.

Example response (create / get)

{
  "flagId": "3b71566c-d2df-4a8b-9e00-3e930d564903",
  "flagKey": "dark-mode",
  "flagStatus": "CREATED",
  "flagDescription": "Dark theme toggle",
  "flagRules": null
}

🛠 Tech Stack

Technology Purpose
Java 21 LTS runtime.
Spring Boot 3.2 Web, Actuator, Validation, Data JPA.
Spring Data JPA Repository abstraction; H2 driver for in-memory DB.
H2 Embedded DB; optional console for debugging.
Gradle 8.x (Kotlin DSL) Build and dependency management.
Docker & Compose Single-command run; multi-stage Dockerfile (JDK build, JRE run).
JUnit 5 & Mockito Unit and controller slice tests.
Lombok Boilerplate reduction on entities and DTOs.

📄 License

This project is licensed under the MIT License.

About

REST API for feature flags — Spring Boot 3, Java 21, JPA/H2, Docker. Create and evaluate flags by key.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors