The Problem

Tax practitioners must manually log into the Kenya Revenue Authority (KRA) portal to file NIL (zero‑income) returns for each individual taxpayer. The web UI is slow, error‑prone, and does not expose an easy programmatic interface, leading to duplicated effort and delayed compliance.

What This Does

KRAAppBackend is a Spring Boot service that wraps the KRA API and exposes a single REST endpoint for filing NIL returns.

Controller – FileNillReturnController.java receives a JSON payload (FileReturnsDto.java) and forwards it to the service layer. Service – FileNillReturnsService.java builds the request body required by KRA and calls KraAuthService to obtain a valid bearer token. Auth – KraAuthService.java generates a Base64‑encoded consumer key:secret string, posts to the KRA token endpoint using OkHttp, caches the token in memory, and refreshes it on expiration.

The application starts from KraAppBackendApplication.java and reads credentials from src/main/resources/application.properties (kra.consumer.key / kra.consumer.secret).

How To Use It

Clone and enter the project git clone https://github.com/DunstanKiiru/KRAAppBackend.git cd KRAAppBackend Add KRA credentials (do NOT commit this file) src/main/resources/application.properties kra.consumer.key=YOURKEY kra.consumer.secret=YOURSECRET Build the jar (the wrapper script ensures the correct Maven version) ./mvnw clean package Run the service java -jar target/kra-app-backend-0.0.1-SNAPSHOT.jar

The service listens on the default Spring Boot port (8080). To file a NIL return:

curl -X POST http://localhost:8080/api/v1/file-nil-return \ -H "Content-Type: application/json" \ -d '{ "tin": "A123456789", "taxPeriod": "2024", "returnType": "NIL" }'

The controller forwards the payload to FileNillReturnsService, which contacts KRA using the cached token.

Real‑World Use

A tax advisory firm can deploy this jar behind an internal API gateway. Their client‑facing portal collects taxpayer details, then calls the /api/v1/file-nil-return endpoint. The backend handles token rotation automatically, eliminating manual logins and reducing filing time from minutes per client to seconds.

Code Health & Issues

Medium – No CI/CD pipeline – No .github/workflows or similar; builds and tests must be run manually (KraAppBackendApplicationTests.java exists but is not gated). Medium – Missing LICENSE – Repository root lacks a license file; downstream users have unclear redistribution rights. Low – Dependency reproducibility – Maven pom.xml pins versions but does not use a lockfile (dependencyManagement is present, but no versions.lock). Low – In‑memory token cache – KraAuthService stores the token in a simple field; in a multi‑instance deployment this leads to each instance fetching its own token, increasing load on KRA. Low – No input validation – FileNillReturnController passes the DTO directly to the service; malformed tin or taxPeriod values could cause KRA rejections without a clear error response. Low – Limited test coverage – Only the Spring Boot context test (KraAppBackendApplicationTests) is present; business logic in FileNillReturnsService and KraAuthService lacks unit tests.

Overall the code follows standard Spring conventions, uses explicit configuration (application.properties), and compiles cleanly with Maven. No obvious security flaws beyond the mentioned in‑memory token storage.

The Bottom Line

The repository provides a functional, well‑structured Spring Boot wrapper for KRA NIL filing, suitable for internal use or as a prototype integration layer. It is ready to run with minimal setup, but production deployment should add CI pipelines, a proper license, stronger input validation, and a distributed token cache or external secret store.