copypasta_reddit

Untitled

Oct 12th, 2025
41
0
179 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.08 KB | None | 0 0
  1. # initial_prompt.md
  2.  
  3. ## AI Prompt for Web Application Development Workflow
  4.  
  5. The stack and constraints:
  6. - Backend: Node.js v22, Express, TypeScript, Prisma (PostgreSQL 16), Zod, JWT, PM2, Jest, ts-jest
  7. - Frontend: Next.js (React 18 + TypeScript), TailwindCSS, Axios.
  8. - Auth: Google SSO + email/password, account migration from email β†’ Google SSO, JWT authorization, credential encryption
  9. - DB: PostgreSQL 16 in its own Docker container, Prisma ORM + Migrate
  10. - Containers: Docker and Docker Compose (separate app and DB containers), persistent DB volume
  11. - Scripts: start.sh waits for dependencies; shutdown.sh gracefully stops all containers
  12. - Validation/formatting: Zod for runtime validation; Prettier for code formatting
  13. - Process: Work in an existing Git repo; commit after each validated feature
  14. - Roles: First registered user β†’ ADMINISTRATOR; subsequent users β†’ INTERVIEWEE; third role β†’ INTERVIEWER. Admins can manage users/roles, and there must always be at least one ADMINISTRATOR. INTERVIEWER/INTERVIEWEE land on a welcome page. All pages include Logout.
  15. - UI/UX: High-contrast dark mode; professional palette (#a30502, #f78b04, #2b1718, #153a42, #027f93); clean, readable typography; responsive layout; smooth animations/transitions; WCAG 2.2 compliant
  16. - Secrets: Config files in /config; fallback to environment variables if missing
  17. - Logging: Application logs + separate audit logs for ADMINISTRATOR/INTERVIEWER actions
  18. - Resource/performance: Optimize container orchestration resources
  19. - Documentation: Automatic generation (see Documentation Strategy)
  20. - Observability: Add placeholders and TODO comments where Datadog monitoring will be integrated
  21. - i18n readiness: Design architecture to be internationalization-ready for future expansion
  22. - Use context7 mcp to consult latest documentation during implementation
  23. - Test goals: 100% test pass rate and target 100% coverage; when not achievable, create TODO markdown of deferred tests
  24.  
  25. ---
  26.  
  27. ## 🎯 Objective
  28.  
  29. You are an expert AI web application developer and product manager. Generate a **comprehensive, production-ready implementation plan** for a modern full-stack TypeScript application with a Node.js + Express backend and a React 18 + Next.js frontend styled with TailwindCSS.
  30. The plan must include **tasks, subtasks, and atomic tasks**, addressing **dependencies, edge cases, tests, rollback strategies, and documentation updates**.
  31.  
  32. The process should be **iterative**, **self-analyzing**, and **checkpoint-driven**, producing not just instructions but reflections and validations at each major phase. Actively perform self-analysis of your nature, choices, and reasoning as you plan and write. As you generate text (plans, designs, code, tests), refer to, interpret, and evolve your approach based on what you just wrote. This continuous meta-analysis must be explicit and actionable.
  33.  
  34. ---
  35.  
  36. ## 🧱 Core Tech Stack
  37.  
  38. ### Frontend
  39. - **Framework:** Next.js (React 18 + TypeScript)
  40. - **Styling:** TailwindCSS
  41. - **API Layer:** Axios for HTTP communication
  42. - **Optional Tools:** Storybook for component documentation
  43. - **Bundler:** Built-in Next.js
  44.  
  45. ### Backend
  46. - **Runtime:** Node.js 22+ (ESM, `"type": "module"`)
  47. - **Framework:** Express (TypeScript)
  48. - **ORM:** Prisma (PostgreSQL)
  49. - **Validation:** Zod (source of truth for OpenAPI)
  50. - **API Docs:** OpenAPI 3.1 β†’ Redoc / Swagger UI
  51.  
  52. ### Monorepo
  53. - **Tooling:** Turborepo
  54. - **Structure:**
  55. - `apps/web` β†’ Next.js frontend
  56. - `apps/api` β†’ Express backend
  57. - `apps/docs` β†’ Docusaurus documentation site
  58. - `packages/ui`, `packages/shared` β†’ shared components and utilities
  59.  
  60. ---
  61.  
  62. ## βš™οΈ Database & Persistence
  63.  
  64. - **DB:** PostgreSQL 16
  65. - **ORM:** Prisma ORM with migrations
  66. - **Soft Deletes:** For user-generated content (`deleted_at`)
  67. - **Indexes:** Partial indexes and partitioning for large tables
  68. - **Pooling:** PgBouncer (local and prod)
  69. - **Constraints:** Always β‰₯1 admin, transactional updates
  70. - **Tuning:** WAL, shared buffers, autovacuum, and query analysis (EXPLAIN/ANALYZE)
  71.  
  72. ---
  73.  
  74. ## πŸ”’ Authentication & Authorization
  75.  
  76. - **Flows:** Email/password and Google SSO
  77. - **Tokens:** Short-lived JWTs (5–10m) + refresh cookies (HTTP-only, Secure, SameSite=Lax)
  78. - **Key Rotation:** JWKS endpoint with dual-key rotation
  79. - **Roles:** ADMINISTRATOR, INTERVIEWER, INTERVIEWEE
  80. - **Break-glass Recovery:** CLI-based superadmin
  81. - **Rate Limits:** /auth and /api endpoints with per-IP/user quotas
  82. - **CSRF:** Double-submit token pattern
  83.  
  84. ---
  85.  
  86. ## 🧰 API Design & Documentation
  87.  
  88. - **Zod-to-OpenAPI:** Zod schemas define API contracts.
  89. - **Endpoints:** `/openapi.json` (machine-readable) + `/docs/api` (Redoc)
  90. - **Versioned Docs:** Snapshot docs per release tag.
  91. - **Docs CI/CD:**
  92. 1. Generate OpenAPI JSON
  93. 2. Run TypeDoc
  94. 3. Build Docusaurus
  95. 4. Publish versioned docs
  96.  
  97. ---
  98.  
  99. ## πŸ§ͺ Testing & Quality Gates
  100.  
  101. - **Unit/Integration:** Jest (ESM config)
  102. - **E2E:** Playwright
  103. - **Mutation Testing:** Stryker
  104. - **Accessibility:** @axe-core/playwright (fails on WCAG 2.2 AA issues)
  105. - **Visual Regression:** Playwright snapshots
  106. - **Coverage Targets:** Global β‰₯90%, critical modules 100%
  107. - **Deferred Tests:** Create TODO markdown for deferred/unimplemented tests
  108.  
  109. ---
  110.  
  111. ## 🩺 Runtime, Health, and Observability
  112.  
  113. - **Containers:** Single process per container
  114. - **Health Checks:** `/healthz`, `/readyz` (checks DB, JWKS, migrations)
  115. - **Metrics:** `/metrics` endpoint (Prometheus)
  116. - **Observability Hooks:** `traceSpan()`, `metricCounter()`, `logContext()`
  117. - **Secrets Management:** Cloud Secret Manager or Vault
  118. - **CORS/TLS:** Strict enforcement and cookie hardening
  119. - **TODO:** Add Datadog APM/trace TODO placeholders inline in code
  120.  
  121. ---
  122.  
  123. ## 🧭 Workflow and Feature Development Loop
  124.  
  125. Each feature must follow this loop before completion:
  126.  
  127. 1. **Work Plan Creation**
  128. - Produce a high-level work plan broken down into:
  129. - Major tasks β†’ subtasks β†’ atomic tasks
  130. - Include for each task:
  131. - Acceptance criteria and objective success metrics
  132. - Quality gates (lint/typecheck/test/coverage thresholds)
  133. - Rollback triggers (explicit conditions to revert)
  134.  
  135. 2. **UI/UX Planning and Approval**
  136. - Create UI/UX screenshot mockups for every page/feature BEFORE implementation.
  137. - **Element Identification**: Each visible element must have a clear element name or element ID in the screenshot for precise feedback and revisions.
  138. - **Multi-Step Workflows**: For features with multiple steps or states, provide a screenshot per step/state.
  139. - Support iterative refinement: accept feedback referencing element IDs/names and generate updated mockups.
  140. - Apply palette, dark mode, responsive layout, hierarchy, animations, and WCAG 2.2.
  141. - Do not proceed to implementation until UI/UX has been approved.
  142.  
  143. 3. **Test Case Creation**
  144. - After approval, detail comprehensive frontend, backend, and E2E test cases.
  145. - Define pass criteria, coverage targets, test metrics.
  146. - Include security, accessibility, and performance tests where appropriate.
  147. - If tests cannot be fully implemented immediately, create a TODO markdown file listing deferred tests and rationales.
  148.  
  149. 4. **Feature Development**
  150. - Backend: Express + TS + Prisma + Zod + JWT
  151. - Frontend: Next.js (React 18 + TS) + TailwindCSS + Axios + Vite
  152. - Implement with strict typing, runtime validation, secure API handling, error management.
  153. - use secure APIs and error handling.
  154.  
  155. 5. **Testing & Rollback Plan**
  156. - Implement Jest, Playwright tests aiming for 100% coverage and pass.
  157. - If tests fail:
  158. - Fix iteratively until passing.
  159. - If persistent, ask to create a TODO markdown listing deferred tests and continue.
  160. - If app breaks after last working feature:
  161. - Use Git checkpoints or Git tags and impact assessment to rollback to stable state.
  162. - Refine the feature prompt and re-implement.
  163.  
  164. 6. **Containerization & Optimization**
  165. - Use Docker multi-stage builds for app and database.
  166. - Apply resource and performance optimization strategies (CPU/memory limits in compose/yaml).
  167. - Provide start.sh that waits for all dependencies (DB Healthy), and shutdown.sh for graceful termination.
  168. - Use Docker Compose.
  169.  
  170. 7. **Database Schema & Optimization**
  171. - Define schemas with Prisma, use migrations.
  172. - Follow PostgreSQL best practices:
  173. - Normalized schemas, indexed columns per query pattern.
  174. - Use appropriate data types and constraints, foreign keys, and soft deletes selectively.
  175. - Indexing strategies: B+ trees, GIN for JSONB, partial indexes.
  176. - Partition large tables by time or domain if applicable.
  177. - Ensure data durability with persistent volumes.
  178.  
  179. 8. **Authentication & Role Migration**
  180. - Support email/password and Google SSO login.
  181. - Implement a migration workflow:
  182. - User initiates account migration.
  183. - Only complete if Google SSO auth succeeds.
  184. - If an existing SSO account exists, prompt merge.
  185. - Perform atomic migration, with rollback on error.
  186. - Log all steps and outcomes.
  187. - Enforce roles:
  188. - First user β†’ ADMINISTRATOR
  189. - Later users β†’ INTERVIEWEE, INTERVIEWER.
  190. - Admins manage users/roles via admin page, maintaining at least one admin.
  191. - Landing pages for interviewee/interviewer.
  192.  
  193. 9. **Secrets, Configuration**
  194. - Config files stored in `/config`; fallback to environment variables if files missing.
  195. - Secure handling; no secrets baked into images.
  196.  
  197. 10. **Logging & Audit**
  198. - Structured JSON logs with correlation/request IDs.
  199. - Application logs + audit logs for all moderator/admin actions.
  200. - Redact PII; configure log levels.
  201.  
  202. 11. **Commit Strategy**
  203. - Commit after each feature/validation step.
  204. - Use conventional commits.
  205. - Tag releases at stable points.
  206.  
  207. 12. **Documentation & Monitoring Placeholders**
  208. - Generate API docs (OpenAPI + Redocly or alternatives), TypeDoc, and Docusaurus docs site.
  209. - Automate docs updates via CI.
  210. - TODO placeholders for Datadog instrumentation in code:
  211. - APM trace setup
  212. - Metrics endpoints
  213. - Log enrichment
  214. - Placeholder health endpoints at `/healthz`, `/readyz`.
  215.  
  216. 13. **Internationalization (i18n)**
  217. - Architecture prepared for multi-language support:
  218. - Configured locales in Next.js
  219. - Message catalogs; ICU formatting
  220. - Design for text expansion, RTL support
  221. - URL schemas for localized paths
  222. - Current only English; ready for future expansion.
  223.  
  224. 14. **Deployment Configurations**
  225. - Local Docker Compose setup:
  226. - Multi-stage Dockerfiles for app and Postgres
  227. - Persistent Postgres volume
  228. - start.sh / shutdown.sh scripts
  229. - AWS:
  230. - ECR, Terraform templates
  231. - ECS Fargate / EKS options
  232. - Secrets: AWS Secrets Manager / Parameter Store
  233. - Monitoring placeholders (TODO for Datadog)
  234. - GCP:
  235. - Artifact Registry, Cloud Run / GKE
  236. - Cloud SQL for PostgreSQL
  237. - Azure:
  238. - ACR, Container Apps or AKS
  239. - Azure Database for PostgreSQL
  240. - Secrets via Key Vault
  241. - Multi-cloud considerations:
  242. - Standardize images, use environment-specific configs, IaC templates.
  243.  
  244. 15. **Container Optimization & Security**
  245. - Use multi-stage Docker builds.
  246. - Run containers non-root.
  247. - Apply resource limits; health checks; update scanning.
  248. - Secrets injected at runtime securely.
  249.  
  250. 16. **Security & JWT**
  251. - Short-lived tokens, refresh tokens.
  252. - Secure cookies, CSRF protections.
  253. - Rate limit login endpoints.
  254. - Maintain JWT key rotation strategy.
  255.  
  256.  
  257. ---
  258.  
  259. ## 🧠 Self-Analysis Protocol
  260.  
  261. After each major step, perform a brief reflective evaluation:
  262. - Identify 2–3 **risks or weaknesses** in approach.
  263. - Compare **alternative strategies**.
  264. - Record **decision rationale** and potential downstream impact.
  265. - Maintain decision log for traceability.
  266.  
  267. ---
  268.  
  269. ## πŸ” Rollback & Recovery
  270.  
  271. - Use Git tags as stable checkpoints.
  272. - Conduct impact analysis before rollback.
  273. - Prefer partial rollback (component-level) before full revert.
  274. - Document causes, fixes, and revalidation notes.
  275.  
  276. ---
  277.  
  278. ## 🧾 Definition of Done (DoD)
  279.  
  280. - [ ] Lint & Typecheck clean
  281. - [ ] All tests pass
  282. - [ ] Coverage β‰₯90%
  283. - [ ] Accessibility checks pass
  284. - [ ] Docs updated
  285. - [ ] Observability hooks added
  286. - [ ] Audit logs validated
  287. - [ ] Rollback strategy documented
  288.  
  289. ---
  290.  
  291. ## πŸ“„ Documentation Strategy
  292.  
  293. - Generate:
  294. - OpenAPI spec + Redocly site
  295. - TypeDoc code reference
  296. - Docusaurus guides/tutorials
  297. - CI Integration:
  298. - Auto-build on merge
  299. - Version docs per tag
  300. - Publish to `docs.example.com`
  301.  
  302. ---
  303.  
  304. ## 🌐 Internationalization (i18n)
  305.  
  306. - **Routing:** Next.js i18n routing
  307. - **Localization:** ICU format messages (`@formatjs`)
  308. - **RTL:** Tailwind config for RTL support
  309. - **Expansion:** Plan for additional locales and path schemas
  310.  
  311. ---
  312.  
  313. ## πŸš€ CI/CD & Deployment
  314.  
  315. - **Pipeline:** GitHub Actions or GitLab CI
  316. - **Stages:** install β†’ build β†’ test β†’ docs β†’ deploy
  317. - **Environments:** staging (on PR merge) and production (on tag)
  318. - **Cloud Options:** AWS ECS/GKE/Cloud Run with IaC templates
  319. - **Secrets:** Managed by Secret Manager or Parameter Store
  320. - **Monitoring:** TODO placeholders for Datadog, Prometheus
  321.  
  322. ---
  323.  
  324. ## 🧩 Additional Guidelines
  325.  
  326. - Follow **12-factor app** principles (no config files in repo)
  327. - Enforce **security linting** (`eslint-plugin-security`)
  328. - Use **feature flags** for incremental rollout
  329. - Apply **Renovate or Dependabot** for dependencies
  330. - Maintain **audit logs** with correlation IDs
  331. - **Never store secrets in images**
  332.  
  333. ---
  334.  
  335. ## πŸ“˜ Output Requirements
  336.  
  337. The generated plan must include:
  338. 1. Phases & milestones (setup β†’ deployment)
  339. 2. Tasks, subtasks, atomic tasks with dependencies
  340. 3. Edge cases, rollback paths, and fallback strategies
  341. 4. Required files & configuration snippets
  342. 5. Commit checkpoints & changelog references
  343. 6. Cross-linked docs and self-analysis checkpoints
  344.  
  345. ---
  346.  
  347. ### Final Notes
  348. - All steps must have clear acceptance criteria.
  349. - Use iterative refinement: mockups, tests, configs.
  350. - Documentation and code must comply with latest standards.
  351. - Self-reflection and pattern recognition enhance decision quality.
  352.  
  353. ---
  354.  
  355. ### End of initial_prompt.md
Advertisement
Add Comment
Please, Sign In to add comment