Skip to content
Open
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
25 changes: 15 additions & 10 deletions backend/.env.sample
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Server Configuration Variables
NODE_ENV=...
PORT=...
NODE_ENV=development
PORT=3000

# Firebase Configuration Variables
FIREBASE_API_KEY=...
Expand All @@ -10,30 +10,35 @@ FIREBASE_STORAGE_BUCKET=...
FIREBASE_MESSAGING_SENDER_ID=...
FIREBASE_APP_ID=...
FIREBASE_MEASUREMENT_ID=...
FIREBASE_DATABASE_URL=...

# OAuth
# Google OAuth
GOOGLE_CLIENT_ID=...
GOOGLE_CLIENT_SECRET=...

# GitHub OAuth
GITHUB_CLIENT_ID=...
GITHUB_CLIENT_SECRET=...

# Application URLs
FRONTEND_URL=...
BACKEND_URL=...
FRONTEND_URL=http://localhost:3001
BACKEND_URL=http://localhost:3000

# JWT Settings
JWT_SECRET=...

# ALGOLIA Search API
# Algoria Search API
ALGOLIA_APP_ID=...
ALGOLIA_API_KEY=...
ALGOLIA_INDEX_NAME=...

# Stripe Configuration
# Stripe Configuration Variables
STRIPE_SECRET_KEY=...
STRIPE_WEBHOOK_SECRET=...
STRIPE_PRICE_ID=...
STRIPE_TEST_MODE=true
STRIPE_TEST_MODE=...


# Gemini configuration
GEMINI_API_KEY=...
# AI Configuration Variables
GEMINI_API_KEY=...
TOGETHER_API_KEY=...
17 changes: 17 additions & 0 deletions backend/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
services:
postgres:
image: postgres:latest
container_name: summarizz_postgres
restart: unless-stopped
environment:
POSTGRES_USER: summarizz
POSTGRES_PASSWORD: summarizz
POSTGRES_DB: summarizz
POSTGRES_INITDB_ARGS: "--encoding=UTF-8 --lc-collate=C --lc-ctype=C"
ports:
- "5433:5433"
Comment on lines +11 to +12
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix PostgreSQL port mapping

The container’s default Postgres port is 5432, so mapping "5433:5433" won’t expose the database. Change to map host port 5433 to container port 5432:

 ports:
-  - "5433:5433"
+  - "5433:5432"
🤖 Prompt for AI Agents
In backend/docker-compose.yml around lines 11 to 12, the port mapping for
PostgreSQL is incorrect because it maps host port 5433 to container port 5433,
but the container uses the default port 5432. Update the port mapping to
"5433:5432" to expose the container's PostgreSQL service correctly on host port
5433.

volumes:
- postgres_data:/var/lib/postgresql/data

volumes:
postgres_data:
91 changes: 91 additions & 0 deletions backend/justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
export CONFIG_SCRIPT := "./scripts/config.sh"

alias s := setup
alias b := build
alias c := clean
alias t := test
alias rd := run-dev
alias rp := run-prod

default:
just --list

# NOTE: Cleans build artifacts and deletes node_modules
clean:
#!/usr/bin/env bash
source $CONFIG_SCRIPT

info "Cleaning build artifacts and node_modules..."
items=("node_modules" "dist" "coverage" ".eslintcache" ".cache" ".nyc_output" "package-lock.json" "yarn.lock" "pnpm-lock.yaml")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider preserving package lock files.

Removing package lock files (package-lock.json, yarn.lock, pnpm-lock.yaml) can lead to inconsistent dependency versions across different environments and developers. These files ensure reproducible builds.

Consider removing lock files from the clean list or creating a separate recipe for deep cleaning:

-    items=("node_modules" "dist" "coverage" ".eslintcache" ".cache" ".nyc_output" "package-lock.json" "yarn.lock" "pnpm-lock.yaml")
+    items=("node_modules" "dist" "coverage" ".eslintcache" ".cache" ".nyc_output")

Alternatively, add a deep-clean recipe that includes lock file removal for when it's explicitly needed.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
items=("node_modules" "dist" "coverage" ".eslintcache" ".cache" ".nyc_output" "package-lock.json" "yarn.lock" "pnpm-lock.yaml")
items=("node_modules" "dist" "coverage" ".eslintcache" ".cache" ".nyc_output")
🤖 Prompt for AI Agents
In backend/justfile at line 19, the current clean recipe removes package lock
files which can cause inconsistent dependency versions. To fix this, remove
"package-lock.json", "yarn.lock", and "pnpm-lock.yaml" from the items array so
they are preserved during normal cleaning. Optionally, create a separate
"deep-clean" recipe that includes these lock files for explicit deep cleaning
when needed.

