Environment variables
The Chat Server API uses environment variables for sensitive configuration. These should be set before starting the server.JWT_SECRET
TheJWT_SECRET environment variable configures the secret key used for JWT token signing and verification (from Configuration.java:14).
Default value: Base64-encoded string (insecure default for development only)
Setting the variable:
JWT configuration constants
The following JWT-related constants are defined inConfiguration.java:
- JWT_EXPIRATION_MS:
1000 * 60 * 60 * 30(30 days) - Token expiration time in milliseconds
- Tokens issued will be valid for 30 days from creation
Application properties
The server configuration is defined inapplication.properties. These settings control the Spring Boot application behavior.
Database configuration
The server uses SQLite as the primary database (fromapplication.properties:1-12):
Database settings explained
-
spring.datasource.url:
jdbc:sqlite:./main.db- Database file location (created in the current directory)
- Change the path to customize the database location
-
spring.jpa.hibernate.ddl-auto:
update- Automatically updates database schema based on entity changes
- Use
validatein production to prevent accidental schema changes
-
spring.sql.init.mode:
always- Runs initialization scripts on startup
SQLite performance optimizations
The application configures SQLite with performance optimizations via HikariCP connection pool:- journal_mode=WAL: Write-Ahead Logging for better concurrency
- synchronous=NORMAL: Balanced durability and performance
- cache_size=-10000: 10MB cache size (negative value = kilobytes)
- temp_store=MEMORY: Use memory for temporary tables
Database setup
The server supports two embedded databases:SQLite (default)
SQLite is configured as the default database and requires no additional setup.Automatic database creation
When you start the server for the first time, SQLite will automatically create the
main.db file in the server directory.Schema initialization
Hibernate will automatically create tables based on JPA entity classes due to the
ddl-auto=update setting.The database file path is relative to where you start the server. If you run the server from different directories, multiple database files may be created.
H2 Database (alternative)
H2 is included as a runtime dependency (build.gradle.kts:44) and can be used as an alternative in-memory database.
To switch to H2, update application.properties:
Validation constraints
The server enforces validation rules defined inConfiguration.java:8-10:
- MIN_PASSWORD_LENGTH:
6characters - MIN_USERNAME_LENGTH:
2characters - MAX_USERNAME_LENGTH:
8characters
Security configuration
The server uses Spring Security with the following features:- Password encoding: BCrypt (configured in
APIServerApplication.java:17-19) - JWT authentication: Token-based authentication with configurable expiration
- Endpoint security: Protected endpoints require valid JWT tokens
Server metadata
FromConfiguration.java:7:
- SERVER_VERSION:
0.0.1 - Used in API responses and OpenAPI documentation
Custom configuration
To override default settings, create anapplication-local.properties file: