# Navix Backend - PostgreSQL Setup Guide ## Setup Instructions ### 1. Install PostgreSQL **Windows:** ```bash # Download from https://www.postgresql.org/download/windows/ # Or use chocolatey: choco install postgresql ``` **Linux/WSL:** ```bash sudo apt update sudo apt install postgresql postgresql-contrib ``` **macOS:** ```bash brew install postgresql ``` ### 2. Start PostgreSQL Service **Windows:** ```bash # PostgreSQL should start automatically as a service # Or start manually: pg_ctl -D "C:\Program Files\PostgreSQL\{version}\data" start ``` **Linux/WSL:** ```bash sudo service postgresql start ``` **macOS:** ```bash brew services start postgresql ``` ### 3. Create Database and Schema ```bash # Run the schema file as postgres superuser psql -U postgres -f backend/schema.sql # This will: # 1. Create a dedicated 'navix_user' database user # 2. Create the 'navix' database owned by navix_user # 3. Create all tables and schemas # 4. Grant appropriate privileges # IMPORTANT: Change the password in the SQL file before running! # Edit backend/schema.sql and change 'navix_secure_password_change_me' to a strong password ``` ### 4. Configure Environment Variables Copy `.env.example` to `.env` and update with your settings: ```bash cp .env.example .env ``` Edit `.env` with your actual database credentials and JWT secret key. ### 5. Install Python Dependencies ```bash cd backend pip install -r requirements.txt ``` ### 6. Run the Backend ```bash python main.py ``` ## API Endpoints ### Authentication - `POST /api/auth/register` - Register new user - `POST /api/auth/login` - Login and get JWT token - `GET /api/auth/me` - Get current user info (requires auth) ### Sections - `GET /api/sections` - Get all sections with apps (requires auth) - `POST /api/sections` - Create new section (requires auth) ### Apps - `POST /api/apps` - Create new app (requires auth) - `PUT /api/apps/{app_id}` - Update app (requires auth) - `DELETE /api/apps/{app_id}` - Delete app (requires auth) ### Legacy (YAML-based) - `GET /api/apps` - Get apps from YAML file - `POST /api/add_app` - Add app to YAML file - `POST /api/edit_app` - Edit app in YAML file - `POST /api/delete_app` - Delete app from YAML file ## Authentication Flow 1. **Register**: `POST /api/auth/register` with `{username, email, password}` 2. **Login**: `POST /api/auth/login` with `{username, password}` → Returns JWT token 3. **Use Token**: Include in Authorization header: `Bearer {token}` ## Testing with cURL ```bash # Register curl -X POST http://localhost:8000/api/auth/register \ -H "Content-Type: application/json" \ -d '{"username":"testuser","email":"test@example.com","password":"password123"}' # Login curl -X POST http://localhost:8000/api/auth/login \ -H "Content-Type: application/json" \ -d '{"username":"testuser","password":"password123"}' # Get sections (use token from login) curl -X GET http://localhost:8000/api/sections \ -H "Authorization: Bearer YOUR_TOKEN_HERE" ``` ## Database Schema - **users**: User accounts with authentication - **sections**: User-specific app sections - **apps**: Applications within sections Each user has their own personal view with their own sections and apps.