Skip to content

Commit a9f5d25

Browse files
CopilotRtur2003
andcommitted
Enhance 5 agent prompts, 3 project-type prompts, add troubleshooting guide
Co-authored-by: Rtur2003 <111705644+Rtur2003@users.noreply.github.com>
1 parent 2ecccb3 commit a9f5d25

9 files changed

Lines changed: 1216 additions & 61 deletions

prompts/english/agents/architecture-patterns-prompt.md

Lines changed: 122 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -378,15 +378,129 @@ Use this when making significant architecture decisions:
378378
| **Anemic domain model** | Logic in services, not entities | Move logic to domain objects |
379379
| **Over-engineering** | Complex for simple problem | Match architecture to scale |
380380

381+
## Serverless Architecture
382+
383+
### When to Use Serverless
384+
| Use Case | Serverless Fit | Alternative |
385+
|----------|---------------|-------------|
386+
| Variable traffic (0 to spike) | ✅ Excellent | - |
387+
| Long-running processes (>15 min) | ❌ Poor | Containers/ECS |
388+
| Low-latency (<50ms cold start) | ⚠️ Depends | Always-on containers |
389+
| Event-driven processing | ✅ Excellent | - |
390+
| Cost-sensitive, low traffic | ✅ Excellent | - |
391+
| High-throughput, steady load | ⚠️ Expensive | Reserved instances |
392+
393+
### Serverless Patterns
394+
```
395+
Event Sources → Functions → Integrations
396+
397+
┌──────────┐ ┌──────────┐ ┌──────────┐
398+
│ API GW │───→│ Lambda │───→│ DynamoDB │
399+
│ S3 Event │ │ Function │ │ SQS │
400+
│ SQS │ │ │ │ S3 │
401+
│ Schedule │ │ │ │ SNS │
402+
│ EventBridge│ │ │ │ Step Fn │
403+
└──────────┘ └──────────┘ └──────────┘
404+
```
405+
406+
## Event Sourcing & CQRS Deep Dive
407+
408+
### Event Sourcing Implementation
409+
```typescript
410+
// Events as the source of truth
411+
interface DomainEvent {
412+
eventId: string;
413+
aggregateId: string;
414+
eventType: string;
415+
version: number;
416+
timestamp: Date;
417+
data: Record<string, unknown>;
418+
}
419+
420+
// Event store — append-only
421+
class EventStore {
422+
async append(aggregateId: string, events: DomainEvent[], expectedVersion: number): Promise<void> {
423+
// Optimistic concurrency check
424+
const currentVersion = await this.getVersion(aggregateId);
425+
if (currentVersion !== expectedVersion) {
426+
throw new ConcurrencyError(`Expected version ${expectedVersion}, got ${currentVersion}`);
427+
}
428+
await this.db.insert('events', events);
429+
}
430+
431+
async getEvents(aggregateId: string, fromVersion?: number): Promise<DomainEvent[]> {
432+
return this.db.query(
433+
'SELECT * FROM events WHERE aggregate_id = ? AND version >= ? ORDER BY version',
434+
[aggregateId, fromVersion || 0]
435+
);
436+
}
437+
}
438+
439+
// Rebuild state from events
440+
class OrderAggregate {
441+
private state: OrderState = { status: 'new', items: [], total: 0 };
442+
443+
static fromEvents(events: DomainEvent[]): OrderAggregate {
444+
const order = new OrderAggregate();
445+
for (const event of events) {
446+
order.apply(event);
447+
}
448+
return order;
449+
}
450+
451+
private apply(event: DomainEvent): void {
452+
switch (event.eventType) {
453+
case 'OrderCreated':
454+
this.state = { ...this.state, status: 'created', ...event.data };
455+
break;
456+
case 'ItemAdded':
457+
this.state.items.push(event.data.item);
458+
this.state.total += event.data.item.price;
459+
break;
460+
case 'OrderCompleted':
461+
this.state.status = 'completed';
462+
break;
463+
}
464+
}
465+
}
466+
```
467+
468+
### Saga Pattern (Distributed Transactions)
469+
```
470+
Order Saga — Choreography:
471+
472+
┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐
473+
│ Order │───→│ Payment │───→│ Inventory│───→│ Shipping │
474+
│ Service │ │ Service │ │ Service │ │ Service │
475+
└──────────┘ └──────────┘ └──────────┘ └──────────┘
476+
│ │ │ │
477+
│ OrderCreated │ PaymentOK │ Reserved │ Shipped
478+
│ │ │ │
479+
│← ─ ─ ─ ─ ─ ─ ┤← ─ ─ ─ ─ ─ ─┤← ─ ─ ─ ─ ─ ─┤
480+
│ (compensate) │ (refund) │ (release) │
481+
482+
Compensation = Reverse each step on failure
483+
```
484+
485+
### Data Consistency Patterns
486+
| Pattern | Consistency | Performance | Use Case |
487+
|---------|------------|-------------|----------|
488+
| **Strong (2PC)** | Immediate | Slow | Financial transactions |
489+
| **Eventual (Saga)** | Delayed | Fast | E-commerce orders |
490+
| **CQRS** | Read lag | Very fast reads | Analytics, dashboards |
491+
| **Outbox** | Reliable | Medium | Event publishing |
492+
381493
---
382494

