Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,11 @@ psql -U your_username -d worklenz_db -f database/sql/5_database_user.sql

5. Start the development servers:
```bash
# Terminal 1: Start the backend
# Backend (single command for build, watch, and auto-restart)
cd worklenz-backend
npm run dev
npm run dev:all

# Terminal 2: Start the frontend
# Frontend (in another terminal)
cd worklenz-frontend
npm run dev
```
Expand Down
28 changes: 13 additions & 15 deletions SETUP_THE_PROJECT.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,28 +91,26 @@ Getting started with development is a breeze! Follow these steps and you'll be c

6. **Run the Development Server:**

**Option 1: Combined development mode (Recommended)**

```bash
npm run dev
```

This starts the development server allowing you to work on the project.

7. **Run the Production Server:**

**a. Build the project:**

```bash
npm run build
npm run dev:all
```

This single command runs both the build watch process and the server with auto-restart. No need to run `npm run dev` and `npm start` separately.

This will compile the TypeScript code into JavaScript for production use.

**b. Start the production server:**

**Option 2: Separate commands**

```bash
# Terminal 1: Build and watch for changes
npm run dev

# Terminal 2: Start the server
npm start
```

The first option (`npm run dev:all`) is recommended as it simplifies the development workflow.

## Docker Setup (Alternative)

For an easier setup, you can use Docker and Docker Compose:
Expand Down
142 changes: 91 additions & 51 deletions worklenz-backend/README.md
Original file line number Diff line number Diff line change
@@ -1,77 +1,117 @@
# Worklenz Backend

This is the Express.js backend for the Worklenz project management application.
This is the Express.js/TypeScript backend for the Worklenz project management application.

## Prerequisites

- Node.js >= 20.0.0
- npm >= 8.11.0
- PostgreSQL >= 12

## Getting Started

Follow these steps to set up the backend for development:
### 1. Environment Configuration

Create a `.env` file from the template:

```bash
cp .env.template .env
```

Update the `.env` file with your specific configuration. Key variables include:

- **Database**: `DB_USER`, `DB_PASSWORD`, `DB_NAME`, `DB_HOST`, `DB_PORT`
- **Server**: `PORT`, `NODE_ENV`, `SESSION_SECRET`, `COOKIE_SECRET`
- **Frontend**: `FRONTEND_URL`, `SERVER_CORS`
- **Storage**: Configure either S3 or Azure Blob Storage
- **Authentication**: Google OAuth credentials if needed

### 2. Database Setup

Create and initialize the database:

```bash
# Create database
createdb worklenz_db

# Run SQL setup files in order
psql -U postgres -d worklenz_db -f database/sql/0_extensions.sql
psql -U postgres -d worklenz_db -f database/sql/1_tables.sql
psql -U postgres -d worklenz_db -f database/sql/indexes.sql
psql -U postgres -d worklenz_db -f database/sql/4_functions.sql
psql -U postgres -d worklenz_db -f database/sql/triggers.sql
psql -U postgres -d worklenz_db -f database/sql/3_views.sql
psql -U postgres -d worklenz_db -f database/sql/2_dml.sql
psql -U postgres -d worklenz_db -f database/sql/5_database_user.sql
```

1. **Configure Environment Variables:**
Or use the provided script:

- Create a copy of the `.env.example` file and name it `.env`.
- Update the required fields in `.env` with your specific configuration.
```bash
chmod +x database/00-init-db.sh
./database/00-init-db.sh
```

2. **Set up Database:**
- Create a new database named `worklenz_db` on your local PostgreSQL server.
- Update the database connection details in your `.env` file.
- Execute the SQL setup files in the correct order:

```bash
# From your PostgreSQL client or command line
psql -U your_username -d worklenz_db -f database/sql/0_extensions.sql
psql -U your_username -d worklenz_db -f database/sql/1_tables.sql
psql -U your_username -d worklenz_db -f database/sql/indexes.sql
psql -U your_username -d worklenz_db -f database/sql/4_functions.sql
psql -U your_username -d worklenz_db -f database/sql/triggers.sql
psql -U your_username -d worklenz_db -f database/sql/3_views.sql
psql -U your_username -d worklenz_db -f database/sql/2_dml.sql
psql -U your_username -d worklenz_db -f database/sql/5_database_user.sql
```

Alternatively, you can use the provided shell script:

```bash
# Make sure the script is executable
chmod +x database/00-init-db.sh
# Run the script (may need modifications for local execution)
./database/00-init-db.sh
```
### 3. Install Dependencies

3. **Install Dependencies:**
```bash
npm install
```

```bash
npm install
```
## Development

4. **Run the Development Server:**
### Quick Start

```bash
npm run dev
```
Run both build watch and server with auto-restart:

This starts the development server with hot reloading enabled.
```bash
npm run dev:all
```

5. **Build for Production:**
This single command replaces the need to run `npm run dev` and `npm start` separately. It:
- Builds the TypeScript code in development mode
- Watches for file changes and rebuilds automatically
- Runs the server with nodemon for auto-restart on changes

```bash
npm run build
```
### Alternative Development Commands

