Skip to content

Commit cc1cf6e

Browse files
authored
Merge pull request #9 from boostcampwm-snu-2026-1/docs/8-code-conventions
docs: add code conventions
2 parents 69a3055 + 98efa2d commit cc1cf6e

5 files changed

Lines changed: 91 additions & 2 deletions

File tree

AGENTS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ If these scripts do not exist yet, future scaffold work must add them. CI uses `
4747
- Keep project data serializable.
4848
- Store musical time in ticks, not seconds.
4949
- Use TypeScript types for project data, audio engine APIs, and feature boundaries.
50+
- Follow `docs/code-conventions.md` for naming, file organization, TypeScript, React, CSS Modules, design tokens, domain naming, tests, and comments.
5051
- Prefer pure utilities for tick math, model transformations, and scheduler calculations.
5152
- Do not introduce new production dependencies without a clear reason.
5253
- Do not rewrite large files unless required.

PLANS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ M1 should include:
2929

3030
Use this section as the current execution order for agent work. Feature document numbering describes the planned product sequence, but actual issue order may change as dependencies, review feedback, or implementation risks become clearer.
3131

32-
1. #6 Project Scaffold -> `docs/features/01-project-scaffold.md` (PR #7 in review)
32+
1. #8 Document Code Conventions -> `docs/code-conventions.md` (PR #9 in review)
3333
2. #4 AudioContext and Sample Playback -> `docs/features/02-audio-context-and-sample-playback.md`
3434
3. #5 Lookahead Scheduler -> `docs/features/03-lookahead-scheduler.md`
3535
4. #3 Drum Step Sequencer -> `docs/features/04-drum-step-sequencer.md`

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ The scaffold provides these scripts. Feature-specific behavior will be added in
4646
- [Audio engine](docs/audio-engine.md)
4747
- [UI and design](docs/ui-design.md)
4848
- [Testing strategy](docs/testing.md)
49+
- [Code conventions](docs/code-conventions.md)
4950
- [Project plans](PLANS.md)
5051
- [Agent instructions](AGENTS.md)
5152

docs/code-conventions.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Code Conventions
2+
3+
## Purpose
4+
5+
Use these conventions to keep agent-authored code consistent across features. Prefer existing local patterns when they are more specific than this document.
6+
7+
## Files and Directories
8+
9+
- React component files use `PascalCase.tsx`: `TransportBar.tsx`, `PianoRoll.tsx`.
10+
- Component CSS Modules use the same base name: `TransportBar.module.css`.
11+
- Feature folders use `kebab-case`: `drum-step-sequencer`, `piano-roll`.
12+
- General TypeScript utility files use `kebab-case.ts`: `tick-time.ts`, `sample-loader.ts`.
13+
- Barrel files may use `index.ts` only when they simplify imports without hiding ownership.
14+
- Test files use `*.test.ts` or `*.test.tsx` next to the code they cover unless a feature establishes a clearer local pattern.
15+
16+
## TypeScript Naming
17+
18+
- Types, interfaces, classes, enums, and React components use `PascalCase`.
19+
- Functions, variables, object properties, and module-level helpers use `camelCase`.
20+
- True constants use `UPPER_SNAKE_CASE`: `DEFAULT_PPQ`, `BAR_TICKS`, `STEP_TICKS`.
21+
- Generic type parameters should be short and meaningful: `T`, `TEvent`, `TClip`.
22+
- Avoid abbreviations unless they are common in the domain, such as `MIDI`, `PPQ`, `BPM`, or `ID`.
23+
24+
## React Components
25+
26+
- Component names should match product nouns: `TransportBar`, `ClipEditor`, `DrumStepSequencer`.
27+
- Event handlers use `handleX`: `handlePlayClick`, `handleStepToggle`.
28+
- Custom hooks use `useX`: `useTransportState`.
29+
- Components should not own exact audio timing or scheduling logic.
30+
- Keep feature-specific UI under `src/features/` unless it is clearly reusable.
31+
- Keep shared presentational components under `src/components/`.
32+
33+
## Domain Naming
34+
35+
- Tick values should use `Tick` or a `Ticks` suffix when they represent a duration or length:
36+
- `startTick`
37+
- `durationTicks`
38+
- `lengthTicks`
39+
- Seconds should be explicit:
40+
- `durationSeconds`
41+
- `lookaheadSeconds`
42+
- `scheduleAheadSeconds`
43+
- Web Audio clock values should make audio-time semantics clear:
44+
- `audioStartTime`
45+
- `scheduledAudioTime`
46+
- IDs use `Id` suffix in property names:
47+
- `clipId`
48+
- `trackId`
49+
- `sampleId`
50+
- Booleans should start with `is`, `has`, `can`, or `should`:
51+
- `isPlaying`
52+
- `hasSelection`
53+
- `canResizeNote`
54+
- `shouldLoop`
55+
56+
## CSS Modules
57+
58+
- CSS Module class names use `camelCase`: `root`, `transportBar`, `stepButton`, `activeStep`.
59+
- Prefer product or component part names over visual-only names.
60+
- Keep static appearance in CSS Modules.
61+
- Runtime editor geometry may use inline styles when values are derived from ticks, pitch, or grid dimensions.
62+
- Do not put component-specific styles in global CSS.
63+
64+
## Design Tokens
65+
66+
- Define primitive tokens first: raw palette, spacing, typography, radius, and timing values.
67+
- Define semantic tokens from primitive tokens.
68+
- Component CSS Modules should use semantic tokens, not primitive tokens.
69+
- Primitive token example: `--color-neutral-900`, `--space-4`, `--radius-2`.
70+
- Semantic token example: `--color-app-background`, `--space-control-gap`, `--radius-control`.
71+
- Document exceptions when component code must reference a primitive token directly.
72+
73+
## Tests
74+
75+
- Test names should describe behavior, not implementation.
76+
- Prefer examples such as:
77+
- `converts ticks to seconds at 120 bpm`
78+
- `does not schedule duplicate events at the loop end`
79+
- Unit-test pure utilities, tick/time conversion, data model transformations, and scheduler calculations.
80+
- Add component or end-to-end tests later when UI behavior becomes stable enough to justify them.
81+
82+
## Comments
83+
84+
- Prefer clear names and small functions over explanatory comments.
85+
- Add comments only where the reason is not obvious from the code.
86+
- Avoid comments that restate the next line of code.
87+
- Use comments to explain timing assumptions, loop-boundary decisions, browser audio constraints, or non-obvious model migrations.

docs/features/01-project-scaffold.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Feature: 01 Project Scaffold
22

33
## Status
4-
In Review
4+
Complete
55

66
## Goal
77

0 commit comments

Comments
 (0)