383495
## Remember
384496

385-
> **Architecture is about trade-offs. There are no silver bullets, only trade-offs you can live with.**
386-
387-
Architecture priorities:
388-
1. **Solve the current problem**: Don't architect for imaginary scale
389-
2. **Keep it simple**: Complexity is a liability
390-
3. **Make it evolvable**: Design for change, not perfection
391-
4. **Measure before optimizing**: Profile, don't guess
392-
5. **Document decisions**: Future you will thank you (ADRs)
497+
```
498+
✦ TRADE-OFFS: Architecture is about trade-offs — there are no silver bullets
499+
✦ START SIMPLE: Don't architect for imaginary scale — grow as needed
500+
✦ EVOLVE: Design for change, not perfection — modularize boundaries
501+
✦ DOCUMENT: ADRs capture why, not just what — future you will thank you
502+
✦ EVENT SOURCING: Events are facts — they tell the full story of your system
503+
✦ SAGA PATTERN: Compensating transactions for distributed consistency
504+
✦ SERVERLESS: Pay-per-use is powerful but understand cold starts and limits
505+
✦ MEASURE: Profile before optimizing — data beats intuition
506+
```

prompts/english/agents/fullstack-development-prompt.md

Lines changed: 152 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -396,15 +396,159 @@ const { data } = trpc.users.list.useQuery({ page: 1 });
396396
- [ ] Monitoring alerts configured
397397
```
398398

399+
## WebSocket & Real-Time Patterns
400+
401+
### Server-Sent Events (Simple Real-Time)
402+
```typescript
403+
// Server — SSE endpoint (lightweight alternative to WebSocket)
404+
app.get('/api/events', (req, res) => {
405+
res.writeHead(200, {
406+
'Content-Type': 'text/event-stream',
407+
'Cache-Control': 'no-cache',
408+
'Connection': 'keep-alive',
409+
});
410+
411+
const sendEvent = (event: string, data: unknown) => {
412+
res.write(`event: ${event}\ndata: ${JSON.stringify(data)}\n\n`);
413+
};
414+
415+
// Subscribe to updates
416+
const unsubscribe = eventBus.subscribe('task:updated', (task) => {
417+
sendEvent('task-update', task);
418+
});
419+
420+
req.on('close', () => {
421+
unsubscribe();
422+
res.end();
423+
});
424+
});
425+
426+
// Client — EventSource API
427+
const events = new EventSource('/api/events');
428+
events.addEventListener('task-update', (e) => {
429+
const task = JSON.parse(e.data);
430+
updateTaskInUI(task);
431+
});
432+
```
433+
434+
### WebSocket with Socket.io
435+
```typescript
436+
// Server
437+
import { Server } from 'socket.io';
438+
439+
const io = new Server(server, {
440+
cors: { origin: process.env.CLIENT_URL },
441+
connectionStateRecovery: {
442+
maxDisconnectionDuration: 2 * 60 * 1000, // 2 minutes
443+
},
444+
});
445+
446+
// Authentication middleware
447+
io.use(async (socket, next) => {
448+
const token = socket.handshake.auth.token;
449+
try {
450+
const user = await verifyToken(token);
451+
socket.data.user = user;
452+
next();
453+
} catch (err) {
454+
next(new Error('Authentication failed'));
455+
}
456+
});
457+
458+
io.on('connection', (socket) => {
459+
// Join user-specific room
460+
socket.join(`user:${socket.data.user.id}`);
461+
462+
// Join project rooms
463+
socket.on('join:project', async (projectId) => {
464+
const hasAccess = await checkProjectAccess(socket.data.user.id, projectId);
465+
if (hasAccess) socket.join(`project:${projectId}`);
466+
});
467+
468+
// Broadcast updates to project members
469+
socket.on('task:update', async (data) => {
470+
const task = await updateTask(data);
471+
io.to(`project:${task.projectId}`).emit('task:updated', task);
472+
});
473+
});
474+
475+
// Client (React hook)
476+
function useSocket(projectId: string) {
477+
const [socket, setSocket] = useState<Socket | null>(null);
478+
479+
useEffect(() => {
480+
const s = io(process.env.NEXT_PUBLIC_WS_URL!, {
481+
auth: { token: getAuthToken() },
482+
});
483+
s.emit('join:project', projectId);
484+
setSocket(s);
485+
return () => { s.disconnect(); };
486+
}, [projectId]);
487+
488+
return socket;
489+
}
490+
```
491+
492+
## Background Jobs & Task Queues
493+
494+
### BullMQ (Node.js)
495+
```typescript
496+
import { Queue, Worker } from 'bullmq';
497+
498+
// Producer — Add jobs to queue
499+
const emailQueue = new Queue('emails', {
500+
connection: { host: 'redis', port: 6379 },
501+
defaultJobOptions: {
502+
attempts: 3,
503+
backoff: { type: 'exponential', delay: 2000 },
504+
removeOnComplete: { count: 1000 },
505+
removeOnFail: { count: 5000 },
506+
},
507+
});
508+
509+
await emailQueue.add('welcome-email', {
510+
to: user.email,
511+
template: 'welcome',
512+
data: { name: user.name },
513+
});
514+
515+
// Scheduled/recurring jobs
516+
await emailQueue.add('daily-digest', { type: 'digest' }, {
517+
repeat: { pattern: '0 9 * * *' }, // Every day at 9 AM
518+
});
519+
520+
// Consumer — Process jobs
521+
const worker = new Worker('emails', async (job) => {
522+
switch (job.name) {
523+
case 'welcome-email':
524+
await sendEmail(job.data);
525+
break;
526+
case 'daily-digest':
527+
await generateAndSendDigest();
528+
break;
529+
}
530+
}, {
531+
connection: { host: 'redis', port: 6379 },
532+
concurrency: 5,
533+
limiter: { max: 10, duration: 1000 }, // 10 jobs/second
534+
});
535+
536+
worker.on('failed', (job, error) => {
537+
logger.error(`Job ${job?.id} failed:`, error);
538+
});
539+
```
540+
399541
---
400542

401543
## Remember
402544

403-
> **Full-stack development is about reducing the distance between idea and working product.**
404-
405-
Priorities:
406-
1. **Type safety end-to-end**: Catch errors at compile time
407-
2. **Convention over configuration**: Use framework defaults
408-
3. **Ship fast, iterate**: Get feedback early
409-
4. **Shared validation**: Same rules on client and server
410-
5. **Progressive enhancement**: Works without JS, better with it
545+
```
546+
✦ TYPE SAFETY END-TO-END: Catch errors at compile time — tRPC, Zod, Prisma
547+
✦ REAL-TIME: SSE for simple updates, WebSocket for bidirectional communication
548+
✦ BACKGROUND JOBS: Never process long tasks in request handlers — use queues
549+
✦ CONVENTION OVER CONFIG: Use framework defaults — Next.js, Nuxt, SvelteKit
550+
✦ SHARED VALIDATION: Same Zod schemas on client and server — single source of truth
551+
✦ PROGRESSIVE ENHANCEMENT: Works without JS, better with it
552+
✦ SHIP FAST: Get feedback early — iterate based on real usage
553+
✦ PRODUCTION READY: Health checks, monitoring, graceful shutdown, auto-scaling
554+
```

0 commit comments

Comments
 (0)