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
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,11 @@ MAX_CONCURRENT_JOBS=2
# token with no extra permissions is enough (public repositories only).
# GITHUB_TOKEN=github_pat_...

# Optional: Postgres (e.g. Neon) for saved reports, share links and a
# cache that survives restarts. Tables are created on startup.
# DATABASE_URL=postgresql://user:password@host/db?sslmode=require
REPORT_RETENTION_DAYS=30

# Optional: reuse reports when the same GitHub commit or the same ZIP is
# analyzed again (in memory; cleared on restart). 0 entries = no caching.
REPORT_CACHE_MAX_ENTRIES=50
Expand Down Expand Up @@ -360,8 +365,19 @@ SAVE_DEBUG_ARTIFACTS=false
| `POST` | `/api/analyze/github` | JSON `{ "url": "https://github.com/owner/repo", "force"?: true }`. Public repositories only; checked on GitHub before the job starts. |
| `GET` | `/api/jobs/:id/events` | Server-Sent Events: `progress`, then `completed` (report + markdown) or `failed` (error body). |
| `GET` | `/api/jobs/:id` | Current job state as JSON. |
| `POST` | `/api/reports/:reportId/share` | Create a public link for a saved report. Returns `{ shareId, expiresAt, ownerToken }` (the token only the first time). |
| `GET` | `/api/shared/:shareId` | A shared report. |
| `DELETE` | `/api/shared/:shareId` | Remove the link. Header `Authorization: Bearer <ownerToken>`. |
| `GET` | `/api/health` | Health check. |

## Saved and Shared Reports

With `DATABASE_URL` set, every finished report is saved in Postgres for `REPORT_RETENTION_DAYS` (default 30) and also serves as the report cache, so it survives restarts.

A report becomes public only when the user clicks **Share**: it then gets a link like `/r/<shareId>` (128-bit random id, not indexed by search engines). The browser that shared it keeps a secret token (only its SHA-256 is stored) and can **Stop sharing** at any time. Expired reports and links are deleted automatically.

Without a database, reports are cached in memory only and sharing is unavailable.

Both analyze endpoints return a `jobId` to follow:

- `202` a new analysis started
Expand Down Expand Up @@ -414,7 +430,6 @@ Each analysis runs as its own job, so concurrent users never see each other's pr
## Version 2.0

- User Authentication
- Saved Reports
- Analysis History
- GitHub OAuth
- Repository Comparison
Expand Down
5 changes: 5 additions & 0 deletions apps/backend/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ MAX_CONCURRENT_JOBS=2
# A fine-grained token with no extra permissions is enough (public repos only).
# GITHUB_TOKEN=

# Postgres (e.g. Neon) for saved reports, share links and a restart-proof
# cache. Tables are created on startup. Leave unset to keep everything in memory.
# DATABASE_URL=postgresql://user:password@host/db?sslmode=require
REPORT_RETENTION_DAYS=30

# Reuse reports when the same GitHub commit or ZIP is analyzed again
# (in memory; cleared on restart). 0 entries = no caching.
REPORT_CACHE_MAX_ENTRIES=50
Expand Down
168 changes: 168 additions & 0 deletions apps/backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions apps/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
"eval": "tsx scripts/eval.ts"
},
"devDependencies": {
"@electric-sql/pglite": "0.5.15",
"@types/cors": "^2.8.19",
"@types/multer": "^2.1.0",
"@types/pg": "8.23.1",
"@types/yauzl": "^2.10.3",
"@types/yazl": "^3.3.1",
"tsx": "^4.22.4",
Expand All @@ -27,6 +29,7 @@
"express": "^5.2.1",
"express-rate-limit": "8.7.3",
"multer": "^2.2.0",
"pg": "8.23.1",
"typescript": "^6.0.3",
"yauzl": "^2.10.0",
"zod": "^4.4.3"
Expand Down
3 changes: 3 additions & 0 deletions apps/backend/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import cors from "cors";
import analyzeRouter from "./routes/analyze.js";
import healthRouter from "./routes/health.js";
import jobsRouter from "./routes/jobs.js";
import reportsRouter from "./routes/reports.js";
import { CorsError, toErrorResponse } from "./http/error-response.js";
import { env } from "./config/env.js";

Expand Down Expand Up @@ -36,6 +37,8 @@ app.use("/api", analyzeRouter);

app.use("/api/jobs", jobsRouter);

app.use("/api", reportsRouter);

app.use("/api/health", healthRouter);

app.use((_req, res) => {
Expand Down
7 changes: 4 additions & 3 deletions apps/backend/src/application/analysis-job.runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { downloadRepositoryZip } from "../github/github.client.js";
import { MAX_UPLOAD_SIZE } from "../constants/upload.js";
import { reportCache } from "../cache/report-cache.js";

import type { AnalysisSource, JobContext } from "../jobs/job.types.js";
import type { AnalysisSource, JobContext, JobResult } from "../jobs/job.types.js";
import type { RepositoryInfo } from "../types/repository-info.js";

const DOWNLOAD_DIRECTORY = "tmp/uploads";
Expand Down Expand Up @@ -93,7 +93,7 @@ export async function runAnalysisJob(
// Deletes the ZIP and extracted files when done.
const result = await analyzeUploadedRepository(zipPath, context, repository);

const jobResult = {
const jobResult: JobResult = {
report: result.report,
markdown: result.markdown,
repository,
Expand All @@ -102,7 +102,8 @@ export async function runAnalysisJob(
};

if (options.cacheKey) {
await reportCache.save(options.cacheKey, jobResult);
// With a database, the saved report's id enables sharing.
jobResult.reportId = await reportCache.save(options.cacheKey, jobResult);
}

jobStore.complete(jobId, jobResult);
Expand Down
Loading
Loading