Description
I'd like to propose migrating the project to use a src/ directory structure to improve code organization and align with TypeScript ecosystem conventions. This change would group all source code under a single directory while keeping configuration files at the root level.
Current Structure
ccusage/
├── index.ts # Mixed with config files
├── calculate-cost.ts
├── calculate-cost.test.ts
├── data-loader.ts
├── data-loader.test.ts
├── logger.ts
├── shared-args.ts
├── types.ts
├── utils.ts
├── utils.test.ts
├── commands/
│ ├── daily.ts
│ └── session.ts
├── package.json # Config files
├── tsconfig.json
└── ...
Proposed Structure
ccusage/
├── src/ # All source code
│ ├── index.ts
│ ├── commands/ # CLI commands
│ │ ├── daily.ts
│ │ └── session.ts
│ ├── core/ # Core business logic
│ │ ├── calculate-cost.ts
│ │ ├── calculate-cost.test.ts
│ │ ├── data-loader.ts
│ │ ├── data-loader.test.ts
│ │ └── types.ts
│ ├── cli/ # CLI utilities
│ │ └── shared-args.ts
│ └── utils/ # General utilities
│ ├── logger.ts
│ ├── utils.ts
│ └── utils.test.ts
├── dist/ # Build output
├── package.json # Config at root
├── tsconfig.json
└── ...
Benefits
- Better Organization: Logical grouping of related functionality
- Cleaner Root: Separates source code from configuration files
- Scalability: Easier to add new features without cluttering the root
- Convention: Aligns with TypeScript/Node.js ecosystem standards
- Developer Experience: Clearer project structure for contributors
Implementation Plan
- Create new directory structure under
src/
- Move files using
git mv to preserve history
- Update import paths throughout the codebase
- Update build configuration in
package.json
- Update
tsconfig.json to include src/
- Ensure all tests pass
- Verify build output remains unchanged
Changes Required
Import Updates: ~15 import statements need path updates
// Example: commands/daily.ts
// Before
import { loadUsageData } from "../data-loader.ts";
// After
import { loadUsageData } from "../core/data-loader.ts";
Configuration Updates:
package.json: Update build script to use ./src/index.ts
tsconfig.json: Add "include": ["src/**/*"]
Impact
- ✅ No breaking changes for npm package users (dist/ output unchanged)
- ✅ No API changes
- ✅ No runtime behavior changes
- ✅ Maintains co-located test structure
Questions
- Would you be open to this organizational change?
- Any concerns about the proposed structure?
- Should we keep the current test co-location or prefer a separate
tests/ directory?
Implementation Offer
I'm happy to implement this change if you think it would benefit the project. I can:
What I'll deliver:
- Create a PR with all the necessary changes
- Ensure all tests pass (
bun test)
- Verify the build works correctly (
bun run build)
- Test CLI functionality (
bun run report daily/session)
- Include the migration script I've prepared for transparency
My approach:
- Fork and create a feature branch
- Run the automated migration script
- Manually verify and adjust any edge cases
- Update documentation as needed
- Submit PR with detailed description
I've already prepared a migration script that automates most of the work while preserving git history. Happy to make any adjustments based on your feedback!
Let me know if you'd like me to proceed.
Checklist
Alternative: Minimal Migration
If the full restructure seems too much, here's a minimal alternative:
ccusage/
├── src/
│ ├── index.ts
│ ├── *.ts # All other .ts files
│ ├── *.test.ts # All test files
│ └── commands/ # Keep commands subdirectory
├── dist/
└── [config files]
Description
I'd like to propose migrating the project to use a
src/directory structure to improve code organization and align with TypeScript ecosystem conventions. This change would group all source code under a single directory while keeping configuration files at the root level.Current Structure
Proposed Structure
Benefits
Implementation Plan
src/git mvto preserve historypackage.jsontsconfig.jsonto includesrc/Changes Required
Import Updates: ~15 import statements need path updates
Configuration Updates:
package.json: Update build script to use./src/index.tstsconfig.json: Add"include": ["src/**/*"]Impact
Questions
tests/directory?Implementation Offer
I'm happy to implement this change if you think it would benefit the project. I can:
What I'll deliver:
bun test)bun run build)bun run report daily/session)My approach:
I've already prepared a migration script that automates most of the work while preserving git history. Happy to make any adjustments based on your feedback!
Let me know if you'd like me to proceed.
Checklist
Alternative: Minimal Migration
If the full restructure seems too much, here's a minimal alternative: