Skip to content

tysker/javalin_rest_api_pipeline

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

9 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ”— Javalin REST API + Traefik Deployment Pipeline

A lightweight REST API built with Javalin and a full production-ready DevOps pipeline using Docker, Traefik, and GitHub Actions.
Includes routing, controllers, exception handling, middleware-style security, PostgreSQL integration, and automated CI/CD deployment.


🧿 Status & CI/CD

Build Java Javalin Docker Traefik


πŸ“Œ Summary

This repository contains:

1. A modular, production-ready REST API (main branch)

  • Javalin routing
  • DAO β†’ Service β†’ Controller
  • Exception & validation handling
  • JWT or custom authentication (depending on your config)
  • Unit + integration tests
  • PostgreSQL integration

2. A complete deployment pipeline (traefik-pipeline branch)

  • Dockerfile + docker-compose
  • Traefik reverse proxy & TLS certificates
  • GitHub Actions CI/CD
  • DigitalOcean deployment (SSH + Docker Compose)
  • Environment-based configuration

Branch link:
πŸ”— https://github.com/tysker/javalin_rest_api_pipeline/tree/traefik-pipeline


🧰 Tech Stack

Backend

  • Java + Javalin
  • PostgreSQL
  • JUnit testing

DevOps

  • Docker & Docker Compose
  • Traefik v3 reverse proxy
  • GitHub Actions CI/CD
  • DigitalOcean droplet (Ubuntu)

πŸ“‚ Project Structure


src/
β”œβ”€β”€ main/java/
β”‚   β”œβ”€β”€ controllers/      # HTTP endpoints
β”‚   β”œβ”€β”€ daos/             # Database layer
β”‚   β”œβ”€β”€ services/         # Business logic
β”‚   β”œβ”€β”€ exceptions/       # Custom exceptions
β”‚   β”œβ”€β”€ security/         # Access manager / filters
β”‚   β”œβ”€β”€ util/             # Helpers
β”‚   └── App.java          # Application entrypoint
β”‚
└── test/
β”œβ”€β”€ unit/             # Unit tests
└── integration/      # Integration tests


πŸ“‚ Deployment Pipeline (traefik-pipeline branch)


deployment/
β”œβ”€β”€ docker/
β”‚   β”œβ”€β”€ Dockerfile
β”‚   β”œβ”€β”€ docker-compose.yml
β”‚   β”œβ”€β”€ docker-compose.prod.yml
β”‚   └── .env
β”‚
β”œβ”€β”€ traefik/
β”‚   β”œβ”€β”€ traefik.yml              # Static config
β”‚   β”œβ”€β”€ traefik_dynamic.yml      # Routers / TLS
β”‚   └── acme.json                # Certificate storage
β”‚
└── github/workflows/
└── deploy.yml               # CI/CD pipeline


πŸ§ͺ Testing

Run tests:

mvn test

πŸš€ Local Development

mvn clean package
java -jar target/app.jar

Runs at:

http://localhost:7000

πŸš€ CI/CD Pipeline Overview

flowchart TD
    A[Push to GitHub] --> B[GitHub Actions]
    B --> C[Run Tests / Build JAR]
    C --> D[Build Docker Image]
    D --> E[Push Image to Docker Hub]
    E --> F[SSH into DigitalOcean Server]
    F --> G[docker compose pull]
    G --> H[docker compose up -d]
    H --> I[Traefik Routes Traffic + HTTPS]
Loading

πŸ›°οΈ Deployment Architecture

                     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                     β”‚        Traefik v3         β”‚
                     β”‚  Automatic HTTPS / Routing β”‚
                     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                    β”‚
                   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                   β”‚                                 β”‚
         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
         β”‚   Javalin API       β”‚          β”‚   Admin Dashboard   β”‚
         β”‚   (Docker Container)β”‚          β”‚   (Optional)        β”‚
         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜          β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                   β”‚                                 β”‚
                   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                    β”‚
                         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                         β”‚    PostgreSQL       β”‚
                         β”‚ (Docker Container)  β”‚
                         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“„ Full Documentation

Api

  • All routes
  • Example requests
  • Example JSON responses
  • Error model

API Documentation

Base URL:


`/api/*`

User Endpoints

GET /api/users

Returns list of users.

GET /api/users/:id

Returns a user by ID.

POST /api/users

Creates a new user.

Body:

{
  "username": "john",
  "password": "secret"
}

PATCH /api/users/:id

Updates a user.

DELETE /api/users/:id

Deletes a user.


Error Model

{
  "status": "error",
  "message": "User not found",
  "path": "/api/users/999",
  "timestamp": "2025-01-20T10:15:14Z"
}

Pipeline

  • Docker architecture
  • Traefik configuration
  • GitHub Actions workflow explanation
  • Deployment steps
  • Environment variables

Deployment Pipeline Documentation

This project includes a complete CI/CD pipeline with:

  • Docker
  • Docker Compose
  • Traefik v3
  • GitHub Actions
  • DigitalOcean (remote server)

1. Build Process

GitHub Actions performs:

  1. Checkout
  2. Java build (mvn -B package)
  3. Run tests
  4. Build Docker image
  5. Push to Docker Hub

2. Deployment Process

  1. GitHub connects to the remote server via SSH
  2. Server pulls the latest Docker image
  3. Traefik reloads routes automatically
  4. New version goes live instantly

3. Traefik Overview

Traefik handles:

  • HTTPS certificates via Let’s Encrypt
  • Routing to API container
  • Middleware
  • Logging
  • Security headers

4. Environment Variables

.env contains:

DOMAIN=mydomain.com
EMAIL=[admin@mydomain.com](mailto:admin@mydomain.com)
POSTGRES_URL=jdbc:postgresql://db:5432/app
POSTGRES_USER=user
POSTGRES_PASSWORD=password
APP_PORT=7000

5. Deployment Trigger

Push to main automatically triggers deployment.


About

This is a simple Javalin REST API that allows you to create, read, update and delete.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages