Overview
We use three primary style guides:- Go - Based on Google Go Style Guide
- TypeScript/React - Based on Google TypeScript Style Guide
- React Architecture - Based on bulletproof-react patterns
- golangci-lint for Go code
- Biome for TypeScript/React code
- Pre-commit hooks that run on every commit
Go Style Guide
Our Go code follows the Google Go Style Guide with project-specific adaptations.Key Conventions
Naming:- Exported names:
PascalCase(e.g.,NewService,RetryBudget) - Unexported names:
camelCase(e.g.,callExternal,retryCount) - Package names: lowercase, single word preferred (e.g.,
greeter,platform) - Acronyms: All uppercase or all lowercase (e.g.,
HTTP,ID,URL)
- Always check errors (enforced by
errcheck) - Use
errors.Is()anderrors.As()for error comparison - Wrap errors with context using
fmt.Errorf("...: %w", err) - Error strings start lowercase, no punctuation
goimports:
- Always make goroutine lifetimes explicit
- Use
context.Contextfor cancellation - Prefer
sync.WaitGrouporerrgroupover fire-and-forget goroutines
- Use table-driven tests for multiple test cases
- Call
t.Helper()in test helper functions
Enforcement
Run these commands to check and format Go code:- Format code with
goimports - Run
golangci-lint - Run tests with
go test
Complete Guide
For the full Go style guide with detailed examples and rationale, see:- docs/go-style-guide.md in the source repository
TypeScript Style Guide
Our TypeScript code follows the Google TypeScript Style Guide with project-specific adaptations.Key Conventions
File Naming:- Use kebab-case:
my-component.tsx - Test files:
.test.tsor.test.tsx
- Never use
any- useunknownwith type guards instead - Never use
objecttype - define specific interfaces - Use
import typefor type-only imports - Prefer type inference over explicit type annotations
- Avoid non-null assertions (
!) - use explicit checks
- Variables/functions:
camelCase(e.g.,userName,fetchData()) - Types/interfaces/classes:
PascalCase(e.g.,UserProfile,AuthService) - Constants:
CONSTANT_CASE(e.g.,MAX_RETRY_COUNT) - Files:
kebab-case(e.g.,auth-panel.tsx)
- Top-level named functions: use
functiondeclarations - Callbacks and nested functions: use arrow functions
- React components: use
functiondeclarations
- Always use
===and!==(never==or!=) - Always use braces, even for single-line statements
- Use optional chaining
?.instead of&&chains - No
var- onlyconstandlet - No default exports (except in config files)
Enforcement
Run these commands to check and format TypeScript code:- Format code with Biome
- Run
biome checkfor linting
Complete Guide
For the full TypeScript style guide with detailed examples, see:- docs/typescript-style-guide.md in the source repository
React Architecture (bulletproof-react)
Our React frontend follows the bulletproof-react architecture pattern.Directory Structure
Feature-First Design
Principles:- Each feature is an independent module
- No direct imports between features
- Shared code goes in
lib/ortypes/ - Each feature has
api/,components/,hooks/, andtypes/subdirectories
- api/ - External API communication logic
- components/ - UI components (depend on hooks/api only)
- hooks/ - Custom hooks wrapping API calls and state
- types/ - TypeScript type definitions
connect-query Integration
Query Pattern (greeter):Adding New Features
- Create
src/features/<feature-name>/directory - Add
types/index.tswith type definitions - Add
api/with API logic (REST withfetchor gRPC withconnect-query) - Add
hooks/with custom hooks - Add
components/with UI components - Import component in
App.tsx
Complete Guide
For the complete architecture guide with patterns and examples, see:- docs/bulletproof-react.md in the source repository
Automated Enforcement
Pre-commit Hooks
All style rules are enforced automatically through Git pre-commit hooks:- treefmt - Formats Nix files
- golangci-lint - Lints Go code
- goimports - Formats Go imports
- biome - Checks TypeScript/React code
- go test - Runs Go tests
devenv.nix and run automatically on git commit.
Manual Commands
CI/CD Integration
The same checks run in CI pipelines to ensure code quality before merging.Editor Configuration
VS Code
Recommended extensions:- Go (golang.go)
- Biome (biomejs.biome)
- Nix IDE (jnoortheen.nix-ide)
.vscode/settings.json):
Other Editors
Configure your editor to:- Run
goimportson save for Go files - Run Biome formatter on save for TypeScript/React files
- Integrate with
golangci-lintfor Go linting - Integrate with Biome for TypeScript linting
Contributing
When contributing code:- Before committing: Run
fmtto format all code - Before pushing: Run
lintto check for issues - Fix all linting errors - Pre-commit hooks will block commits with errors
- Follow naming conventions - Use the appropriate case for your language
- Write tests - Follow the testing patterns in each style guide
- Document public APIs - Add comments for exported functions and types