High-level overview
Architecture principles
Type Safety
End-to-end type safety from database to UI using TypeScript, Drizzle, and tRPC.
Monorepo Structure
Shared code in packages, apps as thin integration layers.
API-First Design
All business logic exposed through tRPC procedures.
Modern Stack
Bun runtime, Next.js, Hono, and serverless-ready architecture.
System components
Applications
Web App (apps/web)
- Framework: Next.js 16 with React 19
- Port: 3001
- Purpose: Authenticated web console for managing skills and graph
- Key features:
- Skill browser and editor
- Graph visualization with D3
- Account management
- OAuth authentication
The web app uses Next.js App Router with React Server Components.
Server (apps/server)
- Framework: Hono
- Port: 3000
- Purpose: API host for Better Auth and tRPC endpoints
- Endpoints:
/api/auth/*- Better Auth routes/trpc/*- tRPC router
Hono is a lightweight, fast web framework designed for edge runtimes.
CLI (apps/cli)
- Framework: Native Bun with @clack/prompts
- Purpose: Command-line interface for skill management
- Key features:
- Interactive prompts
- Local skill editing
- tRPC client for server communication
Shared packages
API (packages/api)
- Purpose: tRPC router and business logic
- Exports:
AppRoutertype (shared with clients)- tRPC procedures for skills, mentions, links
- Key concepts:
- Procedures are the API “endpoints”
- Context provides auth and database access
- All domain logic lives here
Auth (packages/auth)
- Purpose: Better Auth configuration and adapter
- Features:
- Google and GitHub OAuth
- Session management
- Drizzle adapter for user storage
- Default skills sync
Database (packages/db)
- Purpose: Drizzle ORM schema and migrations
- Exports:
- Database schema definitions
- Drizzle client instance
- Query helpers
- Tables:
- Users, accounts, sessions (Better Auth)
- Skills and skill metadata
- Graph links and mentions
Environment (packages/env)
- Purpose: Typed runtime environment validation
- Exports:
@better-skills/env/server@better-skills/env/web@better-skills/env/cli
- Technology: Zod schemas with T3 Env
Config (packages/config)
- Purpose: Shared TypeScript configuration
- Exports: Base
tsconfig.jsonfor all packages
Markdown (packages/markdown)
- Purpose: Markdown parsing and mention extraction
- Features:
- Extract
@mentionsyntax from markdown - Sync auto-generated links
- Preserve manual vs. auto-generated link metadata
- Extract
Data flow
Skill creation flow
Business logic
packages/api validates and processes the skill:- Parse markdown for mentions
- Validate mention ownership
- Create skill record
Authentication flow
Session creation
Better Auth:
- Creates or updates user in database
- Creates session
- Sets session cookie
Request lifecycle
tRPC request
Better Auth request
Build system
Better Skills uses Turborepo for efficient builds:Build pipeline
turbo.json
- Builds run in topological order (dependencies first)
- Outputs are cached locally and remotely
- Only changed packages rebuild
Dependency graph
Deployment architecture
Production setup
Deployment targets
| Component | Platform | URL |
|---|---|---|
| Web | Vercel | https://better-skills.dev |
| Server | Vercel (or any Node.js host) | https://api.better-skills.dev |
| Database | Neon | Managed PostgreSQL |
| CLI | GitHub Releases | Installed via curl script |
Key design decisions
Why Bun?
- Fast: 3-4x faster than Node.js for common tasks
- All-in-one: Runtime, bundler, package manager
- Native TypeScript: No transpilation needed
- Modern APIs: Web-standard APIs (fetch, etc.)
Why monorepo?
- Code sharing: Packages used by multiple apps
- Type safety: Shared types across all apps
- Atomic changes: Update API and clients in one PR
- Developer experience: Single repo, single install
Why tRPC?
- Type safety: End-to-end types from server to client
- No codegen: Types derived directly from router
- Simple: Just TypeScript functions
- Framework agnostic: Works with Next.js, CLI, React Native
Why Drizzle?
- TypeScript-first: Schema as code
- Lightweight: No overhead, generates clean SQL
- Migrations: Built-in migration system
- Type-safe queries: Full IntelliSense for queries
Security considerations
Authentication
Authentication
- OAuth-only (no passwords stored)
- Session cookies with secure flags
- CSRF protection via Better Auth
Authorization
Authorization
Data validation
Data validation
- All inputs validated with Zod schemas
- Environment variables validated at startup
- SQL injection prevented by Drizzle ORM
CORS
CORS
CORS_ORIGINwhitelist in server config- Credentials included for cookie-based auth
Next steps
Monorepo Structure
Deep dive into workspace organization
Tech Stack
Explore technologies in detail
Development Setup
Get started with development
Database Setup
Configure your database