This document outlines the general TypeScript and CLI/library coding styles and guidelines for this repository.
It follows the directory structure within the /app directory:
Note
📂 build
📂 dist
📂 html
📂 scripts
📂 src
└─ 📂 __tests__
└─ 📂 demo
└─ 📂 scripts
└─ 📂 types
└─ 📂 utils
└─ 📄 index.ts
└─ 📄 .env.example
└─ 📄 .gitignore
└─ 📄 .dockerignore
└─ 📄 Dockerfile
└─ 📄 package.json
└─ 📄 package-lock.json
└─ 📄 sea-config.json
└─ 📄 eslint.config.mjs
└─ 📄 vite.config.ts
└─ 📄 tsconfig.json
└─ 📄 ...
📄 README.md
What you should (and shouldn't) edit
✅ Edit:
app/src/**(main TypeScript source)- Top-level build scripts in
app/scripts/**(bash / automation)
🏗️🚫 Auto-generated (do not edit):
dist/**(TS build output; local, published to NPM)build/**(SEA build output; local, published to GitHub Releases)html/**(test coverage output; local)
Generated SEA artifacts (Windows EXE + blob output with build-sea-win.sh). Local build output only. This is what gets published to the GitHub Releases page.
Do not edit manually.
Generated output from TypeScript build (JS + .d.ts + sourcemaps). This is what gets published to the npm registry.
Do not edit manually.
Generated Vitest coverage website output.
Do not edit manually.
Contains build automation scripts (bash)
Contains the main source, configurations, and utilities used throughout the app.
/__tests__— Vitest test files used for testing critical library and CLI features./demo— Sample codes demonstrating library usage./scripts— CLI source code (TypeScript)./types— Main TypeScript interfaces, types and constructs used within the app./utils— General-purpose utility functions, such as string formatters, directory path conventions and constant configurations.
Contains the main application source codes, classes and logic.
/email— Classes and scripts for handling email transport and content formatting and transformation./google— Class that manages and validates input for the Google OAuth2./validator— A wrapper around thezodSchemas containing generic log output formatters and utilities.
This folder contains the EJS HTML template used in sending emails, and other template formats for various use cases.
- Use
LF(Line Feed) as the line ending format for all code and other files to ensure consistency across environments and platforms. - Use arrow functions instead of traditional function declarations when defining functions and methods. Only use
function()definitions for specific cases. - Follow camelCase for naming variables, files, functions/methods and non-component folders.
- Follow PascalCase for naming Zod schemas, TypeScript
types,interfaces,enumsand other TypeScript constructs. - Follow consistent file naming conventions based on content:
- Use
*.schema.tsfor files containing Zod schemas. - Use
*.enum.tsfor files containing only enums. - Use
*.interface.tsfor files containing only interfaces. - Use
*.types.tsfor files that include a mix of types, interfaces, enums, or other related constructs.
- Use
- Always define the types of function parameters and return values. Use TypeScript interfaces or types for generic parameters when applicable.
- Avoid
anyunless absolutely necessary (preferunknown,Record, etc.)
- Avoid
- Aim to keep each source file—under approximately 250 lines of code. If a file exceeds this size, consider refactoring it into smaller, more focused files to improve clarity and maintainability.
- Use early
returnstatements to exit hooks or functions as soon as possible when conditions aren't met, to avoid unnecessary processing and to keep the logic clean and efficient. - Store constant values (e.g., strings or numbers) in well-named variables to improve readability and maintainability.
✅ const PROGRAM_NAME = 'my-app' program.name(PROGRAM_NAME) ❌ program.name('my-app')
- Implement CLI features within the
📂 src/scriptsdirectory. - Think in OOP and use
classesto define app-wide logic in the📂 src/libdirectory whenever possible. - Export new library scripts or classes in the
/src/index.tsfile.
- Use JSDoc-style comments to describe function parameters, return types, and TypeScript type or interface definitions.
- Add minimal but meaningful inline comments where necessary to clarify intent, especially for complex or non-obvious logic.
- Use descriptive and self-explanatory variable names to reduce the need for excessive comments and improve overall code readability.
- Linting is handled by ESLint, configured via
eslint.config.mjs. - All code should pass
"npm run lint"and"npm run transpile:noemit"before commit.
- Strive to minimize external dependencies, especially for simple or easily implementable functionality (e.g., a function that sums two numbers).
- Only use third-party Node libraries when truly necessary—for example, when a library:
- Provides functionality that would be complex or time-consuming to build from scratch
- Is used frequently across the app
- Helps avoid "reinventing the wheel" for heavy processing tasks
- Before adding a library, consider the following 🟢 green flags:
- It comes from a credible author or organization, with an active and trustworthy GitHub repository
- It has high usage and community trust (e.g., ~100K+ downloads on the NPM registry)
- It has small and lightweight footprint (eg., about ~300KB-2MB unpacked) or if it supports tree-shaking.
- The source code is open, transparent, and actively maintained (eg., few open GitHub Issues or PRs)
- Even if not actively maintained, the library still aligns with your needs and is simple enough to extend or adapt for custom use (e.g., a JavaScript
classthat can be easily refactored or subclassed (extend) for custom use)
Note
This app uses Vitest for testing feature-level processes.
- Create and run tests for critical feature-level components, classes, or scripts.
- Place test files in the
/src/__tests__directory. - Name test files to match the target module, using the suffix:
*.test.ts.Example:
send.ts→send.test.ts - Selectively write tests for critical or global features, or business logic as needed.
- All code should pass
"npm test"before commit.
@weaponsforge
20260226