# Local Development with Docker Compose This directory contains the configuration to run the Evrak application locally using Docker Compose. ## Prerequisites 1. **Docker Desktop**: Ensure Docker Desktop is installed and running on your machine. 2. **Ports**: Make sure ports 80, 3000, and 5432 are available on your host machine. ## Quick Start ### 1. Build and Start Services From the project root directory, run: ```bash docker compose -f deploy/local/docker-compose.yml up --build ``` Or in PowerShell: ```powershell docker compose -f deploy/local/docker-compose.yml up --build ``` This will: - Build the Docker images for backend and frontend - Start PostgreSQL database - Start the backend API server - Start the frontend web server ### 2. Access the Application Once all services are running, access the application at: * **Frontend**: http://localhost * **Backend API**: http://localhost:3000 * **Database**: localhost:5432 (user: `evrak_user`, password: `evrak_password`, database: `evrak`) ### 3. Stop Services To stop all services: ```bash docker compose -f deploy/local/docker-compose.yml down ``` To stop and remove volumes (database data): ```bash docker compose -f deploy/local/docker-compose.yml down -v ``` ## Development Workflow ### Running in Detached Mode To run services in the background: ```bash docker compose -f deploy/local/docker-compose.yml up -d --build ``` ### View Logs View logs from all services: ```bash docker compose -f deploy/local/docker-compose.yml logs -f ``` View logs from a specific service: ```bash docker compose -f deploy/local/docker-compose.yml logs -f backend docker compose -f deploy/local/docker-compose.yml logs -f frontend docker compose -f deploy/local/docker-compose.yml logs -f postgres ``` ### Rebuild After Code Changes If you make changes to the code, rebuild the affected service: ```bash docker compose -f deploy/local/docker-compose.yml up --build backend docker compose -f deploy/local/docker-compose.yml up --build frontend ``` ## Troubleshooting * **Ports occupied**: Ensure ports 80, 3000, and 5432 are free on your host machine. * **Build errors**: Make sure all dependencies are properly installed. Try removing `node_modules` and rebuilding. * **Database connection issues**: Wait a few seconds after starting services for the database to initialize. * **CORS errors**: The backend is configured to allow requests from `http://localhost:80`. If you're accessing from a different port, update the `FRONTEND_URL` environment variable in `docker-compose.yml`. ## Service Details - **PostgreSQL**: Database service with automatic health checks and schema initialization - The database schema (including ltree extension, indexes, and helper functions) is automatically initialized on first startup - Row Level Security (RLS) is **disabled** for local development to simplify testing - A default tenant is created automatically: `00000000-0000-0000-0000-000000000001` - **Backend**: NestJS API server running on port 3000 - Supports hierarchical project structure using PostgreSQL ltree - Multi-tenant architecture (RLS disabled for local dev) - **Frontend**: React application served via Nginx on port 80, with API proxying configured ## Database Schema The database is automatically initialized with: - PostgreSQL extensions: `uuid-ossp`, `ltree`, `pg_trgm` - Tables: `tenants`, `users`, `projects` - Indexes: GIST for ltree paths, GIN for JSONB attributes - Helper function: `move_project_subtree()` for moving project hierarchies **Note**: For production deployments, use `backend/src/database/schema.sql` which enables Row Level Security (RLS) for proper tenant isolation.