A framework-agnostic CLI tool for managing reusable code templates. Stop copy-pasting code between projects β save it once, use it everywhere.
Every developer has faced this workflow:
- Create a new project (
nest new my-app) - Open an existing project with code you want to reuse
- Manually copy-paste files (auth module, pagination utils, config files)
- Adjust imports, fix paths, install missing dependencies
- Repeat for every new project
Brick eliminates steps 2-4 entirely.
# Install globally via npm
npm install -g code-brick
# Or with yarn
yarn global add code-brick
# Or with pnpm
pnpm add -g code-brick
# Or with bun
bun add -g code-brickAfter installation, the brick command will be available globally:
brick --version# 1. Initialize brick (one-time setup)
brick init
# 2. Save a folder as a reusable template
brick save my-auth ./src/auth --description "JWT authentication module"
# 3. View your saved templates
brick list
# 4. Apply a template to a new project
cd ~/new-project
brick apply my-auth ./src/authInitialize Brick on your system. Creates the storage directory at ~/.codebrick/.
brick initSave a folder as a reusable template.
# Save current directory
brick save my-template
# Save a specific path
brick save nestjs-auth ./src/auth
# With options
brick save nestjs-auth ./src/auth \
--description "JWT authentication for NestJS" \
--tags auth,jwt,nestjs \
--detect-depsOptions:
-d, --description <desc>β Template description-t, --tags <tags>β Comma-separated tags--include <patterns>β Glob patterns to include--exclude <patterns>β Glob patterns to exclude--detect-depsβ Auto-detect dependencies from imports
List all saved templates.
brick list
# Filter by type
brick list --local
brick list --remote
# Filter by tag
brick list --tag auth
# Detailed view
brick list --detailedOutput:
# Name Type Files Description
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
0 nestjs-auth local 5 JWT authentication module
1 react-modal local 3 Animated modal with backdrop
2 docker-dev local 4 Docker Compose dev setup
3 templates (3 local, 0 remote)
π‘ Tip: Use the index number (
0,1,2) instead of the full name in any command!
Display the file structure of a template.
# By name
brick tree nestjs-auth
# By index
brick tree 0
# With file sizes
brick tree 0 --sizeOutput:
nestjs-auth
βββ guards/
β βββ jwt.guard.ts
βββ strategies/
β βββ jwt.strategy.ts
βββ auth.controller.ts
βββ auth.module.ts
βββ auth.service.ts
5 files, 2 directories
Apply a template to your project.
# Apply to current directory
brick apply nestjs-auth
# Apply by index
brick apply 0 ./src/auth
# With options
brick apply 0 --force --latestOptions:
-f, --forceβ Overwrite existing files without prompting--skip-existingβ Skip files that already exist--dry-runβ Preview changes without writing files--latestβ Use @latest for all dependency versions--no-depsβ Skip dependency installation prompts
Show detailed information about a template.
brick info nestjs-auth
brick info 0Show the size of templates.
# Show all template sizes
brick size
# Show specific template size
brick size nestjs-auth
brick size 0Output (all templates):
# Name Type Files Size
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
0 nestjs-auth local 5 12.4 KB
1 react-modal local 3 8.2 KB
2 docker-dev local 4 3.1 KB
Total: 12 files, 23.7 KB
Output (single template):
nestjs-auth
Files: 5
Directories: 2
Total Size: 12.4 KB
Add files to an existing template.
# Add a single file
brick add nestjs-auth ./src/auth/dto/login.dto.ts
# Add by index
brick add 0 ./src/auth/dto/*.ts
# Add a directory
brick add 0 ./src/auth/decorators/Remove files from a template.
brick remove-file nestjs-auth auth.controller.ts
brick remove-file 0 dto/Delete a template entirely.
brick delete nestjs-auth
# By index
brick delete 0
# Skip confirmation
brick delete 0 --forceRemove local/project-specific imports from template files. This makes templates portable by stripping out imports that reference the original project.
# Clean a template (auto-detects project name)
brick clean flutter-clean
# By index
brick clean 0
# Preview what will be removed (dry run)
brick clean 0 --dry-run
# Use custom pattern
brick clean 0 --pattern "package:my_app/"
# Also remove external packages (not recommended)
brick clean 0 --no-keep-externalOptions:
-p, --pattern <regex>β Custom regex pattern to match imports to remove--dry-runβ Preview changes without modifying files--no-keep-externalβ Also remove external package imports
Example (Flutter/Dart):
Before cleaning:
import 'package:my_app/features/auth/login.dart';
import 'package:my_app/core/utils/helpers.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';After brick clean flutter-template:
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';Supported languages:
| Language | Local Imports Removed | External Imports Kept |
|---|---|---|
| Dart/Flutter | package:project_name/... |
package:flutter/, package:go_router/, etc. |
| TypeScript/JS | ./path, ../path |
react, lodash, express, etc. |
| Python | from .module, from .. |
from flask, import requests |
| Rust | use crate::, use super:: |
use std::, external crates |
The command auto-detects the project name from pubspec.yaml, package.json, or pyproject.toml.
Export a template as a shareable .brick file. Perfect for sharing templates with teammates or between machines.
# Export to current directory
brick export nestjs-auth
# By index
brick export 0
# Specify output path
brick export 0 --output ~/Desktop/my-auth.brickOptions:
-o, --output <path>β Output file path (default:./<name>.brick)
Example output:
β π§± Exporting template
β β Template: nestjs-auth
β β Files: 5 files
β β Output: /Users/you/nestjs-auth.brick
β
β β Export complete!
β Size: 12.34 KB
β
β Share this file and import with:
β brick import nestjs-auth.brick
β
Import a template from a .brick file.
# Import from .brick file
brick import nestjs-auth.brick
# Import with custom name
brick import nestjs-auth.brick --name my-auth-v2
# Force overwrite existing template
brick import nestjs-auth.brick --forceOptions:
-n, --name <name>β Custom name for the imported template-f, --forceβ Overwrite existing template without prompting
Example output:
β π§± Importing template
β β File: /Users/you/nestjs-auth.brick
β β Template: nestjs-auth
β β Description: JWT authentication module
β β Files: 5 files
β
β β Import complete!
β
β View structure: brick tree nestjs-auth
β Apply template: brick apply nestjs-auth
β
Brick automatically ignores common dependency directories, build outputs, and generated files across all frameworks. This keeps your templates clean and portable.
| Framework | Automatically Ignored |
|---|---|
| Node.js | node_modules/, .npm/, .yarn/, .pnpm-store/ |
| Python | __pycache__/, .venv/, venv/, .pytest_cache/, .mypy_cache/ |
| Flutter | .dart_tool/, .pub-cache/, build/, .flutter-plugins* |
| Rust | target/ |
| Go | vendor/ |
| Java | .gradle/, .idea/, out/, build/ |
| iOS | Pods/, .symlinks/, DerivedData/ |
| .NET | bin/, obj/, packages/ |
| Build | dist/, build/, .next/, .nuxt/, .output/, .vercel/ |
| Cache | .cache/, .temp/, .turbo/, coverage/ |
| VCS | .git/, .svn/, .hg/ |
| IDE | .idea/, .vscode/ (settings, not launch configs) |
| Category | Files |
|---|---|
| Locks | package-lock.json, yarn.lock, pnpm-lock.yaml, Podfile.lock |
| Env | .env, .env.local, .env.production, .env.* |
| OS | .DS_Store, Thumbs.db, desktop.ini |
| Logs | *.log, npm-debug.log*, yarn-debug.log* |
| Metadata | brick.json (template metadata) |
This means when you save a template, you get only the source code β no bloat:
# Before smart ignore (hypothetical)
flutter-app: 1,247 files, 89.2 MB β
# With smart ignore (actual)
flutter-app: 42 files, 156 KB β
Brick works with any language or framework since it operates at the file level:
| Category | Examples |
|---|---|
| Frontend | React, Vue, Angular, Svelte, Solid, Astro |
| Backend | NestJS, Express, FastAPI, Django, Rails, Spring Boot |
| Mobile | React Native, Flutter, Swift, Kotlin |
| Languages | TypeScript, JavaScript, Python, Go, Rust, Java, C# |
| Infrastructure | Terraform, Pulumi, Docker, Kubernetes configs |
| Other | Markdown docs, config files, shell scripts |
Templates are stored locally at:
~/.codebrick/
βββ config.json # Configuration
βββ store.json # Template registry
βββ templates/ # Actual template files
βββ nestjs-auth/
βββ react-modal/
βββ ...
# From your existing project with a working auth implementation
cd ~/projects/my-backend
brick save nestjs-auth ./src/auth \
--description "JWT authentication with Passport" \
--tags nestjs,auth,jwt,passport \
--detect-deps# Create new project
nest new my-new-api
cd my-new-api
# Apply the auth template (by index or name)
brick apply 0 ./src/auth
# Install dependencies (brick will show you the command)
npm install @nestjs/jwt @nestjs/passport passport-jwt bcryptbrick save react-modal ./src/components/Modal \
--description "Animated modal with backdrop" \
--tags react,modal,ui,animationbrick save flutter-clean ./lib \
--description "Clean architecture with BLoC" \
--tags flutter,bloc,clean-architecturebrick save docker-dev ./docker \
--description "Docker Compose development setup" \
--tags docker,devops# List templates
brick list
# 0 nestjs-auth
# 1 react-modal
# 2 flutter-clean
# Use index for faster operations
brick tree 0
brick info 1
brick apply 2 ./lib
brick size 0
brick clean 2 # Remove local imports
brick delete 1 --force# Export a template to share
brick export nestjs-auth
# Creates: nestjs-auth.brick (shareable file)
# Send the .brick file to your teammate, then they run:
brick import nestjs-auth.brick
# Or import with a custom name
brick import nestjs-auth.brick --name company-authContributions are welcome! Please open an issue or submit a pull request.