A web server application built with the Odin programming language, featuring PostgreSQL database integration and JWT authentication.
- Prerequisites
- Installation
- Project Setup
- Running the Application
- Additional Commands
- Environment Variables
- Odin Compiler: The Odin programming language compiler
- PostgreSQL C Libraries (libpq): Required for database connectivity
- Docker & Docker Compose: For running the PostgreSQL database
- Make: For using the Makefile commands
brew install odin# Clone the Odin repository
git clone https://github.com/odin-lang/Odin
cd Odin
# Build the compiler
make
# Add to PATH (add this to your ~/.bashrc or ~/.zshrc)
export PATH=$PATH:/path/to/Odin- Download the latest release from Odin Releases
- Extract the archive to a directory (e.g.,
C:\Odin) - Add the Odin directory to your system PATH
odin versionThe application requires the PostgreSQL C libraries (libpq) to connect to the database.
# Install PostgreSQL (includes libpq)
brew install libpq
# Note the installation path (typically /opt/homebrew/Cellar/libpq/<version>/)
brew list libpqAfter installation, you need to set the library paths. The Makefile handles this automatically, but if you need to set them manually:
export LIBRARY_PATH="/opt/homebrew/Cellar/libpq/17.6/lib:$LIBRARY_PATH"
export CPATH="/opt/homebrew/Cellar/libpq/17.6/include:$CPATH"Note: Adjust the version number (17.6) to match your installed version.
sudo apt-get update
sudo apt-get install libpq-dev postgresql-clientsudo dnf install libpq-devel postgresql- Download and install PostgreSQL from postgresql.org
- Add the PostgreSQL
libandincludedirectories to your system PATH
-
Clone the repository (if not already done):
cd /path/to/coffee_server -
Configure environment variables:
The project includes a
.envfile with the following configuration:BINARY=odin-coffee PORT=8080 POSTGRES_USER=postgres POSTGRES_PASSWORD=password POSTGRES_DB=odin-coffee-db DB_PORT=5432 HOST=localhostModify these values as needed for your environment.
-
Ensure PostgreSQL library paths are correct:
Check the Makefile and update the libpq paths if your installation is in a different location:
# Find your libpq installation brew list libpq # macOS # or dpkg -L libpq-dev # Linux
Docker Compose is used to run the PostgreSQL database in a container.
docker compose up -dThis command will:
- Start a PostgreSQL 14.2 container
- Expose the database on port 5432
- Store data persistently in
./db/cached-db-data/postgres/ - Use the environment variables from your
.envfile
docker compose downdocker compose psdocker compose logs dev_dbThe Makefile provides convenient commands for running the application.
make runThis command will:
- Export the necessary library paths for PostgreSQL
- Compile and run the Odin application
make connect_to_dbThis command connects to the running PostgreSQL container using the psql client.
If you need to build without running:
export LIBRARY_PATH="/opt/homebrew/Cellar/libpq/17.6/lib:$LIBRARY_PATH"
export CPATH="/opt/homebrew/Cellar/libpq/17.6/include:$CPATH"
odin build ../coffee_serverIf you need to run migrations, you can use goose (if installed):
goose -dir ./migrations postgres "user=postgres dbname=odin-coffee-db sslmode=disable" upKey environment variables used by the application:
| Variable | Description | Default |
|---|---|---|
BINARY |
Container name for Docker | odin-coffee |
PORT |
Application port | 8080 |
POSTGRES_USER |
Database user | postgres |
POSTGRES_PASSWORD |
Database password | password |
POSTGRES_DB |
Database name | odin-coffee-db |
DB_PORT |
Database port | 5432 |
HOST |
Database host | localhost |
JWT_SECRET |
Secret key for JWT tokens | (see .env) |
APP_ENV |
Application environment | development |
coffee_server/
├── main.odin # Main application entry point
├── database.odin # Database connection and queries
├── Makefile # Build and run commands
├── docker-compose.yml # PostgreSQL container configuration
├── .env # Environment variables
├── helpers/ # Helper functions
├── services/ # Business logic services
├── types/ # Type definitions
├── migrations/ # Database migrations
└── odin-http/ # HTTP server library
If you encounter errors about missing PostgreSQL libraries:
-
Verify libpq installation:
brew list libpq # macOS -
Update the paths in the Makefile to match your installation
-
Set the environment variables manually:
export LIBRARY_PATH="/path/to/libpq/lib:$LIBRARY_PATH" export CPATH="/path/to/libpq/include:$CPATH"
-
Ensure Docker is running:
docker ps
-
Check if the database container is healthy:
docker compose ps
-
Verify the database is accepting connections:
make connect_to_db
If port 5432 or 3000 is already in use, update the .env file with different port numbers.
[Your License Here]
[Your Contributing Guidelines Here]