Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ build/

### Internal docs (not committed) ###
internal/
internal/*
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Repository contribution guidelines and branch protection rules (`CONTRIBUTING.md`).
- GitHub status badges in `README.md`.

### Fixed
- Dockerfile JDK version mismatch: `eclipse-temurin:21-jre` → `eclipse-temurin:25-jre` to align with project's `java.version`.
- Broken GraalVM native profile in `pom.xml`: removed invalid dependency declaration with undefined property reference.
- Removed `System.out.println` debug statement from `UserController`.
- README updated to accurately reflect current project status.

---

## [0.1.0] - 2026-07-27
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM eclipse-temurin:21-jre AS runtime
FROM eclipse-temurin:25-jre AS runtime

WORKDIR /app

Expand Down
124 changes: 56 additions & 68 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,107 +4,95 @@
<a href="https://github.com/shashankch/payflow-api/actions/workflows/ci.yml"><img src="https://github.com/shashankch/payflow-api/actions/workflows/ci.yml/badge.svg" alt="Build"></a>
<a href="https://dev.java/"><img src="https://img.shields.io/badge/Java-25-ED8B00?logo=openjdk&logoColor=white" alt="Java 25"></a>
<a href="https://spring.io/projects/spring-boot"><img src="https://img.shields.io/badge/Spring%20Boot-4.0.6-6DB33F?logo=springboot&logoColor=white" alt="Spring Boot"></a>
<a href="https://www.postgresql.org/"><img src="https://img.shields.io/badge/PostgreSQL-17-4169E1?logo=postgresql&logoColor=white" alt="PostgreSQL"></a>
<a href="LICENSE"><img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="License: MIT"></a>
<a href="CONTRIBUTING.md"><img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg" alt="PRs Welcome"></a>
</p>

Payflow is a highly resilient, transactional payments backend built using **Java 25** and **Spring Boot 4.x**. The project is designed with a pluggable, cloud-flexible architecture optimized for local developer iteration, Kubernetes deployment, and resource-constrained environments (like AWS Free Tier and Oracle Cloud Always Free).
Payflow is a transactional payments backend built using **Java 25** and **Spring Boot 4.x**, designed to evolve from a baseline REST API into an enterprise-grade payment system with ACID guarantees, event-driven architecture, and observability.

---

## Current Status & Evolution Roadmap
## Current Status

The project is currently evolving through a phased implementation roadmap from a Phase 0 baseline into an enterprise-grade payment system.
The project is evolving through a phased implementation roadmap. See the full plan in **[Phased Roadmap](docs/ROADMAP.md)**.

- **Phase 0 (Completed)**: Baseline REST API for User & Transaction CRUD with H2 in-memory storage.
- **Phase 1 (In Progress)**: Project hygiene, static analysis (Spotless, Checkstyle), and GitHub Actions CI.
- **Target Phases**: PostgreSQL & Flyway migrations, pessimistic row locking with deadlock avoidance, durable idempotency engine, transactional outbox pattern, JWT security, Resilience4j fault tolerance, Redis caching & Redisson distributed locking, Kafka event streaming, and Gen-AI transaction insights.

See the complete step-by-step evolution in **[Phased Roadmap](docs/ROADMAP.md)**.
| Phase | Description | Status |
|-------|-------------|--------|
| **Phase 0** | Baseline REST API — User & Transaction CRUD with H2 in-memory storage | ✅ Complete |
| **Phase 1** | Project hygiene — Spotless, Checkstyle, GitHub Actions CI | ✅ Complete |
| **Phase 2** | Domain model hardening, DTO layer, validation, error handling | ⬜ Not Started |
| **Phase 3+** | Concurrency control, Flyway, security, observability, and more | ⬜ Not Started |

---

## Technical Architecture Highlights
## Implemented Features

- **ACID Transaction Hardening**: Enforces sequential consistency under race conditions using database-level pessimistic locking (`SELECT FOR UPDATE`).
- **Distributed Locking Coordination**: Integrates **Redis Redlock** (via Redisson) to synchronize distributed triggers across multi-instance deployments.
- **JPA N+1 Resolution**: Avoids Hibernate lazy loading bottlenecks through explicit **Fetch Joins** and `@EntityGraph` definitions.
- **REST API Versioning**: Implements strict URI version control (`/api/v1`) protecting endpoints from breaking changes.
- **Gen-AI Spending Assistant**: Integrates **Spring AI** (Ollama / Groq / Gemini) to automatically categorize transactions and generate spend analysis.
- **Durable Idempotency Engine**: Enforces exactly-once execution on mutation APIs via SHA-256 request payload hashing and persistent state checking.
- **Transactional Outbox Pattern**: Guarantees atomic consistency between state transitions and event streaming without dual-write vulnerabilities.
- **Pluggable Resilience Policies**: Configured via Resilience4j for client-side rate-limiting, exponential backoff retries with jitter, and call timeouts.
- **Telemetry & Observability**: Integrated with Spring Boot Actuator, Prometheus metrics, Logback MDC-based distributed trace correlation, and Grafana dashboards.
- **REST API**: Basic CRUD endpoints for User registration and Transaction creation.
- **Layered Architecture**: Controller → Service → Repository pattern with Spring Data JPA.
- **In-Memory Database**: H2 with auto-generated schema for zero-dependency local development.
- **Code Quality**: Spotless (Eclipse formatter) + Checkstyle enforced at Maven `validate` phase.
- **CI Pipeline**: GitHub Actions workflow running `mvn clean verify` on push/PR to `main`.
- **Actuator**: Health, info, and metrics endpoints exposed.

---

## Project Documentation Directory
## Target Architecture (Roadmap)

1. 📘 **[System Architecture Guide](docs/ARCHITECTURE.md)**: Deep technical details on topology, locking, idempotency, Spring profiles, and observability.
2. 🗓️ **[Phased Implementation Roadmap](docs/ROADMAP.md)**: Subdivided step-by-step phases (A and B) spanning database migrations, security, event streaming, and deployment.
3. 🌐 **[REST API Specification](docs/API_SPECIFICATION.md)**: Complete request and response payload schemas, versioned endpoints, validations, status codes, and RFC 7807 error formats.
4. 📋 **[Engineering Conventions](docs/CONVENTIONS.md)**: Coding standards, Git commit conventions, PR guidelines, and test naming rules.
5. 📜 **[Architecture Decision Records](docs/ADR.md)**: Log of architectural decisions, context, trade-offs, and consequences.
The following features are planned and will be implemented across future phases:

---
- ACID transaction hardening with pessimistic locking and deadlock avoidance
- Balance ledger with double-entry bookkeeping for auditability
- DTO layer with input validation and RFC 7807 error responses
- PostgreSQL with Flyway-managed schema migrations
- Durable idempotency engine with SHA-256 payload hashing
- Transactional outbox pattern for reliable event streaming
- JWT authentication and authorization
- Resilience4j fault tolerance (rate limiting, retry, circuit breaker)
- Redis caching and distributed locking
- Kafka event streaming
- Structured logging with MDC trace correlation and Prometheus metrics
- Multi-stage Docker build with full-stack Docker Compose
- Kubernetes manifests with health probes and graceful shutdown
- Gen-AI spend insights with Spring AI

## Spring Profiles Strategy
See **[System Architecture Guide](docs/ARCHITECTURE.md)** for detailed design documentation.

The application leverages profile isolation to adapt resources to the target environment dynamically:
---

- **`local` (Default)**: In-memory H2 database, automated hibernate schema updates, and zero-dependency local startup.
- **`test`**: Active during integration tests, utilizing **Testcontainers** to dynamically boot local Postgres/Kafka container instances for validation.
- **`prod`**: Production-grade settings. Database credentials and broker addresses are read from system environment variables. Schema evolution is strictly managed by **Flyway migrations**.
- **`prod-light` (Resource Constrained / Free Tier)**: Memory-optimized profile for single constrained virtual servers (1 GiB RAM). Uses lightweight in-memory fallbacks for Redis and Kafka to prevent OOM failures.
## Project Documentation

| Doc | Description |
|-----|-------------|
| 📘 [System Architecture](docs/ARCHITECTURE.md) | Design patterns, concurrency control, observability |
| 🗓️ [Phased Roadmap](docs/ROADMAP.md) | Step-by-step evolution plan |
| 🌐 [API Specification](docs/API_SPECIFICATION.md) | Endpoints, payloads, validation rules, error formats |
| 📋 [Conventions](docs/CONVENTIONS.md) | Coding standards, Git workflow, testing rules |
| 📜 [Architecture Decisions](docs/ADR.md) | Decision records with context and trade-offs |

---

## Quick Start

### 1. Build and Run Local Tests
Requires JDK 25 and Maven:
```bash
mvn clean install
mvn test
```
### Prerequisites
- JDK 25 (Temurin recommended)
- Maven 3.9+

### 2. Local Standalone Startup (Zero Dependencies)
Boots the application on port `8080` using H2 in-memory storage:
### Build & Run
```bash
mvn spring-boot:run
```
- **H2 Console**: Available at `http://localhost:8080/h2-console`
- *JDBC URL*: `jdbc:h2:mem:payupidb`
- *Credentials*: `user` / `user`
# Build and run tests
mvn clean verify

### 3. Local Full-Stack Ecosystem Startup (Docker Compose)
To run a local staging environment containing Postgres, Redis, Kafka KRaft, Prometheus, and Grafana:
```bash
docker-compose up --build
# Start locally (H2 in-memory, port 8080)
mvn spring-boot:run
```

---
- **H2 Console**: `http://localhost:8080/h2-console`
- JDBC URL: `jdbc:h2:mem:payupidb`
- Credentials: `user` / `user`

## Production Deployment Readiness

### Kubernetes Deployment
Static Kubernetes manifests are defined under the `k8s/` directory. Deploy using:
### Docker
```bash
kubectl apply -f k8s/
```
- **Liveness Probe**: Routed to `/actuator/health/liveness`
- **Readiness Probe**: Routed to `/actuator/health/readiness`
- **Graceful Shutdown**: Handled via `server.shutdown=graceful` coordinating with container orchestration to process in-flight transactions before pod termination.

### GraalVM Native Compilation
To compile the application to a lightweight, platform-native binary that starts in milliseconds and consumes ~30-50MB of RAM:
```bash
# Compile native binary locally
mvn -Pnative native:compile

# Or build an optimized native OCI image via Buildpacks
mvn -Pnative spring-boot:build-image
docker-compose up --build
```

---
Expand Down
Loading
Loading