Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/frontend #1

Merged
merged 4 commits into from
Jan 9, 2025
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
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
frontend/coverage
frontend/dist
frontend/node_modules
frontend/ssl

**/*.log
**/*.env
Expand Down
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ TAVILY_API_KEY=

## Langfuse observability settings
LANGFUSE_BASE_URL=
LANGFUSE_PROJECT_ID=
LANGFUSE_PUBLIC_KEY=
LANGFUSE_SECRET_KEY=

## OpenTelemetry observability settings
OTEL_HOST=
Expand Down
50 changes: 35 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,40 +41,45 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: '23'
cache: 'yarn'
cache-dependency-path: 'frontend/yarn.lock'
cache: 'npm'
cache-dependency-path: 'frontend/package-lock.json'

# Cache Yarn dependencies
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
# Cache npm dependencies
- name: Get npm cache directory
id: npm-cache-dir
run: echo "dir=$(npm config get cache)" >> $GITHUB_OUTPUT

- name: Cache Yarn packages
- name: Cache npm packages
uses: actions/cache@v3
id: yarn-cache
id: npm-cache
with:
path: |
${{ steps.yarn-cache-dir-path.outputs.dir }}
${{ steps.npm-cache-dir.outputs.dir }}
frontend/node_modules
key: ${{ runner.os }}-yarn-${{ hashFiles('frontend/yarn.lock') }}
key: ${{ runner.os }}-npm-${{ hashFiles('frontend/package-lock.json') }}
restore-keys: |
${{ runner.os }}-yarn-
${{ runner.os }}-npm-

# Frontend lint and test
- name: Frontend - Install dependencies
if: steps.yarn-cache.outputs.cache-hit != 'true'
if: steps.npm-cache.outputs.cache-hit != 'true'
working-directory: frontend
run: yarn install --frozen-lockfile
run: npm ci
continue-on-error: true

- name: Frontend - Prettier
working-directory: frontend
run: npm run prettier
continue-on-error: true

- name: Frontend - Lint
working-directory: frontend
run: yarn lint
run: npm run lint
continue-on-error: true

- name: Frontend - Test
working-directory: frontend
run: yarn test
run: npm run test
continue-on-error: true

# Backend lint and test
Expand All @@ -100,6 +105,21 @@ jobs:
run: go test ./... -v
continue-on-error: true

- name: Backend - Test Build
working-directory: backend
env:
CGO_ENABLED: 0
GO111MODULE: on
run: |
# Build for AMD64
GOOS=linux GOARCH=amd64 go build -trimpath -o /tmp/pentagi-amd64 ./cmd/pentagi
echo "βœ“ Successfully built for linux/amd64"

# Build for ARM64
GOOS=linux GOARCH=arm64 go build -trimpath -o /tmp/pentagi-arm64 ./cmd/pentagi
echo "βœ“ Successfully built for linux/arm64"
continue-on-error: true

docker-build:
needs: lint-and-test
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v')
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
backend/tmp
backend/build

frontend/coverage
frontend/dist
frontend/node_modules
frontend/ssl

