Skip to content

Commit f2b47fa

Browse files
authored
Merge pull request #1301 from ArtemioPadilla/docs/add-claude-instructions
Add Claude Code project documentation (CLAUDE.md)
2 parents 0820996 + 1717f7c commit f2b47fa

File tree

1 file changed

+177
-0
lines changed

1 file changed

+177
-0
lines changed

CLAUDE.md

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
LearnGitBranching is an interactive git visualization tool for teaching git concepts through a game-like interface. It's a 100% client-side JavaScript application that simulates git operations and renders them visually using Raphael.js for SVG graphics.
8+
9+
## Build & Development Commands
10+
11+
### Setup
12+
```bash
13+
yarn install
14+
```
15+
16+
### Building
17+
```bash
18+
yarn gulp fastBuild # Fast build without tests/linting
19+
yarn gulp build # Full production build with tests & lint
20+
yarn gulp watching # Watch mode - rebuilds on file changes
21+
```
22+
23+
### Testing & Linting
24+
```bash
25+
yarn test # Run Jasmine test suite
26+
yarn test:coverage # Run tests with nyc coverage
27+
gulp jshint # Run JSHint linter
28+
gulp lintStrings # Validate internationalization strings
29+
```
30+
31+
### Development Server
32+
```bash
33+
yarn dev # Start Vite dev server
34+
# After building, open index.html directly in browser
35+
```
36+
37+
### Single Test Execution
38+
```bash
39+
# Run specific test file
40+
npx gulp-jasmine __tests__/git.spec.js
41+
```
42+
43+
## Architecture Overview
44+
45+
### Core Components
46+
47+
**GitEngine** (`src/js/git/index.js`)
48+
- The heart of the application - simulates all git operations
49+
- Manages the commit graph, branches, tags, refs, and HEAD
50+
- Processes commands and updates the visualization
51+
- Supports both git and Mercurial (hg) modes via `mode` property
52+
- Uses EventBaton pattern for command dispatching
53+
54+
**Visualization System** (`src/js/visuals/`)
55+
- `visualization.js`: Main visualization controller
56+
- `tree.js`: Renders the commit tree using Raphael.js
57+
- `visNode.js`, `visBranch.js`, `visTag.js`, `visEdge.js`: Individual visual components
58+
- `animation/`: Animation system using promise chains (Q library)
59+
60+
**Command Processing** (`src/js/commands/index.js`, `src/js/git/commands.js`)
61+
- Commands are defined with regex patterns, options, and execute functions
62+
- Supports both git and Mercurial command sets
63+
- Command delegation system allows commands to internally invoke other commands
64+
- All git commands are simulated - they manipulate in-memory data structures
65+
66+
**Levels System** (`src/levels/`)
67+
- Each level is a JavaScript module exporting level configuration
68+
- Organized into sequences: intro, rampup, move, mixed, advanced, remote, remoteAdvanced
69+
- Level definition includes: name, goal description, starting tree state, solution validation
70+
- See `src/levels/index.js` for all level sequences
71+
72+
### Flux Architecture
73+
74+
The app uses a Flux-like architecture:
75+
76+
**Dispatcher** (`src/js/dispatcher/AppDispatcher.js`)
77+
- Central event bus using Facebook's Flux Dispatcher
78+
- Handles VIEW_ACTION and URI_ACTION payload sources
79+
80+
**Stores** (`src/js/stores/`)
81+
- `CommandLineStore.js`: Manages command line state
82+
- `LevelStore.js`: Tracks current level and progress
83+
- `LocaleStore.js`: Handles internationalization
84+
- `GlobalStateStore.js`: Global application state
85+
86+
**Actions** (`src/js/actions/`)
87+
- Action creators for CommandLine, Level, Locale, and GlobalState
88+
89+
### UI Components
90+
91+
**Backbone Views** (`src/js/views/`)
92+
- Legacy Backbone.js views for modals, dialogs, builders
93+
- `gitDemonstrationView.js`: Shows animated git command demonstrations
94+
95+
**React Components** (`src/js/react_views/`)
96+
- Modern React components for command line, toolbar, helper bars
97+
- Command history view with syntax highlighting
98+
99+
### Key Patterns
100+
101+
**EventBaton** (`src/js/util/eventBaton.js`)
102+
- Pattern for transferring event handling responsibility
103+
- Used extensively for command processing and level events
104+
105+
**TreeCompare** (`src/js/graph/treeCompare.js`)
106+
- Compares two commit trees for level completion validation
107+
- Handles branch positions, commit structure, tags
108+
109+
**Animation Chains**
110+
- All visual updates go through animation queue
111+
- Uses Q promises to chain animations
112+
- Can be disabled for testing (headless mode)
113+
114+
## Project Structure
115+
116+
```
117+
src/
118+
├── js/
119+
│ ├── app/ # Application bootstrapping
120+
│ ├── git/ # Git engine and commands
121+
│ ├── mercurial/ # Mercurial (hg) support
122+
│ ├── commands/ # Command parsing and execution
123+
│ ├── level/ # Level loading and validation
124+
│ ├── visuals/ # Visualization and animation
125+
│ ├── views/ # Backbone views
126+
│ ├── react_views/ # React components
127+
│ ├── stores/ # Flux stores
128+
│ ├── actions/ # Flux actions
129+
│ ├── models/ # Backbone models and collections
130+
│ ├── intl/ # Internationalization
131+
│ ├── graph/ # Tree comparison logic
132+
│ └── util/ # Utilities
133+
├── levels/ # Level definitions organized by category
134+
├── style/ # CSS files
135+
└── template.index.html # HTML template
136+
137+
__tests__/ # Jasmine test specs
138+
```
139+
140+
## Build Process
141+
142+
The gulp build process:
143+
1. Browserify bundles all JS files (including JSX with Babel transform)
144+
2. CSS files concatenated and minified (production)
145+
3. Files are hashed for cache busting
146+
4. `template.index.html` is processed with hashed filenames to generate `index.html`
147+
5. Tests run with Jasmine, linting with JSHint
148+
149+
Production builds minify JS with Terser and HTML with html-minifier.
150+
151+
## Key Technologies
152+
153+
- **Backbone.js**: MVC framework (legacy parts)
154+
- **React 17**: UI components (modern parts)
155+
- **Flux**: Unidirectional data flow
156+
- **Raphael.js**: SVG graphics for visualization
157+
- **Q**: Promises for animation chains
158+
- **jQuery/jQuery UI**: DOM manipulation and dialogs
159+
- **Browserify + Babel**: Module bundling and JSX transform
160+
- **Gulp**: Build automation
161+
- **Jasmine**: Testing framework
162+
163+
## Testing Conventions
164+
165+
- Tests in `__tests__/` directory
166+
- Headless git engine for testing (`src/js/git/headless.js`)
167+
- Use `create.js` helper to set up test git trees
168+
- Mock commands with `mock.js` utility
169+
- Tests cover git operations, remote operations, levels, tree comparison
170+
171+
## Remote Repository Simulation
172+
173+
Remote operations (push/pull/fetch) are simulated by creating a separate GitEngine instance for the "origin" repository. The `o/` prefix denotes remote tracking branches.
174+
175+
## Internationalization
176+
177+
String translations in `src/js/intl/strings.js`. Use `intl.str()` and `intl.getDialog()` to access localized strings. Locale validation via `checkStrings.js`.

0 commit comments

Comments
 (0)