Skip to content

🧱 Your personal code template manager. Save, organize, and reuse code snippets across projects β€” works with any framework.

Notifications You must be signed in to change notification settings

seeebbii/code-brick

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

11 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🧱 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:

  1. Create a new project (nest new my-app)
  2. Open an existing project with code you want to reuse
  3. Manually copy-paste files (auth module, pagination utils, config files)
  4. Adjust imports, fix paths, install missing dependencies
  5. 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-brick

After installation, the brick command will be available globally:

brick --version

Quick 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/auth

Commands

brick init

Initialize Brick on your system. Creates the storage directory at ~/.codebrick/.

brick init

brick 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-deps

Options:

  • -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 --detailed

Output:

  #   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 --size

Output:

nestjs-auth
β”œβ”€β”€ guards/
β”‚   └── jwt.guard.ts
β”œβ”€β”€ strategies/
β”‚   └── jwt.strategy.ts
β”œβ”€β”€ auth.controller.ts
β”œβ”€β”€ auth.module.ts
└── auth.service.ts

5 files, 2 directories

brick 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 --latest

Options:

  • -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 0

brick size [name|index]

Show the size of templates.

# Show all template sizes
brick size

# Show specific template size
brick size nestjs-auth
brick size 0

Output (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

brick 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 --force

brick 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-external

Options:

  • -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.brick

Options:

  • -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 --force

Options:

  • -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-deps

Apply 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 bcrypt

Save React Components

brick save react-modal ./src/components/Modal \
  --description "Animated modal with backdrop" \
  --tags react,modal,ui,animation

Save Flutter Clean Architecture

brick save flutter-clean ./lib \
  --description "Clean architecture with BLoC" \
  --tags flutter,bloc,clean-architecture

Save Docker Configs

brick save docker-dev ./docker \
  --description "Docker Compose development setup" \
  --tags docker,devops

Quick 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 --force

Share 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-auth

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

About

🧱 Your personal code template manager. Save, organize, and reuse code snippets across projects β€” works with any framework.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published