for item in "${items[@]}"; do
if [[ "$item" == *.* ]]; then
find . -name "$item" -type f -exec rm -f "{}" + 2>/dev/null || true
else
find . -name "$item" -type d -prune -exec rm -rf "{}" + 2>/dev/null || true
fi
done


# NOTE: Best to run this before any other recipe to ensure a clean start
setup: clean
#!/usr/bin/env bash
source $CONFIG_SCRIPT

info "Setting up backend application with provided configuration..."
npm install

# NOTE: Builds the entire backend application for dev/prod runs
build:
#!/usr/bin/env bash
source $CONFIG_SCRIPT

info "Building backend application with provided configuration..."
npm run build

# NOTE: Runs the linter (eslint) to check for standards and code quality
lint:
#!/usr/bin/env bash
source $CONFIG_SCRIPT

info "Running linter with provided configuration..."
npm run lint

# NOTE: Runs tests using jest (optionally set --verbose flag)
test arg="default":
#!/usr/bin/env bash
source $CONFIG_SCRIPT

info "Running backend tests with provided argument: $arg..."
if [ -z "$arg" ]; then \
arg="default" \
fi

if [ "$arg" == "v" ] || [ "$arg" == "-v" ] || [ "$arg" == "--v" ] || [ "$arg" == "verbose" ]; then \
npm run test:verbose \
else \
npm run test \
fi

# NOTE: Runs all tasks in a sequence to setup respective backend environment
start arg="default": clean build lint (test arg)
#!/usr/bin/env bash
source $CONFIG_SCRIPT

info "Starting backend application with provided configuration..."
npm run start

# NOTE: Runs the respective backend environment in development mode (nodemon for hot reloading)
run-dev: clean build lint
#!/usr/bin/env bash
source $CONFIG_SCRIPT

info "Running backend application in development mode..."
npm run dev

# NOTE: Runs the respective backend environment in production mode (without nodemon, should only be used when deploying)
run-prod arg="default": clean build lint (test arg)
#!/usr/bin/env bash
source $CONFIG_SCRIPT

info "Running backend application in production mode..."
npm run start
3 changes: 2 additions & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"@algolia/client-search": "^5.20.4",
"@aws-sdk/client-s3": "^3.816.0",
"@aws-sdk/s3-request-presigner": "^3.816.0",
"@google/generative-ai": "^0.24.1",
"@google/genai": "^1.4.0",
"@langchain/core": "^0.3.57",
"@types/jsonwebtoken": "^9.0.7",
"algoliasearch": "^4.24.0",
Expand All @@ -53,6 +53,7 @@
"helmet": "^8.1.0",
"jsonwebtoken": "^9.0.2",
"stripe": "^18.1.1",
"together-ai": "^0.16.0",
"winston": "^3.17.0",
"zod": "^3.24.4"
}
Expand Down
53 changes: 53 additions & 0 deletions backend/scripts/config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env bash

set -e

if command -v tput >/dev/null 2>&1; then
COLOR_RESET=$(tput sgr0)
COLOR_RED=$(tput setaf 1)
COLOR_GREEN=$(tput setaf 2)
COLOR_YELLOW=$(tput setaf 3)
COLOR_BLUE=$(tput setaf 4)
COLOR_MAGENTA=$(tput setaf 5)
COLOR_CYAN=$(tput setaf 6)
COLOR_WHITE=$(tput setaf 7)
else
COLOR_RESET="\033[0m"
COLOR_RED="\033[0;31m"
COLOR_GREEN="\033[0;32m"
COLOR_YELLOW="\033[0;33m"
COLOR_BLUE="\033[0;34m"
COLOR_MAGENTA="\033[0;35m"
COLOR_CYAN="\033[0;36m"
COLOR_WHITE="\033[0;37m"
fi

PREFIX_INFO="${COLOR_BLUE}[INFO]${COLOR_RESET}"
PREFIX_WARN="${COLOR_YELLOW}[WARN]${COLOR_RESET}"
PREFIX_ERROR="${COLOR_RED}[ERROR]${COLOR_RESET}"
PREFIX_SUCCESS="${COLOR_GREEN}[SUCCESS]${COLOR_RESET}"
PREFIX_DEBUG="${COLOR_MAGENTA}[DEBUG]${COLOR_RESET}"

_get_current_timestamp() {
date "+%Y-%m-%d %H:%M:%S"
}

info() {
echo "${PREFIX_INFO} [$(_get_current_timestamp)] ${1}"
}

warn() {
echo "${PREFIX_WARN} [$(_get_current_timestamp)] ${COLOR_YELLOW}${1}${COLOR_RESET}" >&2
}

error() {
echo "${PREFIX_ERROR} [$(_get_current_timestamp)] ${COLOR_RED}${1}${COLOR_RESET}" >&2
}

