Skip to main content

Glimx Workspace Templates

Glimx CLI provides pre-configured project templates to help you quickly start new projects with best practices and sensible defaults. This document explains how to use and customize these templates.

Available Templates

Glimx comes with three built-in templates:

  1. node-typescript - Modern Node.js project with TypeScript, ESLint, and Prettier
  2. react-vite - React application with Vite, TypeScript, and TailwindCSS
  3. python-fastapi - Python FastAPI project with Poetry package manager

Using Templates

To create a new project from a template, use the --template flag:

# Create a new Node.js TypeScript project
glimx --template node-typescript my-project

# Create a new React + Vite project
glimx --template react-vite my-app

# Create a new Python FastAPI project
glimx --template python-fastapi my-api

This will:

  1. Create a new directory with the specified name
  2. Generate all files from the template
  3. Initialize a git repository
  4. Install dependencies (if applicable)

Template Details

Node.js + TypeScript Template

This template creates a modern Node.js project with:

  • TypeScript for type safety
  • ESLint for code quality
  • Prettier for code formatting
  • Jest for testing
  • VS Code configuration

File structure:

my-project/
├── src/
│ ├── index.ts
│ └── __tests__/
├── package.json
├── tsconfig.json
├── eslint.config.js
├── prettier.config.js
├── jest.config.js
└── .gitignore

React + Vite Template

This template creates a React application with:

  • Vite for fast development
  • TypeScript for type safety
  • TailwindCSS for styling
  • React Router for navigation
  • ESLint and Prettier for code quality
  • Vitest for testing

File structure:

my-app/
├── src/
│ ├── App.tsx
│ ├── main.tsx
│ ├── components/
│ └── __tests__/
├── public/
├── index.html
├── package.json
├── tsconfig.json
├── vite.config.ts
├── tailwind.config.js
├── postcss.config.js
├── eslint.config.js
└── .gitignore

Python FastAPI Template

This template creates a Python FastAPI project with:

  • FastAPI for building APIs
  • Poetry for dependency management
  • Pydantic for data validation
  • Uvicorn for development server
  • Pytest for testing

File structure:

my-api/
├── src/
│ ├── main.py
│ ├── api/
│ └── tests/
├── pyproject.toml
├── poetry.lock
├── README.md
└── .gitignore

Customizing Templates

Modifying Template Files

You can customize the template files by editing the JSON template files located in packages/opencode/templates/:

  1. node-typescript.json - Node.js + TypeScript template
  2. react-vite.json - React + Vite template
  3. python-fastapi.json - Python FastAPI template

Each template file contains:

  • File definitions with content
  • Package dependencies
  • Scripts to run after creation

Creating New Templates

To create a new template:

  1. Create a new JSON file in the templates directory
  2. Define the template structure following the existing format
  3. Add an entry to index.json

Example template structure:

{
"name": "My Custom Template",
"description": "A custom project template",
"files": {
"src/index.ts": {
"content": "console.log('Hello, World!');"
},
"package.json": {
"content": "{\n \"name\": \"{{projectName}}\",\n \"version\": \"1.0.0\"\n}"
}
},
"dependencies": {
"dev": ["typescript", "@types/node"],
"prod": ["express"]
},
"scripts": [
"npm install",
"git init",
"git add .",
"git commit -m \"Initial commit\""
]
}

Template Variables

Templates support variables that are replaced during project creation:

  • {{projectName}} - The name of the project
  • {{username}} - The current user's username
  • {{date}} - Current date in YYYY-MM-DD format

Example usage in template:

{
"files": {
"README.md": {
"content": "# {{projectName}}\n\nCreated by {{username}} on {{date}}"
}
}
}

Advanced Template Features

Conditional Files

You can include files conditionally based on user input:

{
"files": {
"src/components/Button.tsx": {
"content": "...",
"condition": "includeUI"
}
},
"prompts": [
{
"name": "includeUI",
"type": "confirm",
"message": "Include UI components?",
"default": true
}
]
}

Post-Creation Scripts

Run scripts after the project is created:

{
"scripts": [
"npm install",
"git init",
"git add .",
"git commit -m \"Initial commit\""
]
}

Best Practices

When Creating Templates

  1. Keep it simple - Templates should provide a minimal starting point
  2. Use popular tools - Choose widely-adopted tools and frameworks
  3. Include documentation - Add README files explaining the project structure
  4. Configure linting - Include ESLint/Prettier or equivalent for code quality
  5. Set up testing - Include a basic testing setup
  6. Version control - Initialize git repository with appropriate .gitignore

When Using Templates

  1. Review the files - Examine the generated files before starting development
  2. Update dependencies - Check for newer versions of dependencies
  3. Customize configuration - Adjust configurations to match your needs
  4. Add project-specific files - Add any additional files specific to your project

Troubleshooting Templates

Template Not Found

If you get an error that a template is not found:

  1. Check that the template name is correct
  2. Verify the template exists in packages/opencode/templates/
  3. Ensure index.json includes the template

Dependency Installation Failures

If dependencies fail to install:

  1. Check your internet connection
  2. Verify you have the required package managers installed (npm, yarn, poetry, etc.)
  3. Try installing dependencies manually:
cd my-project
npm install # or poetry install for Python projects

File Generation Issues

If files are not generated correctly:

  1. Check the template JSON file for syntax errors
  2. Verify all required fields are present
  3. Ensure file paths are correct

Contributing Templates

To contribute a new template to Glimx:

  1. Fork the Glimx repository
  2. Create your template following the existing format
  3. Add it to index.json
  4. Test the template thoroughly
  5. Submit a pull request with documentation

Next Steps

After creating a project from a template:

  1. Review the generated files and README
  2. Install dependencies if not automatically installed
  3. Start the development server
  4. Begin customizing the project for your needs

For more information on using Glimx CLI: