4.7 KiB
4.7 KiB
Charon Copilot Instructions
Code Quality Guidelines
Every session should improve the codebase, not just add to it. Actively refactor code you encounter, even outside of your immediate task scope. Think about long-term maintainability and consistency. Make a detailed plan before writing code. Always create unit tests for new code coverage.
- DRY: Consolidate duplicate patterns into reusable functions, types, or components after the second occurrence.
- CLEAN: Delete dead code immediately. Remove unused imports, variables, functions, types, commented code, and console logs.
- LEVERAGE: Use battle-tested packages over custom implementations.
- READABLE: Maintain comments and clear naming for complex logic. Favor clarity over cleverness.
- CONVENTIONAL COMMITS: Write commit messages using
feat:,fix:,chore:,refactor:, ordocs:prefixes.
🚨 CRITICAL ARCHITECTURE RULES 🚨
- Single Frontend Source: All frontend code MUST reside in
frontend/. NEVER createbackend/frontend/or any other nested frontend directory. - Single Backend Source: All backend code MUST reside in
backend/. - No Python: This is a Go (Backend) + React/TypeScript (Frontend) project. Do not introduce Python scripts or requirements.
Big Picture
- Charon is a self-hosted web app for managing reverse proxy host configurations with the novice user in mind. Everything should prioritize simplicity, usability, reliability, and security, all rolled into one simple binary + static assets deployment. No external dependencies.
- Users should feel like they have enterprise-level security and features with zero effort.
backend/cmd/apiloads config, opens SQLite, then hands off tointernal/server.internal/configrespectsCHARON_ENV,CHARON_HTTP_PORT,CHARON_DB_PATHand creates thedata/directory.internal/servermounts the built React app (viaattachFrontend) wheneverfrontend/distexists.- Persistent types live in
internal/models; GORM auto-migrates them.
Backend Workflow
- Run:
cd backend && go run ./cmd/api. - Test:
go test ./.... - API Response: Handlers return structured errors using
gin.H{"error": "message"}. - JSON Tags: All struct fields exposed to the frontend MUST have explicit
json:"snake_case"tags. - IDs: UUIDs (
github.com/google/uuid) are generated server-side; clients never send numeric IDs. - Security: Sanitize all file paths using
filepath.Clean. Usefmt.Errorf("context: %w", err)for error wrapping. - Graceful Shutdown: Long-running work must respect
server.Run(ctx).
Frontend Workflow
- Location: Always work within
frontend/. - Stack: React 18 + Vite + TypeScript + TanStack Query (React Query).
- State Management: Use
src/hooks/use*.tswrapping React Query. - API Layer: Create typed API clients in
src/api/*.tsthat wrapclient.ts. - Forms: Use local
useStatefor form fields, submit viauseMutation, theninvalidateQuerieson success.
Cross-Cutting Notes
- VS Code Integration: If you introduce new repetitive CLI actions (e.g., scans, builds, scripts), register them in .vscode/tasks.json to allow for easy manual verification.
- Sync: React Query expects the exact JSON produced by GORM tags (snake_case). Keep API and UI field names aligned.
- Migrations: When adding models, update
internal/modelsANDinternal/api/routes/routes.go(AutoMigrate). - Testing: All new code MUST include accompanying unit tests.
- Ignore Files: Always check
.gitignore,.dockerignore, and.codecov.ymlwhen adding new file or folders.
Documentation
- Features: Update
docs/features.mdwhen adding capabilities. - Links: Use GitHub Pages URLs (
https://wikid82.github.io/charon/) for docs and GitHub blob links for repo files.
CI/CD & Commit Conventions
- Triggers: Use
feat:,fix:, orperf:to trigger Docker builds.chore:skips builds. - Beta:
feature/beta-releasealways builds. - History-Rewrite PRs: If a PR touches files in
scripts/history-rewrite/ordocs/plans/history_rewrite.md, the PR description MUST include the history-rewrite checklist from.github/PULL_REQUEST_TEMPLATE/history-rewrite.md. This is enforced by CI.
✅ Task Completion Protocol (Definition of Done)
Before marking an implementation task as complete, perform the following:
- Pre-Commit Triage: Run
pre-commit run --all-files.- If errors occur, fix them immediately.
- If logic errors occur, analyze and propose a fix.
- Do not output code that violates pre-commit standards.
- Verify Build: Ensure the backend compiles and the frontend builds without errors.
- Clean Up: Ensure no debug print statements or commented-out blocks remain.