Skip to main content
wit is a Git-compatible version control system with an integrated hosting platform, built in TypeScript. This document provides a comprehensive overview of the system architecture.

System Context

High-Level Architecture

wit consists of four main layers:
LayerPurposeKey Technologies
CLICommand-line interfaceCommander.js, Ink
ServerHTTP, SSH, WebSocket serversHono, ssh2
CoreGit implementation, AI featuresCustom Git engine, Mastra
DataPersistence and storagePostgreSQL, Drizzle ORM

Directory Structure

src/
├── cli.ts              # CLI entry point
├── index.ts            # Library exports
├── commands/           # CLI command handlers (75+ commands)
├── core/               # Git implementation
│   ├── repository.ts   # Main Repository class
│   ├── object.ts       # Git objects (blob, tree, commit, tag)
│   ├── object-store.ts # Object persistence
│   ├── index.ts        # Staging area
│   ├── refs.ts         # References (branches, tags)
│   ├── protocol/       # Git protocols (Smart HTTP, SSH)
│   └── storage/        # Storage backends
├── server/             # Server infrastructure
│   ├── routes/         # HTTP endpoints
│   ├── ssh/            # SSH server
│   ├── middleware/     # Auth, rate limiting
│   └── sandbox/        # Code execution sandboxes
├── api/                # tRPC API layer
│   └── trpc/           # tRPC routers
├── db/                 # Database schema
│   ├── schema.ts       # Drizzle schema
│   └── auth-schema.ts  # Authentication tables
├── ai/                 # AI features
│   ├── agent.ts        # AI coding agent
│   ├── tools/          # Agent tools
│   └── workflows/      # Multi-step workflows
├── events/             # Event-driven architecture
│   ├── bus.ts          # Event bus
│   └── handlers/       # Event handlers
├── ui/                 # Terminal and web UI
├── search/             # Semantic code search
├── primitives/         # Core abstractions
└── ci/                 # CI/CD execution

Component Diagram

Key Architectural Decisions

1. Repository-Centric Design

The Repository class is the central abstraction for all Git operations:
class Repository {
  readonly gitDir: string;      // .wit directory
  readonly workDir: string;     // Working directory
  readonly objects: ObjectStore; // Git objects
  readonly index: Index;         // Staging area
  readonly refs: Refs;           // Branches, tags
  readonly journal: Journal;     // Undo history
  readonly mergeManager: MergeManager;
  readonly remotes: RemoteManager;
  // ... more managers
}
All operations flow through this class, ensuring consistent behavior across CLI, server, and AI features.

2. Event-Driven Architecture

The platform uses an event bus for loose coupling between components: Events trigger notifications, CI pipelines, webhooks, and activity logging without tight coupling.

3. Pluggable Storage

Storage backends are abstracted behind interfaces:
interface StorageBackend {
  read(path: string): Promise<Buffer>;
  write(path: string, data: Buffer): Promise<void>;
  exists(path: string): Promise<boolean>;
  delete(path: string): Promise<void>;
  list(prefix: string): Promise<string[]>;
}
Currently supports disk storage; S3 support planned.

4. Type-Safe API

The API layer uses tRPC for end-to-end type safety:
// Server
export const repoRouter = router({
  get: protectedProcedure
    .input(z.object({ owner: z.string(), name: z.string() }))
    .query(async ({ input }) => { ... }),
});

// Client - fully typed
const repo = await trpc.repo.get.query({ owner: 'user', name: 'repo' });

5. AI as First-Class Citizen

AI features are deeply integrated, not bolted on:
  • Commit messages: AI-generated from diffs
  • Code review: Automated PR analysis
  • Conflict resolution: AI-suggested resolutions
  • Semantic search: Vector-based code understanding
  • Coding agent: Autonomous code changes

Data Flow Examples

Push Operation

Pull Request Creation

Extension Points

Adding a New Command

  1. Create handler in src/commands/:
export async function myCommand(options: MyOptions) {
  const repo = await Repository.find(process.cwd());
  // Implementation
}
  1. Register in CLI (Commander.js)
  2. Add to command index

Adding an AI Tool

  1. Create tool in src/ai/tools/:
export const myTool = createTool({
  id: 'my-tool',
  description: 'Does something',
  inputSchema: z.object({ ... }),
  execute: async ({ input, context }) => { ... },
});
  1. Register in tools index
  2. Tool is automatically available to agents

Adding an Event Handler

  1. Create handler in src/events/handlers/:
export function registerMyHandlers() {
  eventBus.on('pr.created', async (event) => {
    // Handle event
  });
}
  1. Register in server startup

Adding an API Endpoint

  1. Create tRPC router in src/api/trpc/routers/:
export const myRouter = router({
  myProcedure: protectedProcedure
    .input(schema)
    .mutation(async ({ input, ctx }) => { ... }),
});
  1. Add to main app router

For Self-Hosters

Required Services

ServicePurposeRequired
PostgreSQLPlatform dataYes
RedisCaching (future)No
S3-compatibleObject storage (future)No
LLM APIAI featuresNo (for AI)

Environment Variables

# Required
DATABASE_URL=postgresql://user:pass@host:5432/wit

# Optional - AI features
ANTHROPIC_API_KEY=sk-...
OPENAI_API_KEY=sk-...

# Optional - External integrations
GITHUB_CLIENT_ID=...
GITHUB_CLIENT_SECRET=...

# Optional - Sandbox providers
E2B_API_KEY=...
DAYTONA_API_KEY=...

Deployment Architecture

For horizontal scaling, ensure:
  • Shared storage for Git repositories
  • Database connection pooling
  • Session affinity for WebSocket connections