success() {
echo "${PREFIX_SUCCESS} [$(_get_current_timestamp)] ${COLOR_GREEN}${1}${COLOR_RESET}"
}

debug() {
echo "${PREFIX_DEBUG} [$(_get_current_timestamp)] ${COLOR_MAGENTA}${1}${COLOR_RESET}"
}
2 changes: 1 addition & 1 deletion backend/scripts/deploy_test_pg_db.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

echo "Setting up test PostgreSQL database for Summarizz..."

Expand Down
19 changes: 15 additions & 4 deletions backend/scripts/test_data.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

-- Test data for Summarizz application
-- This script populates the database with test data for development purposes

Expand Down Expand Up @@ -245,9 +244,21 @@ CROSS JOIN (SELECT user_id FROM users ORDER BY random() LIMIT 1) u;

-- Update content metrics based on interactions
UPDATE content c
SET
likes = (SELECT COUNT(*) FROM user_content_interactions WHERE content_id = c.content_id AND interaction_type = 'like'),
shares = (SELECT COUNT(*) FROM user_content_interactions WHERE content_id = c.content_id AND interaction_type = 'share');
SET
likes = (
SELECT COUNT(*)
FROM user_content_interactions
WHERE
content_id = c.content_id
AND interaction_type = 'like'
),
shares = (
SELECT COUNT(*)
FROM user_content_interactions
WHERE
content_id = c.content_id
AND interaction_type = 'share'
);

-- Update comment like counts
UPDATE comments c
Expand Down
105 changes: 97 additions & 8 deletions backend/src/modules/ai/config/models.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,107 @@
import { AIModel, ModelConfig } from '../types';
import { AIGenerationModel, AIModel, GenerationModelConfig, ModelConfig } from '../types';
import { HarmBlockMethod, HarmBlockThreshold, HarmCategory } from '@google/genai';
import { SUMMARY_SYSTEM_PROMPT } from './prompts';

