Polyglot Repo Toolchain Design
This design provides a scalable, zero-config (for devs) toolchain for polyglot repositories (e.g., Python, JavaScript/TypeScript, Go, Java, Rust). It enforces consistency across languages via shared configs, linters/formatters per-language, checks (security, licenses, deps), and CI/CD pipelines.
Key principles:
- Developer-friendly: Local enforcement via
pre-commit hooks (runs on git commit).
- Shared everything: Language-agnostic tools first, then per-lang.
- Fail-fast CI: Mirrors local hooks; runs on PRs/pushes.
- Extensible: Easy to add languages.
- Tools: GitHub Actions (portable to GitLab/Azure),
pre-commit, act for local CI testing.
Assumes a repo structure like:
polyglot-repo/
├── .pre-commit-config.yaml # Core orchestrator
├── .editorconfig # Editor consistency
├── .github/workflows/ # CI
│ └── ci.yaml
├── pyproject.toml # Python config
├── package.json # JS/TS config
├── go.work # Go workspace
├── README.md
└── src/ # Code by lang (python/, js/, go/, etc.)
├── python/
├── js/
└── go/
1. Shared Configs
These apply repo-wide for consistency.
.editorconfig
Enforces indentation, line endings, etc.
root = true
[*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
charset = utf-8
[*.{py,js,ts,go,java,rs}]
indent_style = space
indent_size = 4
[*.{md,yaml,yml,json}]
indent_style = space
indent_size = 2
.gitignore (shared patterns + lang-specific)
Use gitignore.io generator + append:
# Global
.DS_Store
*.log
node_modules/
__pycache__/
target/ # Java/Rust/Go
...
# Lang-specific below
License & Headers
- Single
LICENSE (MIT/Apache).
- Enforce headers via
addlicense hook (see pre-commit).
README Template
Use cookiecutter or just a standard:
# Polyglot Repo
## Setup
```bash
pre-commit install
Linting
pre-commit run --all-files
## 2. Linters & Formatters (via pre-commit)
`pre-commit` orchestrates **local hooks** (install once: `pipx install pre-commit && pre-commit install`). Runs on commit/PR.
### Install & Core Config: `.pre-commit-config.yaml`
```yaml
repos:
# Shared (lang-agnostic)
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files # >50MB
- id: check-merge-conflict
- id: detect-private-key # Secrets
- id: detect-aws-credentials
- repo: https://github.com/pre-commit/mirrors-prettier # Markdown/JSON/YAML
rev: v4.0.0-alpha.7
hooks:
- id: prettier
- repo: https://github.com/google/addlicense
rev: v1.2.0
hooks:
- id: addlicense
args: ["-c=MIT", "-y=2024", "-l=mit"]
# Python
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.1
hooks:
- id: ruff # Lint + format (replaces flake8/black/isort)
args: [--fix]
- id: ruff-format
# JS/TS
- repo: https://github.com/pre-commit/mirrors-eslint
rev: v9.6.0
hooks:
- id: eslint
# Go
- repo: https://github.com/golangci/golangci-lint
rev: v1.61.0
hooks:
- id: golangci-lint
# Java (Maven/Gradle)
- repo: https://github.com/diffplug/spotless-maven-pre-commit or similar
# Or use Spotless Gradle plugin
# Rust
- repo: https://github.com/rust-lang/rust-clippy
rev: nightly # Or stable
hooks:
- id: clippy
# Consistency Checks (shared)
- repo: https://github.com/pre-commit/identify-base-files
rev: v1.0.4
hooks:
- id: identify-base-files # Ensure README, LICENSE exist
# Run all: pre-commit run --all-files
Per-lang setup (idempotent):
- Python:
pip install ruff
- JS:
npm install --save-dev eslint prettier @typescript-eslint/parser
- Go:
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
- Share ESLint/Prettier config via
.eslintrc.json and .prettierrc.
3. Consistency Checks
Beyond linters:
- Deps:
pip-audit (Python), npm audit, go mod tidy.
- Security:
trivy or snyk (add to pre-commit).
- Docker/Containers:
hadolint.
- Markdown:
markdownlint-cli.
- Changelog:
git-chglog hook.
- No TODOs in prod code: Custom hook with
rg --type=py,js,go "TODO|FIXME".
Add to pre-commit:
- repo: https://github.com/pyupio/pip-audit-pre-commit
rev: v4.1.2
hooks:
- id: pip-audit
4. CI Pipeline (GitHub Actions)
Mirrors pre-commit + tests/builds. Use matrix for langs.
.github/workflows/ci.yaml
name: CI
on: [push, pull_request]
jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # For golangci-lint
- uses: actions/setup-python@v5
with: { python-version: '3.12' }
- uses: pre-commit/action@v3.0.1 # Runs all hooks!
test:
needs: pre-commit
runs-on: ubuntu-latest
strategy:
matrix:
lang: [python, js, go]
steps:
- uses: actions/checkout@v4
# Python
- if: matrix.lang == 'python'
run: |
pip install -e .[test]
pytest
# JS
- if: matrix.lang == 'js'
uses: actions/setup-node@v4
with: { node-version: 20 }
run: npm ci && npm test
# Go
- if: matrix.lang == 'go'
uses: actions/setup-go@v5
with: { go-version: '1.23' }
run: go test ./...
security:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: aquasecurity/trivy-action@master
with:
scan-type: 'fs'
format: 'sarif'
output: 'trivy-results.sarif'
- uses: github/codeql-action/analyze@v3 # Free vuln scanning
Advanced:
- Cache:
actions/cache for node_modules, ~/.cache/pip, ~/go/pkg/mod.
- CD: Add
deploy job on main (e.g., Docker build/push).
- Badges: Use
shields.io for CI status.
Onboarding & Maintenance
- New dev:
pre-commit install → Auto-lint on commit.
- Add lang: Append hook to
.pre-commit-config.yaml, update CI matrix.
- Local CI test:
brew install act → act.
- Update hooks:
pre-commit autoupdate.
- Enforce: Block merges if CI fails (repo settings).
This setup is battle-tested (inspired by Google/Meta open-source repos). Total setup: ~30min. Scales to 10+ langs. Ping for lang-specific tweaks! 🕵️♂️