madison / open-git

public

Public repo for open-git repository.

485 files

on orgs

README.md

open-git

open-git is a GitHub-inspired code hosting app with stronger AI workflows, Stack Auth for authentication, and a shadcn/base-ui foundation.

Apps and Packages

  • apps/web - Next.js App Router application.
  • packages/ui - shared shadcn/base-ui components and global styles.
  • packages/code-storage - isomorphic-git + S3 SDK package.

Stack Auth

The app is wired for Stack Auth with:

  • apps/web/stack.ts - shared StackServerApp configuration.
  • apps/web/app/handler/[...stack]/page.tsx - Stack Auth catch-all handler.
  • apps/web/app/dashboard/page.tsx - example protected server route.
  • apps/web/.env.example - required environment variables.

Copy apps/web/.env.example to apps/web/.env.local and fill in values from Stack Auth:

NEXT_PUBLIC_STACK_PROJECT_ID=
STACK_SECRET_SERVER_KEY=
DATABASE_URL=postgresql://opengit:opengit@localhost:54329/opengit
CODE_STORAGE_BUCKET=opengit-code-storage
CODE_STORAGE_REGION=us-east-1
CODE_STORAGE_S3_ENDPOINT=http://localhost:9000
CODE_STORAGE_ACCESS_KEY_ID=opengit
CODE_STORAGE_SECRET_ACCESS_KEY=opengit_password
GIT_REMOTE_BASE_URL=http://localhost:4321
GIT_GATEWAY_PORT=4321
GIT_GATEWAY_CACHE_ROOT=.git-gateway-cache
OPEN_GIT_INTERNAL_AUTH_URL=http://localhost:3000/api/internal/repository-authorizations
OPEN_GIT_INTERNAL_AUTH_SECRET=replace-with-a-random-secret

The official initializer can be rerun after authenticating with Stack Auth:

npx @stackframe/stack-cli@latest init --mode create --output-dir apps/web --no-agent

Local Infrastructure

Stack Auth owns authentication and session identity. open-git owns product data that needs app-level invariants, starting with unique usernames.

The local development stack uses Postgres and MinIO:

  • compose.yaml - local Postgres and S3-compatible MinIO for OrbStack/Docker.
  • apps/web/db/schema.ts - schema definitions.
  • apps/web/db/index.ts - shared Drizzle client.
  • apps/web/db/user-profiles.ts - Stack Auth user to app profile helper.
  • apps/web/drizzle.config.ts - Drizzle migration config.
  • packages/code-storage - SDK that stores bare Git repositories in S3.

user_profiles.stack_user_id is unique and maps to user.id from Stack Auth. user_profiles.username is also unique, but nullable until the future onboarding flow lets a signed-in user reserve a username.

The onboarding flow lives at apps/web/app/onboarding. It validates usernames on the server, writes the unique username to Postgres, then sets clientReadOnlyMetadata.onboarded in Stack Auth after the database write succeeds.

Start all local infrastructure, then generate and apply migrations from the web app package:

pnpm infra:up
pnpm --filter web db:generate
pnpm --filter web db:migrate

Local Postgres runs on localhost:54329 with database, username, and password all set to opengit.

Local MinIO exposes the S3 API on localhost:9000 and the browser console on http://localhost:9001. The local bucket is created automatically as opengit-code-storage; the console login is opengit / opengit_password.

UI work: Docker infra + Next.js only (hot reload)

For day-to-day UI and app behavior, run Postgres and MinIO in Docker, then run only the web app so Next loads apps/web/.env.local and Turbopack hot-reloads.

pnpm infra:up
pnpm --filter web db:migrate   # after schema changes: db:generate then migrate
pnpm dev:web

Open http://localhost:3000. Do not use root pnpm dev unless you intend to start every package: the CLI runner expects ~/.opengit/runner.json, and git-worker / managed-runner need their own env and are not required for basic browsing and repository CRUD in the UI.

Repository pages read from a Postgres index (branches, file tree, README HTML). Creating or forking a repo indexes synchronously in the web app. After git push through the gateway, run the indexing worker so the UI catches up:

pnpm --filter web indexing-worker

To clone or push over Git from your machine, run the gateway in a second terminal (it uses the same env pattern as production; point DATABASE_URL and S3 variables at the same Docker services as in .env.local):

pnpm --filter git-gateway dev

Git HTTP Gateway

The Git gateway exposes normal HTTPS-style Git remotes backed by the same S3 repository storage:

pnpm --filter git-gateway dev
git clone http://localhost:4321/<username>/<repository>.git

Public repositories can be cloned without credentials. Private clones and pushes use HTTP Basic auth with your username and a Git token generated at /settings/developer/tokens.

Adding components

To add components to your app, run the following command at the root of your web app:

pnpm dlx shadcn@latest add button -c apps/web

This will place the ui components in the packages/ui/src/components directory.

Using components

To use the components in your app, import them from the ui package.

import { Button } from "@workspace/ui/components/button";