export const MODEL_CONFIGS: Record<AIModel, ModelConfig> = {
const MAX_OUTPUT_TOKENS = 1500;

export const SUMMARIZATION_MODEL_CONFIGS: Record<AIModel, ModelConfig> = {
[AIModel.Gemini20Flash]: {
safetySettings: [
{
method: HarmBlockMethod.SEVERITY,
category: HarmCategory.HARM_CATEGORY_HATE_SPEECH,
threshold: HarmBlockThreshold.BLOCK_LOW_AND_ABOVE
},
{
method: HarmBlockMethod.SEVERITY,
category: HarmCategory.HARM_CATEGORY_HATE_SPEECH,
threshold: HarmBlockThreshold.BLOCK_LOW_AND_ABOVE
},
{
method: HarmBlockMethod.SEVERITY,
category: HarmCategory.HARM_CATEGORY_HATE_SPEECH,
threshold: HarmBlockThreshold.BLOCK_LOW_AND_ABOVE
},
{
method: HarmBlockMethod.SEVERITY,
category: HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT,
threshold: HarmBlockThreshold.BLOCK_LOW_AND_ABOVE
}
],
Comment on lines +9 to +30
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix duplicate safety settings for hate speech.

Each model configuration contains three identical safety settings for HARM_CATEGORY_HATE_SPEECH. This appears to be a copy-paste error. You likely intended to block different harm categories.

Consider using different harm categories like:

       {
         method: HarmBlockMethod.SEVERITY,
         category: HarmCategory.HARM_CATEGORY_HATE_SPEECH,
         threshold: HarmBlockThreshold.BLOCK_LOW_AND_ABOVE
       },
       {
         method: HarmBlockMethod.SEVERITY,
-        category: HarmCategory.HARM_CATEGORY_HATE_SPEECH,
+        category: HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT,
         threshold: HarmBlockThreshold.BLOCK_LOW_AND_ABOVE
       },
       {
         method: HarmBlockMethod.SEVERITY,
-        category: HarmCategory.HARM_CATEGORY_HATE_SPEECH,
+        category: HarmCategory.HARM_CATEGORY_HARASSMENT,
         threshold: HarmBlockThreshold.BLOCK_LOW_AND_ABOVE
       },

Also applies to: 37-58, 65-86

🤖 Prompt for AI Agents
In backend/src/modules/ai/config/models.ts between lines 9 and 30, there are
three identical safety settings for HARM_CATEGORY_HATE_SPEECH, which is a
duplication error. Replace the duplicate entries with distinct harm categories
such as HARM_CATEGORY_HATE_SPEECH, HARM_CATEGORY_VIOLENCE, and
HARM_CATEGORY_SEXUALLY_EXPLICIT to cover different types of harm. Apply the same
fix to the similar duplicate blocks found in lines 37-58 and 65-86.

systemInstruction: SUMMARY_SYSTEM_PROMPT,
temperature: 0.2,
maxOutputTokens: 1500,
maxOutputTokens: MAX_OUTPUT_TOKENS,
topP: 1,
frequencyPenalty: 0.1,
presencePenalty: 0.1,
},
[AIModel.Gemini15Flash]: {
safetySettings: [
{
method: HarmBlockMethod.SEVERITY,
category: HarmCategory.HARM_CATEGORY_HATE_SPEECH,
threshold: HarmBlockThreshold.BLOCK_LOW_AND_ABOVE
},
{
method: HarmBlockMethod.SEVERITY,
category: HarmCategory.HARM_CATEGORY_HATE_SPEECH,
threshold: HarmBlockThreshold.BLOCK_LOW_AND_ABOVE
},
{
method: HarmBlockMethod.SEVERITY,
category: HarmCategory.HARM_CATEGORY_HATE_SPEECH,
threshold: HarmBlockThreshold.BLOCK_LOW_AND_ABOVE
},
{
method: HarmBlockMethod.SEVERITY,
category: HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT,
threshold: HarmBlockThreshold.BLOCK_LOW_AND_ABOVE
}
],
systemInstruction: SUMMARY_SYSTEM_PROMPT,
temperature: 0.2,
maxOutputTokens: MAX_OUTPUT_TOKENS,
topP: 1,
},
[AIModel.Gemini15FlashLite]: {
safetySettings: [
{
method: HarmBlockMethod.SEVERITY,
category: HarmCategory.HARM_CATEGORY_HATE_SPEECH,
threshold: HarmBlockThreshold.BLOCK_LOW_AND_ABOVE
},
{
method: HarmBlockMethod.SEVERITY,
category: HarmCategory.HARM_CATEGORY_HATE_SPEECH,
threshold: HarmBlockThreshold.BLOCK_LOW_AND_ABOVE
},
{
method: HarmBlockMethod.SEVERITY,
category: HarmCategory.HARM_CATEGORY_HATE_SPEECH,
threshold: HarmBlockThreshold.BLOCK_LOW_AND_ABOVE
},
{
method: HarmBlockMethod.SEVERITY,
category: HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT,
threshold: HarmBlockThreshold.BLOCK_LOW_AND_ABOVE
}
],
systemInstruction: SUMMARY_SYSTEM_PROMPT,
temperature: 0.2,
maxOutputTokens: 1500,
maxOutputTokens: MAX_OUTPUT_TOKENS,
topP: 1,
frequencyPenalty: 0.1,
presencePenalty: 0.1,
}
};

export const IMAGE_GENERATION_MODEL_CONFIGS: Record<AIGenerationModel, GenerationModelConfig> = {
[AIGenerationModel.Gemini20FlashImageGenPreview]: {

},
[AIGenerationModel.TogetherFlux1SchnellFree]: {

},
[AIGenerationModel.TogetherFlux1Schnell]: {

},
[AIGenerationModel.TogetherFlux1Dev]: {

}
};
Comment on lines +94 to 107
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add model configurations for image generation.

All image generation model configurations are empty. Based on the GenerationModelConfig interface, you should specify parameters like dimensions, steps, and safety settings.

Example configuration:

   [AIGenerationModel.Gemini20FlashImageGenPreview]: {
-
+    width: 1024,
+    height: 1024,
+    steps: 50,
+    responseFormat: 'url',
+    disableSafetyChecker: false
   },

Would you like me to help generate appropriate configurations for each model based on their capabilities?

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export const IMAGE_GENERATION_MODEL_CONFIGS: Record<AIGenerationModel, GenerationModelConfig> = {
[AIGenerationModel.Gemini20FlashImageGenPreview]: {
},
[AIGenerationModel.TogetherFlux1SchnellFree]: {
},
[AIGenerationModel.TogetherFlux1Schnell]: {
},
[AIGenerationModel.TogetherFlux1Dev]: {
}
};
export const IMAGE_GENERATION_MODEL_CONFIGS: Record<AIGenerationModel, GenerationModelConfig> = {
[AIGenerationModel.Gemini20FlashImageGenPreview]: {
width: 1024,
height: 1024,
steps: 50,
responseFormat: 'url',
disableSafetyChecker: false
},
[AIGenerationModel.TogetherFlux1SchnellFree]: {
},
[AIGenerationModel.TogetherFlux1Schnell]: {
},
[AIGenerationModel.TogetherFlux1Dev]: {
}
};
🤖 Prompt for AI Agents
In backend/src/modules/ai/config/models.ts between lines 94 and 107, the
IMAGE_GENERATION_MODEL_CONFIGS object has empty configurations for each model.
To fix this, fill in each model's configuration with appropriate properties
defined in the GenerationModelConfig interface, such as image dimensions, number
of steps, and safety settings. Use the models' capabilities to determine
suitable values for these parameters to ensure proper image generation behavior.

Loading