build/*
data/*
Expand Down
12 changes: 10 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@
"program": "${workspaceFolder}/backend/cmd/pentagi/main.go",
"envFile": "${workspaceFolder}/.env",
"env": {
"CORS_ORIGINS": "http://localhost:8080,http://localhost:8000",
"CORS_ORIGINS": "http://localhost:*,https://localhost:*",
"PUBLIC_URL": "http://localhost:8080",
"STATIC_URL": "http://localhost:8000",
// Choose it instead of STATIC_URL to serve static files from a directory:
// "STATIC_DIR": "${workspaceFolder}/frontend/dist",
"SERVER_PORT": "8080",
"SERVER_USE_SSL": "false",
"DATABASE_URL": "postgres://postgres:postgres@localhost:5432/pentagidb?sslmode=disable",
// Langfuse (optional) uncomment to enable
// "LANGFUSE_BASE_URL": "http://localhost:4000",
// Observability (optional) uncomment to enable
// "OTEL_HOST": "localhost:8148"
},
"cwd": "${workspaceFolder}",
"output": "${workspaceFolder}/build/__debug_bin",
Expand All @@ -26,7 +32,9 @@
"runtimeArgs": ["run", "dev"],
"env": {
"VITE_API_URL": "localhost:8080",
"PORT": "8000",
"VITE_USE_HTTPS": "false",
"VITE_PORT": "8000",
"VITE_HOST": "0.0.0.0",
},
"cwd": "${workspaceFolder}/frontend",
},
Expand Down
35 changes: 28 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,42 @@
FROM node:23-slim as fe-build

ENV NODE_ENV=production
ENV VITE_BUILD_MEMORY_LIMIT=4096
ENV NODE_OPTIONS="--max-old-space-size=4096"

WORKDIR /frontend

COPY ./backend/pkg/graph/schema.graphqls ../backend/pkg/graph/
COPY frontend/ .

# Install dependencies with package manager detection for SBOM
RUN --mount=type=cache,target=/root/.yarn \
yarn install --frozen-lockfile --production=false

RUN yarn build
RUN --mount=type=cache,target=/root/.npm \
npm ci --include=dev

# Build frontend with optimizations and parallel processing
RUN npm run build -- \
--mode production \
--minify esbuild \
--outDir dist \
--emptyOutDir \
--sourcemap false \
--target es2020

# STEP 2: Build the backend
FROM golang:1.23-alpine as be-build
ENV CGO_ENABLED=1
RUN apk add --no-cache gcc musl-dev
FROM golang:1.23-bookworm as be-build

ENV CGO_ENABLED=0
ENV GO111MODULE=on

# Install build essentials
RUN apt-get update && apt-get install -y \
ca-certificates \
tzdata \
gcc \
g++ \
make \
git \
musl-dev

WORKDIR /backend

Expand All @@ -29,6 +49,7 @@ COPY backend/ .
RUN --mount=type=cache,target=/go/pkg/mod \
go mod download

# Build backend
RUN go build -trimpath -o /pentagi ./cmd/pentagi

# STEP 3: Build the final image
Expand Down
57 changes: 39 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

## πŸ“– Table of Contents

- [Overview](#overview)
- [Features](#features)
- [Quick Start](#quick-start)
- [Advanced Setup](#advanced-setup)
- [Development](#development)
- [Building](#building)
- [Credits](#credits)
- [License](#license)
- [Overview](#-overview)
- [Features](#-features)
- [Quick Start](#-quick-start)
- [Advanced Setup](#-advanced-setup)
- [Development](#-development)
- [Building](#%EF%B8%8F-building)
- [Credits](#-credits)
- [License](#-license)

## 🎯 Overview

Expand Down Expand Up @@ -55,15 +55,15 @@ flowchart TB
pentagi["✨ PentAGI
(Autonomous penetration testing system)"]

target["🎯 Target System
target["🎯 target-system
(System under test)"]
llm["🧠 LLM Provider
llm["🧠 llm-provider
(OpenAI/Anthropic/Custom)"]
search["πŸ” Search Systems
search["πŸ” search-systems
(Google/Tavily/Traversaal)"]
langfuse["πŸ“Š Langfuse UI
langfuse["πŸ“Š langfuse-ui
(LLM Observability Dashboard)"]
grafana["πŸ“ˆ Grafana
grafana["πŸ“ˆ grafana
(System Monitoring Dashboard)"]

pentester --> |Uses HTTPS| pentagi
Expand Down Expand Up @@ -478,6 +478,9 @@ Langfuse provides advanced capabilities for monitoring and analyzing AI agent op

```bash
LANGFUSE_BASE_URL=http://langfuse-web:3000
LANGFUSE_PROJECT_ID= # default: value from ${LANGFUSE_INIT_PROJECT_ID}
LANGFUSE_PUBLIC_KEY= # default: value from ${LANGFUSE_INIT_PROJECT_PUBLIC_KEY}
LANGFUSE_SECRET_KEY= # default: value from ${LANGFUSE_INIT_PROJECT_SECRET_KEY}
```

3. Run the Langfuse stack:
Expand Down Expand Up @@ -544,6 +547,7 @@ For using Google OAuth you need to create a new OAuth application in your Google
- nodejs
- docker
- postgres
- commitlint

### Environment Setup

Expand Down Expand Up @@ -595,9 +599,23 @@ For running tests `cd backend && go test -v ./...`

#### Frontend Setup

Run once `cd frontend && npm run predev` to install needed packages.
Run once `cd frontend && npm install` to install needed packages.

For generating graphql files have to run `npm run codegen` which using `codegen.yml` file.
For generating graphql files have to run `npm run graphql:generate` which using `graphql-codegen.ts` file.

Be sure that you have `graphql-codegen` installed globally:

```bash
npm install -g graphql-codegen
```

After that you can run:
* `npm run prettier` to check if your code is formatted correctly
* `npm run prettier:fix` to fix it
* `npm run lint` to check if your code is linted correctly
* `npm run lint:fix` to fix it

For generating SSL certificates you need to run `npm run ssl:generate` which using `generate-ssl.ts` file or it will be generated automatically when you run `npm run dev`.

#### Backend Configuration

Expand All @@ -613,7 +631,9 @@ Optional:

Edit the configuration for `frontend` in `.vscode/launch.json` file:
- `VITE_API_URL` - Backend API URL. *Omit* the URL scheme (e.g., `localhost:8080` *NOT* `http://localhost:8080`)
- `PORT` - Port to run the server (default: `8000`)
- `VITE_USE_HTTPS` - Enable SSL for the server (default: `false`)
- `VITE_PORT` - Port to run the server (default: `8000`)
- `VITE_HOST` - Host to run the server (default: `0.0.0.0`)

### Running the Application

Expand All @@ -629,8 +649,9 @@ Run the command(s) in `backend` folder:
#### Frontend

Run the command(s) in `frontend` folder:
- Run `yarn` to install the dependencies
- Run `yarn dev` to run the web app
- Run `npm install` to install the dependencies
- Run `npm run dev` to run the web app
- Run `npm run build` to build the web app

Open your browser and visit the web app URL.

Expand Down
45 changes: 23 additions & 22 deletions backend/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,33 @@ require (
github.com/pressly/goose/v3 v3.19.2
github.com/shirou/gopsutil/v3 v3.23.12
github.com/sirupsen/logrus v1.9.3
github.com/stretchr/testify v1.9.0
github.com/stretchr/testify v1.10.0
github.com/swaggo/gin-swagger v1.3.0
github.com/swaggo/swag v1.8.7
github.com/tmc/langchaingo v0.1.13-pre.0
github.com/vektah/gqlparser/v2 v2.5.14
github.com/xeipuuv/gojsonschema v1.2.0
go.opentelemetry.io/otel v1.32.0
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.8.0
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.32.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.32.0
go.opentelemetry.io/otel/log v0.8.0
go.opentelemetry.io/otel/metric v1.32.0
go.opentelemetry.io/otel/sdk v1.32.0
go.opentelemetry.io/otel/sdk/log v0.8.0
go.opentelemetry.io/otel/sdk/metric v1.32.0
go.opentelemetry.io/otel/trace v1.32.0
go.opentelemetry.io/otel v1.33.0
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.9.0
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.33.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.33.0
go.opentelemetry.io/otel/log v0.9.0
go.opentelemetry.io/otel/metric v1.33.0
go.opentelemetry.io/otel/sdk v1.33.0
go.opentelemetry.io/otel/sdk/log v0.9.0
go.opentelemetry.io/otel/sdk/metric v1.33.0
go.opentelemetry.io/otel/trace v1.33.0
golang.org/x/crypto v0.31.0
golang.org/x/oauth2 v0.24.0
golang.org/x/sys v0.28.0
golang.org/x/sys v0.29.0
google.golang.org/api v0.183.0
google.golang.org/grpc v1.68.0
google.golang.org/grpc v1.69.2
)

require (
cloud.google.com/go/auth v0.5.1 // indirect
cloud.google.com/go/auth/oauth2adapt v0.2.2 // indirect
cloud.google.com/go/compute/metadata v0.5.0 // indirect
cloud.google.com/go/compute/metadata v0.5.2 // indirect
github.com/AssemblyAI/assemblyai-go-sdk v1.3.0 // indirect
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
Expand Down Expand Up @@ -97,7 +97,7 @@ require (
github.com/gorilla/css v1.0.0 // indirect
github.com/gorilla/securecookie v1.1.2 // indirect
github.com/gorilla/sessions v1.2.2 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.24.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.25.1 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9 // indirect
Expand Down Expand Up @@ -147,10 +147,11 @@ require (
gitlab.com/golang-commonmark/mdurl v0.0.0-20191124015652-932350d1cb84 // indirect
gitlab.com/golang-commonmark/puny v0.0.0-20191124015043-9f83538fa04f // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.32.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.32.0 // indirect
go.opentelemetry.io/proto/otlp v1.4.0 // indirect
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.55.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.33.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.33.0 // indirect
go.opentelemetry.io/proto/otlp v1.5.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/arch v0.7.0 // indirect
golang.org/x/exp v0.0.0-20231108232855-2478ac86f678 // indirect
Expand All @@ -159,9 +160,9 @@ require (
golang.org/x/sync v0.10.0 // indirect
golang.org/x/text v0.21.0 // indirect
golang.org/x/tools v0.22.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20241118233622-e639e219e697 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241118233622-e639e219e697 // indirect
google.golang.org/protobuf v1.35.2 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20250102185135-69823020774d // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250102185135-69823020774d // indirect
google.golang.org/protobuf v1.36.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gotest.tools/v3 v3.5.1 // indirect
nhooyr.io/websocket v1.8.7 // indirect
Expand Down
Loading
Loading