Skip to content

Itz-snj/hacktropica

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

16 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

SlothForge MVP

SlothForge is a living software factory that converts product ideas into deployed MVPs. It combines LLM-powered requirement extraction, automated ticket generation, intelligent build orchestration, and continuous drift detection to maintain alignment between specifications and implementation.

Overview

SlothForge automates the entire software development lifecycle:

  1. BRD Extraction: Chat with an LLM to extract structured Business Requirements Documents from product ideas
  2. Ticket Generation: Automatically generate epic/story hierarchies with acceptance criteria and dependency graphs
  3. Build Orchestration: Execute tickets in topological order, generating code that satisfies acceptance criteria
  4. Drift Detection: Compare PR implementations against acceptance criteria to detect gaps and bugs
  5. CI Integration: Trace test failures back to originating tickets and create bug tickets automatically

Architecture

SlothForge is built as a monorepo with the following structure:

slothforge-mvp/
β”œβ”€β”€ apps/
β”‚   β”œβ”€β”€ web/              # Next.js 14 frontend (port 3000)
β”‚   └── api/              # Fastify backend (port 3001)
β”œβ”€β”€ packages/
β”‚   β”œβ”€β”€ db/               # Prisma schema + generated client
β”‚   └── shared/           # TypeScript types + Zod schemas
β”œβ”€β”€ docker-compose.yml    # PostgreSQL + Redis services
β”œβ”€β”€ turbo.json           # Build pipeline configuration
└── pnpm-workspace.yaml  # Workspace definitions

Technology Stack

Layer Technology Purpose
Package Manager pnpm Fast, disk-efficient, first-class monorepo support
Monorepo Tool Turborepo Parallel task execution, build caching
Backend Runtime Node.js 20+ + TypeScript Async-first, rich LLM SDK ecosystem
API Framework Fastify Low overhead, built-in schema validation
ORM Prisma Type-safe DB access, migrations, JSONB support
Database PostgreSQL 16 JSONB for flexible metadata, strong transactions
Cache/Queue Redis 7 Async build jobs, prevents blocking API responses
Frontend Next.js 14 App Router SSE support, React Server Components
UI Library Tailwind CSS + shadcn/ui Fast, consistent, composable components
LLM SDK Vercel AI SDK Unified API across providers, structured output
LLM Provider Google Gemini Generous free tier, large context windows
Schema Validation Zod Runtime + compile-time safety for LLM outputs
Ticket Provider Linear Clean GraphQL API, free tier, webhooks
VCS Provider GitHub REST API + webhooks, widest adoption
Local Tunneling ngrok Expose local API for webhook testing

Prerequisites

Before setting up SlothForge, ensure you have the following installed:

Local Setup

Follow these steps to run SlothForge locally:

1. Clone the Repository

git clone <repository-url>
cd slothforge-mvp

2. Copy Environment Variables

cp .env.example .env

Edit .env and fill in your API keys (see Environment Configuration below).

3. Start Docker Services

Start PostgreSQL and Redis:

docker compose up -d

Verify services are running:

docker compose ps

You should see both slothforge-postgres and slothforge-redis with status "Up".

4. Install Dependencies

Install all workspace dependencies:

pnpm install

5. Run Database Migrations

Apply Prisma migrations to create database tables:

pnpm db:migrate

6. Start Development Servers

Start both frontend and backend in parallel:

pnpm dev

This will start:

Verify the API is running:

curl http://localhost:3001/health
# Should return: {"status":"ok"}

ngrok Setup

To receive webhooks from GitHub and Linear during local development, you need to expose your local API using ngrok.

1. Install ngrok

Download and install ngrok from ngrok.com/download.

2. Start ngrok Tunnel

In a new terminal window, run:

ngrok http 3001

You should see output like:

Forwarding  https://abc123.ngrok.io -> http://localhost:3001

3. Copy HTTPS URL

