bunjs-architecture
Use when implementing clean architecture (routes/controllers/services/repositories), establishing camelCase conventions, designing Prisma schemas, or planning structured workflows for Bun.js applications. See bunjs for basics, bunjs-production for deployment.
What this skill does
# Bun.js Clean Architecture Patterns
## Overview
This skill covers layered architecture, clean code patterns, camelCase naming conventions, and structured implementation workflows for Bun.js TypeScript backend applications. Use this skill when building complex, maintainable applications that require strict separation of concerns.
**When to use this skill:**
- Implementing layered architecture (routes → controllers → services → repositories)
- Establishing coding conventions and naming standards
- Designing database schemas with Prisma
- Creating API endpoint specifications
- Planning implementation workflows
**See also:**
- **dev:bunjs** - Core Bun patterns, HTTP servers, basic database access
- **dev:bunjs-production** - Production deployment, Docker, AWS, Redis
- **dev:bunjs-apidog** - OpenAPI specifications and Apidog integration
## Clean Architecture Principles
### 1. Layered Architecture
**ALWAYS** separate concerns into distinct layers with single responsibilities:
```
┌─────────────────────────────────────┐
│ Routes Layer │ ← Define API routes, attach middleware
│ (src/routes/) │ Map to controllers
└──────────────┬──────────────────────┘
│
┌──────────────▼──────────────────────┐
│ Controllers Layer │ ← Handle HTTP requests/responses
│ (src/controllers/) │ Call services, no business logic
└──────────────┬──────────────────────┘
│
┌──────────────▼──────────────────────┐
│ Services Layer │ ← Implement business logic
│ (src/services/) │ Orchestrate repositories
└──────────────┬──────────────────────┘ No HTTP concerns
│
┌──────────────▼──────────────────────┐
│ Repositories Layer │ ← Encapsulate database access
│ (src/database/repositories/) │ Use Prisma, type-safe queries
└─────────────────────────────────────┘ No business logic
```
**Critical Rules:**
- Controllers NEVER contain business logic (only HTTP handling)
- Services NEVER access HTTP context (no `req`, `res`, `Context`)
- Repositories are the ONLY layer that touches Prisma/database
- Each layer depends only on layers below it
### 2. Dependency Flow
```typescript
// ✅ CORRECT: Downward dependency flow
Routes → Controllers → Services → Repositories → Database
// ❌ WRONG: Upward dependency (service accessing controller)
Service imports from Controller // NEVER DO THIS
// ❌ WRONG: Skip layers (controller accessing repository directly)
Controller → Repository // Should go through Service
```
### 3. Separation of Concerns
| Layer | Responsibilities | Forbidden |
|-------|------------------|-----------|
| **Routes** | Define endpoints, attach middleware, map to controllers | Business logic, DB access |
| **Controllers** | Extract data from HTTP, call services, format responses | Business logic, DB access, validation logic |
| **Services** | Business logic, orchestrate operations, manage transactions | HTTP handling, direct DB access |
| **Repositories** | Database queries, type-safe Prisma operations | Business logic, HTTP handling |
## camelCase Conventions (CRITICAL)
### Why camelCase Everywhere?
**TypeScript-first full-stack development requires ONE naming convention across all layers:**
- ✅ Database → Prisma → TypeScript → API → Frontend (1:1 mapping)
- ✅ Zero translation layer = zero mapping bugs
- ✅ Autocomplete works perfectly everywhere
- ✅ Type safety maintained end-to-end
**This is non-negotiable for our stack.**
### API Field Naming: camelCase
**CRITICAL: All JSON REST API field names MUST use camelCase.**
**Why:**
- ✅ Native to JavaScript/JSON - No transformation needed
- ✅ Industry standard - Google, Microsoft, Facebook, AWS use camelCase
- ✅ TypeScript friendly - Direct mapping to interfaces
- ✅ OpenAPI/Swagger convention - Standard for API specs
- ✅ Auto-generated clients - Expected by code generation tools
**Examples:**
```typescript
// ✅ CORRECT: camelCase
{
"userId": "123",
"firstName": "John",
"lastName": "Doe",
"emailAddress": "[email protected]",
"createdAt": "2025-01-06T12:00:00Z",
"isActive": true,
"phoneNumber": "+1234567890"
}
// ❌ WRONG: snake_case
{
"user_id": "123",
"first_name": "John",
"created_at": "2025-01-06T12:00:00Z"
}
// ❌ WRONG: PascalCase
{
"UserId": "123",
"FirstName": "John"
}
```
**Consistent Application:**
1. **Request Bodies**: All fields in camelCase
2. **Response Bodies**: All fields in camelCase
3. **Query Parameters**: Use camelCase (`pageSize`, `sortBy`, `orderBy`)
4. **Zod Schemas**: Define fields in camelCase
5. **TypeScript Interfaces**: Match API camelCase
### Database Naming: camelCase
**CRITICAL: All database identifiers (tables, columns, indexes, constraints) use camelCase.**
**Why:**
- ✅ Stack consistency - TypeScript is our primary language
- ✅ Zero translation layer - Database names map 1:1 with TypeScript types
- ✅ Reduced complexity - No snake_case ↔ camelCase conversion
- ✅ Modern ORM compatibility - Prisma, Drizzle, TypeORM work seamlessly
- ✅ Team productivity - Full-stack TypeScript developers think in camelCase
**Naming Rules:**
**1. Tables:** Singular, camelCase with `@@map()` to plural
```prisma
model User {
userId String @id
// ...
@@map("users") // Table name: users
}
```
**2. Columns:** camelCase
```prisma
userId, firstName, emailAddress, createdAt, isActive
```
**3. Primary Keys:** `{tableName}Id`
```prisma
userId // in users table
orderId // in orders table
productId // in products table
```
**4. Foreign Keys:** Same as referenced primary key
```prisma
model Order {
orderId String @id
userId String // references users.userId
user User @relation(fields: [userId], references: [userId])
}
```
**5. Boolean Fields:** Prefix with is/has/can
```prisma
isActive, isDeleted, isPublic
hasPermission, hasAccess
canEdit, canDelete
```
**6. Timestamps:** Consistent suffixes
```prisma
createdAt // creation time
updatedAt // last modification
deletedAt // soft delete time
lastLoginAt // specific event times
publishedAt
verifiedAt
```
**7. Indexes:** `idx{TableName}{ColumnName}`
```prisma
@@index([emailAddress], name: "idxUsersEmailAddress")
@@index([userId, createdAt], name: "idxOrdersUserIdCreatedAt")
```
**8. Constraints:**
```prisma
// Foreign keys (Prisma auto-generates, but can specify)
@@index([userId], map: "fkOrdersUserId")
// Unique constraints
@@unique([emailAddress], name: "unqUsersEmailAddress")
```
### Prisma Schema Example (Perfect Mapping)
```prisma
model User {
userId String @id @default(cuid())
emailAddress String @unique
firstName String?
lastName String?
phoneNumber String?
isActive Boolean @default(true)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
lastLoginAt DateTime?
orders Order[]
sessions Session[]
@@index([emailAddress], name: "idxUsersEmailAddress")
@@index([createdAt], name: "idxUsersCreatedAt")
@@map("users")
}
model Order {
orderId String @id @default(cuid())
userId String
totalAmount Decimal @db.Decimal(10, 2)
orderStatus String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
user User @relation(fields: [userId], references: [userId])
orderItems OrderItem[]
@@index([userId], name: "idxOrdersUserId")
@@index([createdAt], name: "idxOrdersCreatedAt")
@@map("orders")
}
model OrderItem {
orderItemId String @id @default(cuid())
orderId String
productId String
quantity Int
unitPrice Decimal @db.Decimal(10, 2)
order Order @relation(fields: [orderId], references: [orderId])
@@index([orderId], name: "idxOrderItemsOrderId")
@@map("orderItems")
}
```
### TypeScript Types (Perfect Match)
```typescript
// Exact 1:1 mapping with database and API
interface User {
userId: string;
emailAddrRelated in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.