Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
261 changes: 261 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ First off, thank you for considering contributing! It's people like you that mak
- [Code of Conduct](#code-of-conduct)
- [How Can I Contribute?](#how-can-i-contribute)
- [Development Setup](#development-setup)
- [Adding New Technology Stacks](#adding-new-technology-stacks)
- [Git Workflow and Pull Requests](#git-workflow-and-pull-requests)
- [Coding Style and Principles](#coding-style-and-principles)
- [Commit Message Guidelines](#commit-message-guidelines)
Expand Down Expand Up @@ -58,6 +59,266 @@ You can now test your local changes by running the CLI from the root of the proj
node packages/cli/dist/index.js <command>
```

## Adding New Technology Stacks

StackCode currently supports multiple technology stacks (React, Vue, Node.js, Python, Java, Go, PHP). If you want to add support for a new technology stack, follow this comprehensive guide:

### 1. Understanding the Stack Generator Architecture

The stack generator system consists of several components:

- **Templates**: Located in `packages/core/src/templates/`
- **Type Definitions**: In `packages/core/src/types.ts` and `packages/cli/src/commands/ui.ts`
- **Scaffolding Logic**: In `packages/core/src/scaffold.ts`
- **CLI Integration**: In `packages/cli/src/commands/init.ts`

### 2. Step-by-Step Guide to Add a New Stack

#### Step 1: Create Template Directory Structure

Create a new directory under `packages/core/src/templates/` with your stack name (e.g., `angular`, `django`, `rails`):

```bash
mkdir packages/core/src/templates/your-stack-name
```

#### Step 2: Create Template Files

Create the necessary template files with `.tpl` extension. These files support variable replacement using `{{variableName}}` syntax:

```
packages/core/src/templates/your-stack-name/
├── package.json.tpl # Or equivalent (requirements.txt, composer.json, etc.)
├── src/
│ ├── main.ts.tpl # Main application file
│ ├── components/ # Component structure
│ │ └── Example.tsx.tpl
│ └── styles/
│ └── globals.css.tpl
├── tsconfig.json.tpl # Configuration files
├── vite.config.ts.tpl # Build tool configuration
└── index.html.tpl # Entry point (for frontend stacks)
```

**Important**: Use these replacement variables in your templates:

- `{{projectName}}` - The project name
- `{{description}}` - Project description
- `{{authorName}}` - Author name

**Example package.json.tpl:**

```json
{
"name": "{{projectName}}",
"version": "1.0.0",
"description": "{{description}}",
"author": "{{authorName}}",
"scripts": {
"dev": "your-dev-command",
"build": "your-build-command"
}
}
```

#### Step 3: Create .gitignore Template

Add a corresponding gitignore template in `packages/core/src/templates/gitignore/your-stack-name.tpl`:

```bash
# Example: packages/core/src/templates/gitignore/angular.tpl
node_modules/
dist/
.angular/
.env
*.log
```

#### Step 4: Update Type Definitions

Add your new stack to the type definitions:

**In `packages/core/src/scaffold.ts`:**

```typescript
export interface ProjectOptions {
projectPath: string;
stack:
| "node-js"
| "node-ts"
| "react"
| "vue"
| "python"
| "java"
| "go"
| "php"
| "your-stack-name";
features: ("docker" | "husky")[];
replacements: Record<string, string>;
}
```

**In `packages/cli/src/commands/ui.ts`:**

```typescript
export interface InitAnswers {
projectName: string;
description: string;
authorName: string;
stack:
| "node-js"
| "node-ts"
| "react"
| "vue"
| "python"
| "java"
| "go"
| "php"
| "your-stack-name";
features: ("docker" | "husky")[];
commitValidation?: boolean;
}
```

#### Step 5: Add to CLI Options

Update the stack choices in `packages/cli/src/commands/ui.ts`:

```typescript
{
type: "list",
name: "stack",
message: t("init.prompt.stack"),
choices: [
{ name: "Node.js + JavaScript", value: "node-js" },
{ name: "Node.js + TypeScript", value: "node-ts" },
{ name: "React + TypeScript", value: "react" },
{ name: "Vue.js + TypeScript", value: "vue" },
{ name: "Python + FastAPI", value: "python" },
{ name: "Java + Spring", value: "java" },
{ name: "Go + Gin", value: "go" },
{ name: "PHP + Laravel", value: "php" },
{ name: "Your Stack + Framework", value: "your-stack-name" },
],
}
```

#### Step 6: Update Package Manager Logic

If your stack uses a different package manager, update the dependency installation logic in `packages/cli/src/commands/init.ts`:

```typescript
// Install dependencies based on the stack type
if (answers.stack === "python") {
await runCommand("pip", ["install", "-e", "."], { cwd: projectPath });
} else if (answers.stack === "java") {
await runCommand("mvn", ["install"], { cwd: projectPath });
} else if (answers.stack === "go") {
await runCommand("go", ["mod", "tidy"], { cwd: projectPath });
} else if (answers.stack === "php") {
await runCommand("composer", ["install"], { cwd: projectPath });
} else if (answers.stack === "your-stack-name") {
await runCommand("your-package-manager", ["install"], { cwd: projectPath });
} else {
// For Node.js-based stacks (node-js, node-ts, react, vue)
await runCommand("npm", ["install"], { cwd: projectPath });
}
```

### 3. Best Practices for New Stacks

#### Template Structure Guidelines:

- **Follow conventions**: Use the technology's standard project structure
- **Include essentials**: Configuration files, build tools, testing setup
- **Add documentation**: Include basic README template
- **Consider scalability**: Create folders for components, services, etc.
- **Modern practices**: Use latest stable versions and best practices

#### Example Folder Structures:

**Frontend Stack (SPA):**

```
src/
├── components/
├── pages/ or views/
├── services/
├── styles/
├── utils/
└── main.ts
```

**Backend Stack (API):**

```
src/
├── controllers/
├── models/
├── services/
├── middleware/
├── routes/
└── main.ts
```

**Full-Stack Framework:**

```
src/
├── components/
├── pages/
├── api/
├── styles/
└── utils/
```

### 4. Testing Your New Stack

1. **Build the project**: `npm run build`
2. **Test scaffolding**: Create a test project with your new stack
3. **Verify structure**: Check that all files are created correctly
4. **Test build**: Ensure the generated project builds/runs successfully
5. **Run tests**: Execute `npm test` to ensure no regressions

### 5. Example: Adding Angular Support

Here's a practical example of adding Angular support:

```bash
# 1. Create template directory
mkdir packages/core/src/templates/angular

# 2. Create basic structure
packages/core/src/templates/angular/
├── package.json.tpl
├── angular.json.tpl
├── tsconfig.json.tpl
├── src/
│ ├── app/
│ │ ├── app.component.ts.tpl
│ │ ├── app.component.html.tpl
│ │ └── app.module.ts.tpl
│ ├── main.ts.tpl
│ └── index.html.tpl
└── .gitignore.tpl
```

### 6. Submission Guidelines

When submitting a PR for a new stack:

1. **Test thoroughly**: Ensure the generated project works end-to-end
2. **Include examples**: Provide sample output or screenshots
3. **Update documentation**: Add your stack to relevant docs
4. **Follow naming**: Use kebab-case for stack names
5. **Add tests**: Include unit tests if complex logic is added

### 7. Internationalization

If adding UI text, ensure it's properly internationalized using the `@stackcode/i18n` package.

This system is designed to be extensible and maintainable. By following these guidelines, you'll ensure that new stacks integrate seamlessly with the existing codebase.

## Git Workflow and Pull Requests

We use the **Gitflow** workflow. All development for new features and bugfixes should happen on branches created from the `develop` branch.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Our goal is to make best practices the easiest path.
StackCode is a suite of tools designed to work together seamlessly:

- 🚀 **Effortless Project Scaffolding (`init`):**
Generate a complete, production-ready project structure in seconds. Starts with a professional Node.js + TypeScript stack, with more to come.
Generate a complete, production-ready project structure in seconds. Choose from multiple technology stacks including Node.js, React, Vue.js, Python, Java, Go, and PHP—each with best practices and optimal folder structures.

- 📝 **Intelligent File Generation (`generate`):**
Need a `.gitignore`? Don't just get one—get a perfect one. Our composable template engine combines rules for your stack, IDE, and tools (like Docker) into a single, organized file.
Expand Down
Loading