name: Where to Find What
description: A quick lookup guide for navigating a repository: where to find endpoints, business logic, models, tests, configs, docs, scripts, plus search patterns and commands
Where to Find What
Overview
Reference guide ที่บอกว่า "หา X อยู่ไหน" สำหรับ common patterns ใน codebase เช่น หา API endpoints, database models, tests, configs ช่วยให้ AI และคนค้นหาได้เร็ว
Why This Matters
- Fast lookup: รู้ทันทีว่าต้องไปไฟล์ไหน
- No guessing: ไม่ต้อง grep หลายรอบ
- Pattern recognition: เข้าใจ conventions ของ repo
- Consistent navigation: ทุกคนหาเหมือนกัน
Core Concepts
1. Code Categories
- HTTP layer: routes/controllers/middleware
- Domain layer: use-cases/services/entities/policies
- Infrastructure: DB clients/repos, queues, external API adapters
- Shared: types, utils, constants, logging/errors
2. Search Patterns
- หาตาม “entry points”:
routes, controllers, handlers, index, main
- หาตาม “contracts”:
OpenAPI, schema, dto, types, events
- หาตาม “dependencies”: import paths, client constructors, env var names
3. Naming Conventions
- ยึดตาม suffixes (
*.service.ts, *.repository.ts, *.controller.ts)
- tests mirror source path
- configs อยู่ที่ root/config ตามมาตรฐานเดียวกัน
4. Common Lookups
- “endpoint อยู่ไหน” →
src/api/routes / src/routes
- “business rule อยู่ไหน” →
src/domain/* (หรือ src/modules/*/domain ใน monorepo)
- “DB schema อยู่ไหน” →
prisma/schema.prisma / migrations/ / src/db/models
5. Cross-References
- endpoint ↔ request/response types ↔ domain service ↔ repository ↔ migration
- event producer ↔ schema registry ↔ consumer handler ↔ DLQ runbook
- feature flag ↔ rollout plan ↔ dashboards/alerts
6. Test Locations
- unit tests อยู่ใกล้ domain หรือ mirror path ใน
tests/
- integration/e2e แยกเป็นโฟลเดอร์เฉพาะ เพื่อไม่ปนกับ unit
- fixtures/mocks มีตำแหน่งชัด (เช่น
tests/__fixtures__, tests/__mocks__)
7. Config Locations
- runtime env vars:
.env.example
- app config:
config/ หรือ src/config/
- infra deploy:
Dockerfile, k8s/, .github/workflows/, terraform/
8. Documentation Locations
- API:
docs/api/ หรือ docs/api.yaml
- Architecture:
docs/architecture/
- Runbooks:
docs/runbooks/
- ADRs:
docs/adr/
Quick Start
# Add a `WHERE.md` at repo root or `docs/`:
# - “Finding Code / Tests / Config / Docs” sections
# - Concrete path patterns + examples (not theory)
# - 5–10 copy/paste search commands for the repo
Production Checklist
Where to Find What Template
# WHERE.md - Quick Lookup Guide
## 🔍 Finding Code
### API Endpoints
```
Want: REST endpoint for /users
Look: src/api/routes/users.ts
Pattern: src/api/routes/{resource}.ts
```
### Business Logic
```
Want: User creation logic
Look: src/domain/users/services/createUser.ts
Pattern: src/domain/{entity}/services/{action}.ts
```
### Database Models
```
Want: User schema
Look: src/infrastructure/db/models/user.ts
Pattern: src/infrastructure/db/models/{entity}.ts
```
### Database Migrations
```
Want: Migration files
Look: prisma/migrations/
Pattern: prisma/migrations/{timestamp}_{name}/
```
### Type Definitions
```
Want: API request/response types
Look: src/api/types/{resource}.ts
Want: Domain types
Look: src/domain/{entity}/types.ts
```
### External API Integrations
```
Want: Stripe integration
Look: src/infrastructure/stripe/
Want: Email service
Look: src/infrastructure/email/
```
## 🧪 Finding Tests
### Unit Tests
```
Source: src/domain/users/services/createUser.ts
Test: tests/domain/users/services/createUser.test.ts
Pattern: tests/{mirror of src path}.test.ts
```
### Integration Tests
```
Look: tests/integration/{feature}/
Pattern: tests/integration/{feature}/*.test.ts
```
### E2E Tests
```
Look: tests/e2e/
Pattern: tests/e2e/{flow}.spec.ts
```
## ⚙️ Finding Configuration
| Config Type | Location |
|-------------|----------|
| Environment vars | `.env.example` |
| App config | `config/` |
| TypeScript | `tsconfig.json` |
| Linting | `.eslintrc.js` |
| Testing | `jest.config.js` |
| Docker | `Dockerfile`, `docker-compose.yml` |
| CI/CD | `.github/workflows/` |
## 📚 Finding Documentation
| Doc Type | Location |
|----------|----------|
| API reference | `docs/api/` |
| Architecture | `docs/architecture/` |
| Runbooks | `docs/runbooks/` |
| ADRs | `docs/adr/` |
## 🔧 Finding Scripts
| Script | Location | Usage |
|--------|----------|-------|
| Dev server | `npm run dev` | Local development |
| Build | `npm run build` | Production build |
| Migrations | `npm run db:migrate` | Run migrations |
| Seed data | `npm run db:seed` | Populate test data |
## 🗂️ By File Type
| I need... | File pattern | Example |
|-----------|--------------|---------|
| Controller | `*Controller.ts` | `UsersController.ts` |
| Service | `*Service.ts` | `UserService.ts` |
| Repository | `*Repository.ts` | `UserRepository.ts` |
| Middleware | `*Middleware.ts` | `AuthMiddleware.ts` |
| Validator | `*Validator.ts` | `UserValidator.ts` |
| DTO | `*Dto.ts` | `CreateUserDto.ts` |
```
Search Commands
# Find file by name
fd "UserService"
# Find definition
grep -r "class UserService" src/
# Find usage
grep -r "UserService" src/ --include="*.ts"
# Find tests for a file
fd "createUser.test" tests/
Anti-patterns
- Inconsistent structure: ไฟล์คล้ายกันอยู่คนละที่
- No pattern: ต้อง grep ทุกครั้ง
- Hidden files: สำคัญแต่หายาก
- No documentation: รู้แค่ในหัวคนเดิม
Integration Points
- IDE search configurations
- AI retrieval playbooks
- Onboarding materials
- Code review guides
Further Reading
1---2name: where-to-find-what3description: Reference guide ที่บอกว่า "หา X อยู่ไหน" สำหรับ common patterns ใน codebase เช่น หา API endpoints, database models, tests, configs ช่วยให้ AI และคนค้นหาได้เร็ว4---5
6---
7name: Where to Find What
8description: A quick lookup guide for navigating a repository: where to find endpoints, business logic, models, tests, configs, docs, scripts, plus search patterns and commands
9---
10
11# Where to Find What
12
13## Overview
14
15Reference guide ที่บอกว่า "หา X อยู่ไหน" สำหรับ common patterns ใน codebase เช่น หา API endpoints, database models, tests, configs ช่วยให้ AI และคนค้นหาได้เร็ว
16
17## Why This Matters
18
19- **Fast lookup**: รู้ทันทีว่าต้องไปไฟล์ไหน
20- **No guessing**: ไม่ต้อง grep หลายรอบ
21- **Pattern recognition**: เข้าใจ conventions ของ repo
22- **Consistent navigation**: ทุกคนหาเหมือนกัน
23
24---
25
26## Core Concepts
27
28### 1. Code Categories
29
30- HTTP layer: routes/controllers/middleware
31- Domain layer: use-cases/services/entities/policies
32- Infrastructure: DB clients/repos, queues, external API adapters
33- Shared: types, utils, constants, logging/errors
34
35### 2. Search Patterns
36
37- หาตาม “entry points”: `routes`, `controllers`, `handlers`, `index`, `main`
38- หาตาม “contracts”: `OpenAPI`, `schema`, `dto`, `types`, `events`
39- หาตาม “dependencies”: import paths, client constructors, env var names
40
41### 3. Naming Conventions
42
43- ยึดตาม suffixes (`*.service.ts`, `*.repository.ts`, `*.controller.ts`)
44- tests mirror source path
45- configs อยู่ที่ root/config ตามมาตรฐานเดียวกัน
46
47### 4. Common Lookups
48
49- “endpoint อยู่ไหน” → `src/api/routes` / `src/routes`
50- “business rule อยู่ไหน” → `src/domain/*` (หรือ `src/modules/*/domain` ใน monorepo)
51- “DB schema อยู่ไหน” → `prisma/schema.prisma` / `migrations/` / `src/db/models`
52
53### 5. Cross-References
54
55- endpoint ↔ request/response types ↔ domain service ↔ repository ↔ migration
56- event producer ↔ schema registry ↔ consumer handler ↔ DLQ runbook
57- feature flag ↔ rollout plan ↔ dashboards/alerts
58
59### 6. Test Locations
60
61- unit tests อยู่ใกล้ domain หรือ mirror path ใน `tests/`
62- integration/e2e แยกเป็นโฟลเดอร์เฉพาะ เพื่อไม่ปนกับ unit
63- fixtures/mocks มีตำแหน่งชัด (เช่น `tests/__fixtures__`, `tests/__mocks__`)
64
65### 7. Config Locations
66
67- runtime env vars: `.env.example`
68- app config: `config/` หรือ `src/config/`
69- infra deploy: `Dockerfile`, `k8s/`, `.github/workflows/`, `terraform/`
70
71### 8. Documentation Locations
72
73- API: `docs/api/` หรือ `docs/api.yaml`
74- Architecture: `docs/architecture/`
75- Runbooks: `docs/runbooks/`
76- ADRs: `docs/adr/`
77
78## Quick Start
79
80```markdown
81# Add a `WHERE.md` at repo root or `docs/`:
82# - “Finding Code / Tests / Config / Docs” sections
83# - Concrete path patterns + examples (not theory)
84# - 5–10 copy/paste search commands for the repo
85```
86
87## Production Checklist
88
89- [ ] Common lookups documented
90- [ ] Naming conventions explained
91- [ ] Search patterns provided
92- [ ] Updated when structure changes
93- [ ] Easy to scan/search
94
95## Where to Find What Template
96
97````markdown
98# WHERE.md - Quick Lookup Guide
99
100## 🔍 Finding Code
101
102### API Endpoints
103```
104Want: REST endpoint for /users
105Look: src/api/routes/users.ts
106Pattern: src/api/routes/{resource}.ts
107```
108
109### Business Logic
110```
111Want: User creation logic
112Look: src/domain/users/services/createUser.ts
113Pattern: src/domain/{entity}/services/{action}.ts
114```
115
116### Database Models
117```
118Want: User schema
119Look: src/infrastructure/db/models/user.ts
120Pattern: src/infrastructure/db/models/{entity}.ts
121```
122
123### Database Migrations
124```
125Want: Migration files
126Look: prisma/migrations/
127Pattern: prisma/migrations/{timestamp}_{name}/
128```
129
130### Type Definitions
131```
132Want: API request/response types
133Look: src/api/types/{resource}.ts
134
135Want: Domain types
136Look: src/domain/{entity}/types.ts
137```
138
139### External API Integrations
140```
141Want: Stripe integration
142Look: src/infrastructure/stripe/
143
144Want: Email service
145Look: src/infrastructure/email/
146```
147
148## 🧪 Finding Tests
149
150### Unit Tests
151```
152Source: src/domain/users/services/createUser.ts
153Test: tests/domain/users/services/createUser.test.ts
154Pattern: tests/{mirror of src path}.test.ts
155```
156
157### Integration Tests
158```
159Look: tests/integration/{feature}/
160Pattern: tests/integration/{feature}/*.test.ts
161```
162
163### E2E Tests
164```
165Look: tests/e2e/
166Pattern: tests/e2e/{flow}.spec.ts
167```
168
169## ⚙️ Finding Configuration
170
171| Config Type | Location |
172|-------------|----------|
173| Environment vars | `.env.example` |
174| App config | `config/` |
175| TypeScript | `tsconfig.json` |
176| Linting | `.eslintrc.js` |
177| Testing | `jest.config.js` |
178| Docker | `Dockerfile`, `docker-compose.yml` |
179| CI/CD | `.github/workflows/` |
180
181## 📚 Finding Documentation
182
183| Doc Type | Location |
184|----------|----------|
185| API reference | `docs/api/` |
186| Architecture | `docs/architecture/` |
187| Runbooks | `docs/runbooks/` |
188| ADRs | `docs/adr/` |
189
190## 🔧 Finding Scripts
191
192| Script | Location | Usage |
193|--------|----------|-------|
194| Dev server | `npm run dev` | Local development |
195| Build | `npm run build` | Production build |
196| Migrations | `npm run db:migrate` | Run migrations |
197| Seed data | `npm run db:seed` | Populate test data |
198
199## 🗂️ By File Type
200
201| I need... | File pattern | Example |
202|-----------|--------------|---------|
203| Controller | `*Controller.ts` | `UsersController.ts` |
204| Service | `*Service.ts` | `UserService.ts` |
205| Repository | `*Repository.ts` | `UserRepository.ts` |
206| Middleware | `*Middleware.ts` | `AuthMiddleware.ts` |
207| Validator | `*Validator.ts` | `UserValidator.ts` |
208| DTO | `*Dto.ts` | `CreateUserDto.ts` |
209```
210````
211
212## Search Commands
213
214```bash
215# Find file by name
216fd "UserService"
217
218# Find definition
219grep -r "class UserService" src/
220
221# Find usage
222grep -r "UserService" src/ --include="*.ts"
223
224# Find tests for a file
225fd "createUser.test" tests/
226```
227
228## Anti-patterns
229
2301. **Inconsistent structure**: ไฟล์คล้ายกันอยู่คนละที่
2312. **No pattern**: ต้อง grep ทุกครั้ง
2323. **Hidden files**: สำคัญแต่หายาก
2334. **No documentation**: รู้แค่ในหัวคนเดิม
234
235## Integration Points
236
237- IDE search configurations
238- AI retrieval playbooks
239- Onboarding materials
240- Code review guides
241
242## Further Reading
243
244- [Project Structure Patterns](https://blog.logrocket.com/node-js-project-architecture-best-practices/)
245- [Clean Architecture](https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html)