Off-the-shelf GitHub Copilot defaults to the broad internet average. Left to its own devices on a private enterprise repository, it will happily invent deprecated ORM calls, import banned utility libraries, bypass internal authentication wrappers, and dump raw database queries straight into your frontend handlers. If your system runs on custom Clean Architecture, Domain-Driven Design (DDD), or a multi-tenant monorepo, unguided AI assistance quickly becomes technical debt generation.
At 365Finds, we have tracked how engineering teams struggle with Copilot hallucinations on proprietary stacks. The fix is not badgering engineers to write fifty-word prompts every time they open a file. The fix is anchoring your architectural contracts into version-controlled instruction files that Copilot loads automatically.
Here is how to design, configure, and maintain workspace rules and instructions for custom project architectures in GitHub Copilot.
The Rule Hierarchy: How Copilot Ingests Your Architecture
GitHub Copilot does not ingest instructions as one giant blob. It relies on a tiered model designed to balance broad project identity with granular, folder-level constraints.
your-repo/
├── .github/
│ ├── copilot-instructions.md # Global baseline: repo-wide architectural rules
│ └── instructions/ # Path-specific constraints
│ ├── backend-services.instructions.md
│ └── frontend-ui.instructions.md
├── apps/
├── packages/
└── AGENTS.md # High-level agent orchestration contract
1. Global Baseline: .github/copilot-instructions.md
This is your project's constitutional document. Checked into the root of your repository under .github/, Copilot automatically attaches this file as background context for GitHub Copilot Chat, Copilot pull request summaries, and automated code review workflows.
2. Path-Specific Directives: .github/instructions/**/*.instructions.md
A monolithic instruction file fails the moment your repository contains both a React frontend and a Go microservice. Path-specific files live inside .github/instructions/ and use YAML frontmatter (applyTo) to match glob patterns. When a developer edits a file matching those paths, Copilot merges the path instructions on top of your global baseline.
3. Editor & Workspace Customization
In Visual Studio Code, workspace settings (.vscode/settings.json) or the Chat: Open Customizations panel link local workflows directly to these markdown files.
[!IMPORTANT] A critical boundary 365Finds insists every team understand: Workspace instructions strongly direct GitHub Copilot Chat, agent sessions, and PR code reviews. They have noticeably weaker and indirect leverage over millisecond inline completions (ghost text). Do not expect an instruction file to instantly replace your IDE linter or typechecker for typing completions.
Step 1: Establish Your Global Architecture Baseline
Create .github/copilot-instructions.md in your repository root.
Keep this file short, declarative, and negative-rule oriented. Large language models drift when fed twenty pages of abstract philosophy. At 365Finds, our rule of thumb is keeping this file under 80 lines. Focus on non-negotiable boundaries, foundational stack versions, and forbidden libraries.
Here is an architectural template for a structured TypeScript backend:
# Repository Architecture & Core Invariants
## Tech Stack & Runtime
- Runtime: Node.js 22 LTS with strict TypeScript 5.5+
- Framework: Fastify (do NOT use Express idioms or middleware)
- Persistence: PostgreSQL 16 managed via Kysely (never write raw knex or Prisma queries)
## Architectural Boundaries (Strict DDD)
- Controllers (`src/transport/http/`) only parse HTTP input and validate schemas using Zod.
- Business logic lives strictly in Domain Use-Cases (`src/core/usecases/`). Never call database adapters directly from controllers.
- Data access must implement domain interfaces located in `src/core/ports/`.
- All inter-service communication must route through `@company/internal-event-bus`. Direct REST calls to sibling services are prohibited.
## Error Handling & Observability
- Throw domain errors extending `AppError` from `@company/errors`. Never throw vanilla JavaScript `Error`.
- Never use `console.log`. Use `ctx.logger.info()` or `ctx.logger.error()`, always passing `requestId`.
Notice the direct prohibitions: "never write raw knex", "never throw vanilla JavaScript Error". Generative models respond far better to explicit guardrails than vague advice like "write clean code."
Step 2: Implement Path-Specific Instructions for Monorepos
If you run a monorepo or a service with distinct layers, .github/copilot-instructions.md is insufficient. Adding frontend styling rules to a global file pollutes the context when Copilot generates database migrations.
Inside .github/instructions/, create scoped .instructions.md files equipped with applyTo glob patterns.
Example: Backend Service Domain Rules (.github/instructions/services.instructions.md)
---
applyTo:
- "services/core-api/src/**"
- "packages/database-client/src/**"
---
# Core API Domain Rules
## Invariants
- Enforce transactional boundaries using our `UnitOfWork` pattern from `@company/db-uow`.
- For any entity mutation, emit an audit payload using `AuditLogService.record(...)`.
- Unit tests must use Vitest and run in-memory SQLite mocks; do not spin up network containers in unit test suites.
Example: UI Layer Rules (.github/instructions/frontend.instructions.md)
---
applyTo:
- "apps/web/src/**"
- "packages/ui-components/src/**"
---
# Web Client & Design System Rules
## Styling & Components
- Use Tailwind CSS with custom design tokens from `@company/design-tokens`.
- Do not introduce inline styles or CSS modules.
- Every interactive element must supply explicit `aria-label` or `aria-labelledby` attributes.
- Use TanStack Query v5 for server state. Never store API responses in Zustand stores.
When an engineer opens apps/web/src/features/billing/CheckoutCard.tsx and asks Copilot Chat to refactor the payment form, Copilot dynamically binds frontend.instructions.md without loading backend database rules into the prompt context window.
Step 3: Configure VS Code Workspace Hooks
To guarantee your development team’s local environment reflects these rules without manual intervention, commit workspace-level settings into version control under .vscode/settings.json.
{
"github.copilot.chat.commitMessageGeneration.instructions": [
{ "text": "Follow Conventional Commits (e.g., feat(billing): add stripe webhook handler). Max subject line 72 chars." }
],
"github.copilot.chat.codeGeneration.instructions": [
{ "file": ".github/copilot-instructions.md" }
]
}
Developers can also inspect active instructions inside VS Code by pressing Cmd+Shift+P (or Ctrl+Shift+P) and selecting Chat: Open Customizations. Under the Instructions tab, VS Code highlights which workspace files Copilot currently references.
Step 4: Validate That Copilot Honors the Rules
Do not assume Copilot obeys instructions simply because files are checked in. Test your configuration rigorously using deliberately provocative prompts in GitHub Copilot Chat.
Open a service file and ask:
"Write a function that updates the user subscription status and logs the event using console.log."
If your instruction rules are working:
- Copilot will refuse to use
console.log, opting instead forctx.logger.info(). - Copilot will pull
UnitOfWorkor your designated repository rather than invoking an arbitrary ORM. - In the Copilot Chat response header, check the References or Used Instructions fold. It will explicitly list
.github/copilot-instructions.mdand the matched.instructions.mdfile.
If Copilot fails to adhere, your instructions are either overly conversational or buried beneath conflicting repository documentation. Cut the prose down to bulleted imperatives.
What 365Finds Recommends vs. What to Avoid
| Practice | Why It Matters | 365Finds Verdict |
|---|---|---|
Modularizing with applyTo | Prevents context clutter; tailors token spend to the current subproject. | Strongly Recommended |
| Negative Constraints ("Do Not Use X") | Disables standard internet training patterns that violate your stack. | Strongly Recommended |
| Embedding Single Golden Examples | Shows exact indentation, import aliases, and wrapper structure. | Recommended (keep snippets under 20 lines) |
| Dumping Full API / Schema Documentation | Consumes massive prompt tokens, dilutes focus, and slows response time. | Avoid |
| Vague Platitudes ("Write Clean, Reusable Code") | Burns context budget without influencing generation outcomes. | Avoid |
| Relying on Instructions for Linter Tasks | Instructions cannot guarantee syntactic safety; use ESLint/Biome/CI. | Unrealistic Expectation |
At 365Finds, our conviction is that .github/copilot-instructions.md should be treated as production code. It belongs in Git, requires peer review on pull requests, and must be updated whenever you deprecate an internal library or shift an architectural boundary. When treated with that discipline, GitHub Copilot shifts from a generic autocomplete engine into a tool tailored to your proprietary architecture.