|
1 | | -# Skat |
| 1 | +# Skat Backend |
2 | 2 |
|
3 | | -A mono-repo project with Java 21 Spring Boot backend and Angular 18 frontend. |
| 3 | +Spring Boot REST API backend for the Skat application. |
4 | 4 |
|
5 | | -## Project Structure |
| 5 | +## Technology Stack |
6 | 6 |
|
7 | | -``` |
8 | | -. |
9 | | -├── backend/ # Spring Boot backend (Java 21) |
10 | | -├── frontend/ # Angular 18 frontend |
11 | | -└── .github/ # CI/CD workflows |
12 | | - └── workflows/ |
13 | | - └── build.yml # Build pipeline |
| 7 | +- **Java**: 21 |
| 8 | +- **Spring Boot**: 3.5.6 |
| 9 | +- **Database**: PostgreSQL (production), H2 (development) |
| 10 | +- **Build Tool**: Maven |
| 11 | + |
| 12 | +## Prerequisites |
| 13 | + |
| 14 | +- Java 21 or higher |
| 15 | +- Maven 3.6 or higher |
| 16 | +- PostgreSQL (for production mode) |
| 17 | + |
| 18 | +## Getting Started |
| 19 | + |
| 20 | +### Running with H2 In-Memory Database (Development) |
| 21 | + |
| 22 | +The easiest way to start the application for development is using the H2 in-memory database: |
| 23 | + |
| 24 | +```bash |
| 25 | +mvn spring-boot:run -Dspring-boot.run.profiles=dev |
14 | 26 | ``` |
15 | 27 |
|
16 | | -## Backend |
| 28 | +The application will start on `http://localhost:8080` |
17 | 29 |
|
18 | | -### Technology Stack |
19 | | -- Java 21 |
20 | | -- Spring Boot 3.4.2 |
21 | | -- PostgreSQL |
22 | | -- Maven |
| 30 | +### Running with PostgreSQL (Production) |
23 | 31 |
|
24 | | -### Build and Run |
| 32 | +1. Ensure PostgreSQL is running and create a database: |
| 33 | + ```sql |
| 34 | + CREATE DATABASE skatdb; |
| 35 | + ``` |
| 36 | + |
| 37 | +2. Update the database credentials in `src/main/resources/application.properties` if needed: |
| 38 | + ```properties |
| 39 | + spring.datasource.url=jdbc:postgresql://localhost:5432/skatdb |
| 40 | + spring.datasource.username=postgres |
| 41 | + spring.datasource.password=postgres |
| 42 | + ``` |
| 43 | + |
| 44 | +3. Start the application: |
| 45 | + ```bash |
| 46 | + mvn spring-boot:run |
| 47 | + ``` |
| 48 | + |
| 49 | +### Building the Application |
| 50 | + |
| 51 | +To build the application and create an executable JAR: |
25 | 52 |
|
26 | 53 | ```bash |
27 | | -cd backend |
28 | 54 | mvn clean package |
29 | | -mvn spring-boot:run |
30 | 55 | ``` |
31 | 56 |
|
32 | | -The backend will start on `http://localhost:8080` |
| 57 | +The JAR file will be created in the `target/` directory. |
33 | 58 |
|
34 | | -For development without PostgreSQL, you can use the H2 in-memory database: |
| 59 | +### Running the JAR |
| 60 | + |
| 61 | +After building, you can run the application using: |
35 | 62 |
|
36 | 63 | ```bash |
37 | | -cd backend |
38 | | -mvn spring-boot:run -Dspring-boot.run.profiles=dev |
39 | | -``` |
| 64 | +# With H2 (development) |
| 65 | +java -jar target/backend-0.0.1-SNAPSHOT.jar --spring.profiles.active=dev |
40 | 66 |
|
41 | | -### API Endpoints |
| 67 | +# With PostgreSQL (production) |
| 68 | +java -jar target/backend-0.0.1-SNAPSHOT.jar |
| 69 | +``` |
42 | 70 |
|
43 | | -- `GET /api/hello` - Returns "Hallo" |
| 71 | +## Running Tests |
44 | 72 |
|
45 | | -### Database Configuration |
| 73 | +Execute the test suite: |
46 | 74 |
|
47 | | -PostgreSQL configuration is in `backend/src/main/resources/application.properties`: |
48 | | -- URL: `jdbc:postgresql://localhost:5432/skatdb` |
49 | | -- Username: `postgres` |
50 | | -- Password: `postgres` |
| 75 | +```bash |
| 76 | +mvn test |
| 77 | +``` |
51 | 78 |
|
52 | | -## Frontend |
| 79 | +## API Endpoints |
53 | 80 |
|
54 | | -### Technology Stack |
55 | | -- Angular 18 |
56 | | -- TypeScript |
57 | | -- Node.js 20 |
| 81 | +### Hello World Endpoint |
58 | 82 |
|
59 | | -### Build and Run |
| 83 | +- **URL**: `/api/hello` |
| 84 | +- **Method**: `GET` |
| 85 | +- **Response**: Plain text "Hallo" |
60 | 86 |
|
| 87 | +Example: |
61 | 88 | ```bash |
62 | | -cd frontend |
63 | | -npm install |
64 | | -npm start |
| 89 | +curl http://localhost:8080/api/hello |
65 | 90 | ``` |
66 | 91 |
|
67 | | -The frontend will start on `http://localhost:4200` |
| 92 | +## Configuration Profiles |
68 | 93 |
|
69 | | -### Features |
| 94 | +### Development Profile (`dev`) |
70 | 95 |
|
71 | | -- Calls the backend `/api/hello` endpoint |
72 | | -- Displays the response without formatting |
| 96 | +Uses H2 in-memory database. Configuration file: `application-dev.properties` |
73 | 97 |
|
74 | | -## Build Pipeline |
| 98 | +- Database: H2 in-memory |
| 99 | +- H2 Console: Enabled at `/h2-console` |
| 100 | +- SQL logging: Enabled |
75 | 101 |
|
76 | | -The project includes a GitHub Actions workflow that: |
77 | | -- Builds the backend with Maven |
78 | | -- Runs backend tests |
79 | | -- Builds the frontend with npm |
80 | | -- Uploads build artifacts |
| 102 | +### Default Profile (Production) |
| 103 | + |
| 104 | +Uses PostgreSQL database. Configuration file: `application.properties` |
| 105 | + |
| 106 | +- Database: PostgreSQL |
| 107 | +- Connection pooling: HikariCP (default) |
| 108 | + |
| 109 | +## Project Structure |
| 110 | + |
| 111 | +``` |
| 112 | +backend/ |
| 113 | +├── src/ |
| 114 | +│ ├── main/ |
| 115 | +│ │ ├── java/ |
| 116 | +│ │ │ └── com/skat/backend/ |
| 117 | +│ │ │ ├── SkatBackendApplication.java # Main application class |
| 118 | +│ │ │ └── controller/ |
| 119 | +│ │ │ └── HelloWorldController.java # REST controller |
| 120 | +│ │ └── resources/ |
| 121 | +│ │ ├── application.properties # Production config |
| 122 | +│ │ └── application-dev.properties # Development config |
| 123 | +│ └── test/ |
| 124 | +│ └── java/ |
| 125 | +│ └── com/skat/backend/ |
| 126 | +│ └── controller/ |
| 127 | +│ └── HelloWorldControllerTest.java # Controller tests |
| 128 | +├── pom.xml # Maven configuration |
| 129 | +└── README.md # This file |
| 130 | +``` |
| 131 | + |
| 132 | +## Troubleshooting |
| 133 | + |
| 134 | +### Port Already in Use |
| 135 | + |
| 136 | +If port 8080 is already in use, you can change it by adding to your run command: |
| 137 | + |
| 138 | +```bash |
| 139 | +mvn spring-boot:run -Dspring-boot.run.arguments=--server.port=8081 |
| 140 | +``` |
| 141 | + |
| 142 | +### Database Connection Issues |
| 143 | + |
| 144 | +- Verify PostgreSQL is running: `pg_isready` |
| 145 | +- Check PostgreSQL logs for connection errors |
| 146 | +- Verify database credentials in `application.properties` |
81 | 147 |
|
82 | 148 | ## Development |
83 | 149 |
|
84 | | -1. Start the backend: |
85 | | - ```bash |
86 | | - cd backend |
87 | | - mvn spring-boot:run |
88 | | - ``` |
| 150 | +### Adding New Dependencies |
89 | 151 |
|
90 | | -2. In a new terminal, start the frontend: |
91 | | - ```bash |
92 | | - cd frontend |
93 | | - npm start |
94 | | - ``` |
| 152 | +Add dependencies to `pom.xml` and run: |
| 153 | + |
| 154 | +```bash |
| 155 | +mvn clean install |
| 156 | +``` |
| 157 | + |
| 158 | +### Code Style |
95 | 159 |
|
96 | | -3. Open your browser at `http://localhost:4200` |
| 160 | +The project follows standard Java coding conventions. Ensure your IDE is configured to use: |
| 161 | +- Tab size: 4 spaces |
| 162 | +- Charset: UTF-8 |
0 commit comments