code-brick
v0.2.0
Published
A framework-agnostic CLI tool for managing reusable code templates. Save, manage, and apply code snippets across projects.
Maintainers
Readme
🧱 Brick CLI
A framework-agnostic CLI tool for managing reusable code templates. Stop copy-pasting code between projects — save it once, use it everywhere.
The Problem
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.
Installation
# 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 --versionQuick Start
# 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/authCommands
brick init
Initialize Brick on your system. Creates the storage directory at ~/.codebrick/.
brick initbrick save <name> [path]
Save 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
brick list
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!
brick tree <name|index>
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 directoriesbrick apply <name|index> [destination]
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
brick info <name|index>
Show detailed information about a template.
brick info nestjs-auth
brick info 0brick size [name|index]
Show 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 KBOutput (single template):
nestjs-auth
Files: 5
Directories: 2
Total Size: 12.4 KBbrick add <name|index> <files...>
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/brick remove-file <name|index> <files...>
Remove files from a template.
brick remove-file nestjs-auth auth.controller.ts
brick remove-file 0 dto/brick delete <name|index>
Delete a template entirely.
brick delete nestjs-auth
# By index
brick delete 0
# Skip confirmation
brick delete 0 --forcebrick clean <name|index>
Remove 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.
brick export <name|index>
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
└brick import <file>
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
└Smart Ignore System
Brick automatically ignores common dependency directories, build outputs, and generated files across all frameworks. This keeps your templates clean and portable.
Ignored Directories
| 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) |
Ignored Files
| 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 ✅Framework Agnostic
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 |
Storage Location
Templates are stored locally at:
~/.codebrick/
├── config.json # Configuration
├── store.json # Template registry
└── templates/ # Actual template files
├── nestjs-auth/
├── react-modal/
└── ...Examples
Save a NestJS Auth Module
# 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-depsApply to a New Project
# 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 bcryptSave React Components
brick save react-modal ./src/components/Modal \
--description "Animated modal with backdrop" \
--tags react,modal,ui,animationSave Flutter Clean Architecture
brick save flutter-clean ./lib \
--description "Clean architecture with BLoC" \
--tags flutter,bloc,clean-architectureSave Docker Configs
brick save docker-dev ./docker \
--description "Docker Compose development setup" \
--tags docker,devopsQuick Operations with Index
# 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 --forceShare Templates with Your Team
# 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-authContributing
Contributions are welcome! Please open an issue or submit a pull request.
