Warning
Rename .env.local to .env before running docker compose or DB connection will fail!
[!NOTE]
PostgreSQL is not exposed on host port 5432 to avoid conflicts. All services run in a private Docker network. You just need to run docker compose up --pull always --build.
This is the backend API for the Courses App. Built with Java 17, Spring Boot, and PostgreSQL, it exposes a REST API to manage courses and their delivery instances — with proper validation for prerequisites and dependencies.
The backend is fully Dockerized, uses Flyway for DB migrations, and is designed to run as part of a full-stack setup with Docker Compose.
- Java 17 + Spring Boot
- PostgreSQL (as DB)
- Spring Data JPA
- Flyway (for migrations)
- Docker (multi-stage Maven build)
- Full CRUD for Courses and Course Instances
- Courses can have multiple prerequisites (validated)
- Delivery instances tied to semester and year
- Proper validation with meaningful error responses
- Clean architecture: Controller → Service → Repository
- Preconfigured Docker container
- Flyway-based schema migration
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/courses |
Create a new course |
| GET | /api/courses |
Get all courses |
| GET | /api/courses/{id} |
Get course by ID |
| DELETE | /api/courses/{id} |
Delete course by ID |
| GET | /api/courses/search?title=… |
Search courses by title (partial) |
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/instances |
Create a course instance |
| GET | /api/instances/{year}/{semester} |
Get all course instances in a given year/semester |
| GET | /api/instances/{year}/{semester}/{courseId} |
Get a specific course instance |
| DELETE | /api/instances/{year}/{semester}/{courseId} |
Delete a specific course instance |
🧠 All requests/responses use JSON format.
Prerequisites and instances are validated during creation to prevent circular references or missing courses.
This app is published as a Docker image on Docker Hub and is designed to run via docker compose.
services:
db:
image: postgres:16
container_name: courses-db
restart: unless-stopped
environment:
POSTGRES_DB: courses
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
volumes:
- postgres_data:/var/lib/postgresql/data
ports:
- "5432:5432"
courses-backend:
image: ranxom/courses-backend:latest
container_name: courses-backend
ports:
- "8080:8080"
depends_on:
- db
env_file:
- .env
restart: unless-stopped
volumes:
postgres_data:SPRING_DATASOURCE_URL=jdbc:postgresql://courses-db:5432/courses
SPRING_DATASOURCE_USERNAME=postgres
SPRING_DATASOURCE_PASSWORD=postgres🔐 This file is required to configure DB credentials and connection inside Docker.
-
This project includes Flyway migrations; DB schema is automatically created at startup.
-
Make sure to link the
.envfile properly or it will fail DB connection. -
If building locally instead of pulling image, run:
docker build -t ranxom/courses-backend:latest .
- Ensure Docker & Docker Compose are installed
- Clone both backend and frontend repos
- Create
.envfile in backend directory (as shown above) - Ensure
docker-compose.ymlincludes the backend and frontend services - Run:
docker-compose upAPI will be available at: http://localhost:8080/api
If you prefer to run the backend without Docker:
./mvnw spring-boot:runEnsure PostgreSQL is running locally and .env or application.properties is configured accordingly.
📦 courses-backend
┣ 📂src
┃ ┣ 📂main
┃ ┃ ┣ 📂java
┃ ┃ ┃ ┗ 📦 com.shizain.courses_backend
┃ ┃ ┣ 📂resources
┃ ┃ ┃ ┣ application.properties
┃ ┃ ┃ ┗ db/migration/V1__init.sql (Flyway)
┣ 📄 Dockerfile
┣ 📄 docker-compose.yml (if colocated)
┣ 📄 .env
┣ 📄 pom.xml
┗ 📄 README.md
Built with 💻 and ☕ by Shizain
MIT