This will compile the TypeScript code into JavaScript for production use.
```bash
# Build and watch files only (no server)
npm run dev

6. **Start Production Server:**
# Build once for development
npm run build:dev

# Start server only (after building)
npm start
```

```bash
npm start
```
## NPM Scripts

| Script | Description |
|--------|-------------|
| `npm start` | Start the server |
| `npm run dev` | Build and watch files for development |
| `npm run dev:all` | Build, watch, and auto-restart server for development (recommended) |
| `npm run build` | Standard build |
| `npm run build:dev` | Development build |
| `npm run build:prod` | Production build with minification and compression |
| `npm test` | Run Jest tests |
| `npm run test:watch` | Run tests in watch mode |
| `npm run clean` | Clean build directory |
| `npm run compile` | Compile TypeScript |
| `npm run compile:dev` | Compile TypeScript for development |
| `npm run watch` | Watch TypeScript and asset files |
| `npm run watch:ts` | Watch TypeScript files only |
| `npm run watch:assets` | Watch asset files only |

## API Documentation

The API endpoints are organized into logical controllers and follow RESTful design principles. The main API routes are prefixed with `/api/v1`.
The API follows RESTful design principles with endpoints prefixed with `/api/`.

### Authentication

Authentication is handled via JWT tokens. Protected routes require a valid token in the Authorization header.
The API uses JWT tokens for authentication. Protected routes require a valid token in the Authorization header.

### File Storage

Expand All @@ -93,4 +133,4 @@ npm test

## Docker Support

The backend can be run in a Docker container. See the main project README for Docker setup instructions.
The backend can be run in a Docker container. See the main project README for Docker setup instructions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,20 @@

BEGIN;

-- Add manual progress fields to tasks table
ALTER TABLE tasks
ADD COLUMN IF NOT EXISTS manual_progress BOOLEAN DEFAULT FALSE,
ADD COLUMN IF NOT EXISTS progress_value INTEGER DEFAULT NULL,
ADD COLUMN IF NOT EXISTS weight INTEGER DEFAULT NULL;
-- Create ENUM type for progress modes
CREATE TYPE PROGRESS_MODE_TYPE AS ENUM ('manual', 'weighted', 'time', 'default');

-- Alter tasks table to use ENUM type
ALTER TABLE tasks
ADD COLUMN IF NOT EXISTS manual_progress BOOLEAN DEFAULT FALSE,
ADD COLUMN IF NOT EXISTS progress_value INTEGER DEFAULT NULL,
ADD COLUMN IF NOT EXISTS progress_mode PROGRESS_MODE_TYPE DEFAULT 'default',
ADD COLUMN IF NOT EXISTS weight INTEGER DEFAULT NULL;

ALTER TABLE projects
ADD COLUMN IF NOT EXISTS use_manual_progress BOOLEAN DEFAULT FALSE,
ADD COLUMN IF NOT EXISTS use_weighted_progress BOOLEAN DEFAULT FALSE,
ADD COLUMN IF NOT EXISTS use_time_progress BOOLEAN DEFAULT FALSE;

-- Update function to consider manual progress
CREATE OR REPLACE FUNCTION get_task_complete_ratio(_task_id uuid) RETURNS json
Expand Down
13 changes: 11 additions & 2 deletions worklenz-backend/database/sql/1_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ CREATE TYPE SCHEDULE_TYPE AS ENUM ('daily', 'weekly', 'yearly', 'monthly', 'ever

CREATE TYPE LANGUAGE_TYPE AS ENUM ('en', 'es', 'pt', 'alb', 'de', 'zh_cn', 'ko');

CREATE TYPE PROGRESS_MODE_TYPE AS ENUM ('manual', 'weighted', 'time', 'default');

-- START: Users
CREATE SEQUENCE IF NOT EXISTS users_user_no_seq START 1;

Expand Down Expand Up @@ -777,7 +779,10 @@ CREATE TABLE IF NOT EXISTS projects (
estimated_man_days INTEGER DEFAULT 0,
hours_per_day INTEGER DEFAULT 8,
health_id UUID,
estimated_working_days INTEGER DEFAULT 0
estimated_working_days INTEGER DEFAULT 0,
use_manual_progress BOOLEAN DEFAULT FALSE NOT NULL,
use_weighted_progress BOOLEAN DEFAULT FALSE NOT NULL,
use_time_progress BOOLEAN DEFAULT FALSE NOT NULL
);

ALTER TABLE projects
Expand Down Expand Up @@ -1414,7 +1419,11 @@ CREATE TABLE IF NOT EXISTS tasks (
priority_sort_order INTEGER DEFAULT 0 NOT NULL,
phase_sort_order INTEGER DEFAULT 0 NOT NULL,
billable BOOLEAN DEFAULT TRUE,
schedule_id UUID
schedule_id UUID,
manual_progress BOOLEAN DEFAULT FALSE NOT NULL,
progress_value INTEGER DEFAULT NULL,
progress_mode PROGRESS_MODE_TYPE DEFAULT 'default' NOT NULL,
weight INTEGER DEFAULT NULL
);

ALTER TABLE tasks
Expand Down
Loading