Copy the HTTPS forwarding URL (e.g., https://abc123.ngrok.io).

4. Set Environment Variable

Add the ngrok URL to your .env file:

NGROK_URL=https://abc123.ngrok.io

Note: The ngrok URL changes every time you restart ngrok (unless you have a paid plan). You'll need to update webhooks whenever the URL changes.

Webhook Registration

SlothForge receives webhooks from GitHub (for CI events) and Linear (for ticket updates).

GitHub Webhook Setup

  1. Go to your GitHub repository
  2. Navigate to Settings > Webhooks > Add webhook
  3. Set Payload URL to: https://your-ngrok-url.ngrok.io/webhooks/github
  4. Set Content type to: application/json
  5. Select Let me select individual events:
    • βœ… Pull requests
    • βœ… Pull request reviews
    • βœ… Workflow runs
    • βœ… Push
  6. Click Add webhook

Linear Webhook Setup

  1. Go to your Linear workspace
  2. Navigate to Settings > API > Webhooks
  3. Click New webhook
  4. Set URL to: https://your-ngrok-url.ngrok.io/webhooks/linear
  5. Select events:
    • βœ… Issue created
    • βœ… Issue updated
    • βœ… Issue deleted
  6. Click Create webhook

Project Structure

Monorepo Layout

slothforge-mvp/
β”œβ”€β”€ apps/
β”‚   β”œβ”€β”€ api/                          # Fastify backend
β”‚   β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”‚   β”œβ”€β”€ server.ts            # Main server entry point
β”‚   β”‚   β”‚   β”œβ”€β”€ lib/
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ prisma.ts        # Prisma client singleton
β”‚   β”‚   β”‚   β”‚   └── redis.ts         # Redis client singleton
β”‚   β”‚   β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”‚   β”‚   └── llm/
β”‚   β”‚   β”‚   β”‚       └── providers.ts # LLM model configurations
β”‚   β”‚   β”‚   └── adapters/
β”‚   β”‚   β”‚       β”œβ”€β”€ ticket/
β”‚   β”‚   β”‚       β”‚   └── LinearAdapter.ts
β”‚   β”‚   β”‚       └── vcs/
β”‚   β”‚   β”‚           └── GitHubAdapter.ts
β”‚   β”‚   └── package.json
β”‚   β”‚
β”‚   └── web/                          # Next.js frontend
β”‚       β”œβ”€β”€ src/
β”‚       β”‚   └── app/
β”‚       β”‚       β”œβ”€β”€ layout.tsx       # Root layout
β”‚       β”‚       β”œβ”€β”€ page.tsx         # Landing page
β”‚       β”‚       └── globals.css      # Global styles
β”‚       └── package.json
β”‚
β”œβ”€β”€ packages/
β”‚   β”œβ”€β”€ db/                           # Database layer
β”‚   β”‚   β”œβ”€β”€ prisma/
β”‚   β”‚   β”‚   └── schema.prisma        # Database schema
β”‚   β”‚   β”œβ”€β”€ index.ts                 # Prisma client export
β”‚   β”‚   └── package.json
β”‚   β”‚
β”‚   └── shared/                       # Shared types and schemas
β”‚       β”œβ”€β”€ src/
β”‚       β”‚   β”œβ”€β”€ types/               # TypeScript interfaces
β”‚       β”‚   β”œβ”€β”€ schemas/             # Zod validation schemas
β”‚       β”‚   └── index.ts             # Package exports
β”‚       └── package.json
β”‚
β”œβ”€β”€ docker-compose.yml                # Local infrastructure
β”œβ”€β”€ turbo.json                        # Turborepo configuration
β”œβ”€β”€ pnpm-workspace.yaml               # Workspace definitions
└── .env.example                      # Environment template

Database Schema

SlothForge uses PostgreSQL with 10 core tables:

  • Project: Core entity representing a SlothForge project
  • BRD: Business Requirements Document with structured fields
  • Ticket: Work items (epics and stories) with acceptance criteria
  • TicketEdge: Dependency relationships between tickets
  • DriftResult: Output of drift detection runs
  • DriftFeedback: User feedback on drift detection accuracy
  • CIEvent: CI pipeline events from webhooks
  • ProcessedEvent: Idempotency table for webhook deduplication
  • ReviewQueue: Human review queue for LLM failures

View the full schema in packages/db/prisma/schema.prisma.

Available Scripts

Root Level

Run these commands from the repository root:

Command Description
pnpm dev Start all applications in development mode (parallel)
pnpm build Build all applications for production
pnpm lint Run linters across all workspaces
pnpm test Run tests across all workspaces
pnpm db:migrate Run Prisma migrations on the database

Workspace-Specific

Run these commands with pnpm --filter <workspace>:

API (@slothforge/api)

pnpm --filter @slothforge/api dev          # Start API in watch mode
pnpm --filter @slothforge/api build        # Build API for production
pnpm --filter @slothforge/api test         # Run API tests
pnpm --filter @slothforge/api test:watch   # Run API tests in watch mode

Web (@slothforge/web)

pnpm --filter @slothforge/web dev          # Start Next.js dev server
pnpm --filter @slothforge/web build        # Build Next.js for production
pnpm --filter @slothforge/web start        # Start production server

Database (@slothforge/db)

pnpm --filter @slothforge/db migrate:dev   # Run migrations (dev)
pnpm --filter @slothforge/db migrate:deploy # Run migrations (prod)
pnpm --filter @slothforge/db studio        # Open Prisma Studio
pnpm --filter @slothforge/db generate      # Generate Prisma client
pnpm --filter @slothforge/db test          # Run database tests

Shared (@slothforge/shared)

pnpm --filter @slothforge/shared test      # Run shared package tests
pnpm --filter @slothforge/shared lint      # Lint shared package

Environment Configuration

SlothForge requires several environment variables for external service integrations. Copy .env.example to .env and fill in the following:

Application Configuration

Variable Default Description
NODE_ENV development Node environment (development, production, test)
PORT 3001 API server port

Database Configuration

Variable Required Description
DATABASE_URL βœ… PostgreSQL connection string
REDIS_URL βœ… Redis connection string

Local Development Values:

DATABASE_URL=postgresql://slothforge:slothforge_local@localhost:5432/slothforge
REDIS_URL=redis://localhost:6379

LLM Integration

Variable Required Description How to Obtain
GOOGLE_GENERATIVE_AI_API_KEY βœ… Google Gemini API key 1. Visit aistudio.google.com/app/apikey
2. Sign in with Google
3. Click "Create API Key"
4. Copy the generated key

External Service Integrations

Variable Required Description How to Obtain
LINEAR_API_KEY βœ… Linear API key for ticket management 1. Visit linear.app/settings/api
2. Navigate to "Personal API keys"
3. Click "Create key"
4. Copy the generated key
GITHUB_TOKEN βœ… GitHub Personal Access Token 1. Visit github.com/settings/tokens
2. Click "Generate new token (classic)"
3. Select scopes: repo (all), admin:repo_hook (all)
4. Click "Generate token"
5. Copy the token (save it securely!)
NGROK_URL βœ… ngrok HTTPS URL for webhooks 1. Install ngrok
2. Run ngrok http 3001
3. Copy the HTTPS forwarding URL

Development Workflow

Typical Development Session

  1. Start Infrastructure:

    docker compose up -d
  2. Start ngrok (in a separate terminal):

    ngrok http 3001
  3. Update NGROK_URL in .env with the new URL

  4. Start Development Servers:

    pnpm dev
  5. Open Prisma Studio (optional, in a separate terminal):

    pnpm --filter @slothforge/db studio

Making Database Changes

  1. Edit packages/db/prisma/schema.prisma
  2. Create a migration:
    pnpm db:migrate
  3. Prisma will prompt you to name the migration
  4. The migration is automatically applied to your local database

Adding Dependencies

Add dependencies to specific workspaces:

# Add to API
pnpm --filter @slothforge/api add <package-name>

# Add to Web
pnpm --filter @slothforge/web add <package-name>

# Add to Shared
pnpm --filter @slothforge/shared add <package-name>

# Add dev dependency
pnpm --filter @slothforge/api add -D <package-name>

Running Tests

# Run all tests
pnpm test

# Run tests for specific workspace
pnpm --filter @slothforge/api test

# Run tests in watch mode
pnpm --filter @slothforge/api test:watch

Troubleshooting

Port Already in Use

If you see "Port 3000 (or 3001) is already in use":

# Find and kill the process using the port
lsof -ti:3000 | xargs kill -9
lsof -ti:3001 | xargs kill -9

Docker Services Not Starting

If Docker services fail to start:

# Stop all services
docker compose down

# Remove volumes (WARNING: deletes all data)
docker compose down -v

# Start fresh
docker compose up -d

Database Connection Errors

If the API cannot connect to PostgreSQL:

  1. Verify Docker services are running: docker compose ps
  2. Check DATABASE_URL in .env matches docker-compose.yml
  3. Ensure migrations have been run: pnpm db:migrate

Prisma Client Not Found

If you see "Cannot find module '@prisma/client'":

# Regenerate Prisma client
pnpm --filter @slothforge/db generate

TypeScript Errors Across Workspaces

If you see import errors between workspaces:

# Rebuild all workspaces
pnpm build

ngrok URL Changed

If webhooks stop working after restarting ngrok:

  1. Copy the new ngrok HTTPS URL
  2. Update NGROK_URL in .env
  3. Update webhook URLs in GitHub and Linear settings
  4. Restart the API: pnpm --filter @slothforge/api dev

License

[Add your license here]

Contributing

[Add contributing guidelines here]

About

Demo Link

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages