cortex-tms 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +258 -0
- package/bin/cortex-tms.js +34 -0
- package/dist/__tests__/init.test.d.ts +2 -0
- package/dist/__tests__/init.test.d.ts.map +1 -0
- package/dist/__tests__/init.test.js +172 -0
- package/dist/__tests__/init.test.js.map +1 -0
- package/dist/__tests__/utils/temp-dir.d.ts +6 -0
- package/dist/__tests__/utils/temp-dir.d.ts.map +1 -0
- package/dist/__tests__/utils/temp-dir.js +34 -0
- package/dist/__tests__/utils/temp-dir.js.map +1 -0
- package/dist/__tests__/validate.test.d.ts +2 -0
- package/dist/__tests__/validate.test.d.ts.map +1 -0
- package/dist/__tests__/validate.test.js +207 -0
- package/dist/__tests__/validate.test.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +32 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/init.d.ts +4 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +121 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/validate.d.ts +4 -0
- package/dist/commands/validate.d.ts.map +1 -0
- package/dist/commands/validate.js +151 -0
- package/dist/commands/validate.js.map +1 -0
- package/dist/types/cli.d.ts +94 -0
- package/dist/types/cli.d.ts.map +1 -0
- package/dist/types/cli.js +2 -0
- package/dist/types/cli.js.map +1 -0
- package/dist/utils/config.d.ts +13 -0
- package/dist/utils/config.d.ts.map +1 -0
- package/dist/utils/config.js +185 -0
- package/dist/utils/config.js.map +1 -0
- package/dist/utils/detection.d.ts +5 -0
- package/dist/utils/detection.d.ts.map +1 -0
- package/dist/utils/detection.js +60 -0
- package/dist/utils/detection.js.map +1 -0
- package/dist/utils/prompts.d.ts +5 -0
- package/dist/utils/prompts.d.ts.map +1 -0
- package/dist/utils/prompts.js +82 -0
- package/dist/utils/prompts.js.map +1 -0
- package/dist/utils/templates.d.ts +14 -0
- package/dist/utils/templates.d.ts.map +1 -0
- package/dist/utils/templates.js +98 -0
- package/dist/utils/templates.js.map +1 -0
- package/dist/utils/validator.d.ts +12 -0
- package/dist/utils/validator.d.ts.map +1 -0
- package/dist/utils/validator.js +241 -0
- package/dist/utils/validator.js.map +1 -0
- package/package.json +69 -0
- package/templates/.github/copilot-instructions.md +28 -0
- package/templates/CLAUDE.md +18 -0
- package/templates/FUTURE-ENHANCEMENTS.md +79 -0
- package/templates/NEXT-TASKS.md +20 -0
- package/templates/README.md +172 -0
- package/templates/docs/archive/v1.0-CHANGELOG.md +0 -0
- package/templates/docs/core/ARCHITECTURE.md +102 -0
- package/templates/docs/core/DECISIONS.md +83 -0
- package/templates/docs/core/DOMAIN-LOGIC.md +8 -0
- package/templates/docs/core/GLOSSARY.md +66 -0
- package/templates/docs/core/PATTERNS.md +55 -0
- package/templates/docs/core/SCHEMA.md +246 -0
- package/templates/docs/core/TROUBLESHOOTING.md +325 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# Architecture: [Project Name]
|
|
2
|
+
|
|
3
|
+
## 🎯 Quick Context (For AI Agents)
|
|
4
|
+
<!-- This section provides high-level orientation in 3 bullets -->
|
|
5
|
+
- **What it does**: [One sentence - e.g., "A CLI tool that scaffolds AI-optimized project documentation"]
|
|
6
|
+
- **Who it's for**: [Target audience - e.g., "Developers building greenfield projects with AI coding assistants"]
|
|
7
|
+
- **Key constraint**: [Critical limitation - e.g., "Must run offline", "Sub-100ms API responses", "Zero external dependencies"]
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## 🏗️ System Overview
|
|
12
|
+
[Briefly describe what the system does and the problem it solves. 2-3 sentences max.]
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## 🧠 Mental Model
|
|
17
|
+
[Describe the high-level concept or metaphor that explains how the system works. This helps both humans and AI agents understand the core logic.]
|
|
18
|
+
|
|
19
|
+
**Example**: "A centralized hub for documentation that uses a tiered memory system to optimize AI context" or "A real-time event pipeline where actions flow through validation → execution → logging stages."
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## 📂 Component Map
|
|
24
|
+
|
|
25
|
+
| Component | Responsibility | Tech Stack |
|
|
26
|
+
|:----------|:---------------|:-----------|
|
|
27
|
+
| [e.g., Frontend] | [User interaction layer] | [e.g., Next.js 15, React 18] |
|
|
28
|
+
| [e.g., CLI Tool] | [File system operations] | [e.g., Node.js, Commander.js] |
|
|
29
|
+
| [e.g., API Server] | [Business logic & data access] | [e.g., Express, PostgreSQL] |
|
|
30
|
+
| [e.g., Auth Layer] | [Authentication & authorization] | [e.g., Auth.js, JWT] |
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## 🔄 Core Data Flow
|
|
35
|
+
<!-- Describe the primary "happy path" through your system -->
|
|
36
|
+
|
|
37
|
+
1. **[Step 1]**: [e.g., User triggers command via CLI]
|
|
38
|
+
2. **[Step 2]**: [e.g., CLI reads configuration from local file]
|
|
39
|
+
3. **[Step 3]**: [e.g., System validates input against schema]
|
|
40
|
+
4. **[Step 4]**: [e.g., Results written to file system / database]
|
|
41
|
+
|
|
42
|
+
**Diagram** (optional):
|
|
43
|
+
```
|
|
44
|
+
[User] → [CLI] → [Validation] → [File System]
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## 🚢 Deployment & Infrastructure
|
|
50
|
+
|
|
51
|
+
- **Environment**: [e.g., Vercel, AWS Lambda, Local CLI, Docker]
|
|
52
|
+
- **CI/CD**: [e.g., GitHub Actions, GitLab CI]
|
|
53
|
+
- **Observability**: [e.g., Sentry for errors, CloudWatch for logs]
|
|
54
|
+
- **Database**: [e.g., PostgreSQL on Railway, SQLite local-first]
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## 🔒 Security Posture
|
|
59
|
+
|
|
60
|
+
- **Authentication**: [e.g., Auth.js with Google OAuth, API keys, None (CLI tool)]
|
|
61
|
+
- **Authorization**: [e.g., RBAC with roles (admin, user), Scopes (read, write)]
|
|
62
|
+
- **Data Safety**: [e.g., Secrets stored in environment variables, No PII in logs]
|
|
63
|
+
- **Attack Surface**: [e.g., Public API endpoints rate-limited, Internal services behind VPC]
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## 🧪 Testing Strategy
|
|
68
|
+
|
|
69
|
+
- **Unit Tests**: [e.g., Vitest for business logic]
|
|
70
|
+
- **Integration Tests**: [e.g., Playwright for API endpoints]
|
|
71
|
+
- **E2E Tests**: [e.g., Cypress for critical user flows]
|
|
72
|
+
- **Test Coverage Target**: [e.g., 80% for core modules]
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
## 🛠️ Technology Decisions (ADR Summary)
|
|
77
|
+
<!-- High-level summary only. For detailed rationale, see docs/core/DECISIONS.md -->
|
|
78
|
+
|
|
79
|
+
- **[Tech/Framework 1]**: [Why it was chosen - e.g., "Next.js for SSR and API routes in one framework"]
|
|
80
|
+
- **[Tech/Framework 2]**: [Why it was chosen - e.g., "PostgreSQL for relational data with ACID guarantees"]
|
|
81
|
+
- **[Tech/Framework 3]**: [Why it was chosen - e.g., "pnpm for faster installs and strict dependency resolution"]
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## 📌 Key Files & Locations
|
|
86
|
+
<!-- Help AI agents find critical code -->
|
|
87
|
+
|
|
88
|
+
| File/Folder | Purpose | Notes |
|
|
89
|
+
|:------------|:--------|:------|
|
|
90
|
+
| [e.g., `src/index.ts`] | [Main entry point] | [CLI initialization] |
|
|
91
|
+
| [e.g., `src/commands/`] | [CLI command handlers] | [Uses Commander.js pattern] |
|
|
92
|
+
| [e.g., `src/lib/validation.ts`] | [Schema validation logic] | [Uses Zod for type safety] |
|
|
93
|
+
| [e.g., `templates/`] | [Boilerplate files] | [Copied to user projects] |
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
## 🔗 Related Documentation
|
|
98
|
+
|
|
99
|
+
- **Patterns**: See `docs/core/PATTERNS.md` for code conventions
|
|
100
|
+
- **Domain Logic**: See `docs/core/DOMAIN-LOGIC.md` for business rules
|
|
101
|
+
- **Decisions**: See `docs/core/DECISIONS.md` for detailed ADRs
|
|
102
|
+
- **Schema**: See `docs/core/SCHEMA.md` for data models (if applicable)
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# Architecture Decisions (ADR)
|
|
2
|
+
|
|
3
|
+
## 🎯 Purpose
|
|
4
|
+
This file documents **why** we made key technical decisions. When an AI agent or developer asks "Why did we choose X over Y?", the answer should be here.
|
|
5
|
+
|
|
6
|
+
**ADR Format**: Context → Decision → Reasoning → Consequences
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## [YYYY-MM-DD] - [Decision Title]
|
|
11
|
+
|
|
12
|
+
**Context**: [What problem were we solving? What constraints existed?]
|
|
13
|
+
|
|
14
|
+
**Decision**: [What did we choose? Be specific - e.g., "Use PostgreSQL as the primary database"]
|
|
15
|
+
|
|
16
|
+
**Reasoning**: [Why did we choose this over alternatives?]
|
|
17
|
+
- **Pro**: [Advantage 1 - e.g., "ACID compliance for financial transactions"]
|
|
18
|
+
- **Pro**: [Advantage 2 - e.g., "Strong TypeScript support via Prisma"]
|
|
19
|
+
- **Con**: [Trade-off 1 - e.g., "More complex than SQLite for local dev"]
|
|
20
|
+
- **Alternative Considered**: [What we didn't choose and why - e.g., "MongoDB: Too flexible for our relational data model"]
|
|
21
|
+
|
|
22
|
+
**Consequences**: [What does this decision enable or prevent?]
|
|
23
|
+
- ✅ [Positive outcome - e.g., "Can use transactions for multi-table updates"]
|
|
24
|
+
- ⚠️ [Trade-off - e.g., "Requires Docker for local development"]
|
|
25
|
+
|
|
26
|
+
**Status**: [Active | Deprecated | Superseded by ADR-XXX]
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## Example: [2026-01-10] - Use pnpm as Package Manager
|
|
31
|
+
|
|
32
|
+
**Context**: We needed a package manager for the Node.js CLI project. The team had experience with npm and yarn, but wanted to evaluate modern alternatives for speed and disk efficiency.
|
|
33
|
+
|
|
34
|
+
**Decision**: Use `pnpm` as the exclusive package manager for this project.
|
|
35
|
+
|
|
36
|
+
**Reasoning**:
|
|
37
|
+
- **Pro**: Faster installs via content-addressable storage (saves ~40% time vs npm)
|
|
38
|
+
- **Pro**: Strict dependency resolution prevents phantom dependencies
|
|
39
|
+
- **Pro**: Symlink-based `node_modules` saves disk space in monorepos
|
|
40
|
+
- **Con**: Less universal than npm (requires installation step for new contributors)
|
|
41
|
+
- **Alternative Considered**: Yarn 2 (Berry) - Too complex with PnP; Bun - Too bleeding-edge for production
|
|
42
|
+
|
|
43
|
+
**Consequences**:
|
|
44
|
+
- ✅ CI/CD runs 40% faster
|
|
45
|
+
- ✅ Prevents accidental use of undeclared dependencies
|
|
46
|
+
- ⚠️ All documentation must specify `pnpm` commands (can't use `npm`)
|
|
47
|
+
- ⚠️ Contributors must install pnpm (`npm install -g pnpm`)
|
|
48
|
+
|
|
49
|
+
**Status**: Active
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## Template for New Decisions
|
|
54
|
+
|
|
55
|
+
**Copy this template when adding a new ADR:**
|
|
56
|
+
|
|
57
|
+
```markdown
|
|
58
|
+
## [YYYY-MM-DD] - [Decision Title]
|
|
59
|
+
|
|
60
|
+
**Context**: [Problem and constraints]
|
|
61
|
+
|
|
62
|
+
**Decision**: [What we chose]
|
|
63
|
+
|
|
64
|
+
**Reasoning**:
|
|
65
|
+
- **Pro**: [Advantage 1]
|
|
66
|
+
- **Pro**: [Advantage 2]
|
|
67
|
+
- **Con**: [Trade-off 1]
|
|
68
|
+
- **Alternative Considered**: [What we didn't choose and why]
|
|
69
|
+
|
|
70
|
+
**Consequences**:
|
|
71
|
+
- ✅ [Positive outcome]
|
|
72
|
+
- ⚠️ [Trade-off]
|
|
73
|
+
|
|
74
|
+
**Status**: Active
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## 🔗 Cross-References
|
|
80
|
+
|
|
81
|
+
- **Architecture**: See `docs/core/ARCHITECTURE.md` for technology stack
|
|
82
|
+
- **Patterns**: See `docs/core/PATTERNS.md` for implementation patterns
|
|
83
|
+
- **Glossary**: See `docs/core/GLOSSARY.md` for term definitions
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# Glossary: [Project Name]
|
|
2
|
+
|
|
3
|
+
## 🎯 Purpose
|
|
4
|
+
This file defines project-specific terminology, acronyms, and domain language to ensure consistent communication between humans and AI agents.
|
|
5
|
+
|
|
6
|
+
**When to add a term**: If you find yourself explaining the same concept twice, add it here.
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## 📋 Core Terminology
|
|
11
|
+
|
|
12
|
+
### [Term 1]
|
|
13
|
+
**Definition**: [Clear, concise explanation of what this means in your project]
|
|
14
|
+
**Example**: [Usage in context - e.g., "The **SessionManager** handles all user authentication state"]
|
|
15
|
+
**Related Terms**: [Links to related concepts - e.g., "See: AuthProvider, TokenRefresh"]
|
|
16
|
+
|
|
17
|
+
### [Term 2]
|
|
18
|
+
**Definition**: [Clear, concise explanation]
|
|
19
|
+
**Example**: [Usage in context]
|
|
20
|
+
**Related Terms**: [Links to related concepts]
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## 🔤 Acronyms & Abbreviations
|
|
25
|
+
|
|
26
|
+
| Acronym | Stands For | Meaning in This Project |
|
|
27
|
+
|:--------|:-----------|:------------------------|
|
|
28
|
+
| [e.g., ADR] | [Architecture Decision Record] | [Documents why we chose a specific tech or pattern] |
|
|
29
|
+
| [e.g., CRUD] | [Create, Read, Update, Delete] | [Standard database operations] |
|
|
30
|
+
| [e.g., SSR] | [Server-Side Rendering] | [Next.js rendering strategy for SEO-critical pages] |
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## 🏗️ Domain-Specific Concepts
|
|
35
|
+
|
|
36
|
+
### [Concept 1: e.g., "Tiered Memory System"]
|
|
37
|
+
**What it is**: [High-level explanation - e.g., "A documentation organization pattern that categorizes files by access frequency"]
|
|
38
|
+
**Why it matters**: [Business/technical value - e.g., "Reduces AI agent context window waste by 60%"]
|
|
39
|
+
**Key Components**:
|
|
40
|
+
- **[Sub-concept A]**: [Definition]
|
|
41
|
+
- **[Sub-concept B]**: [Definition]
|
|
42
|
+
|
|
43
|
+
### [Concept 2: e.g., "Truth Syncing"]
|
|
44
|
+
**What it is**: [High-level explanation]
|
|
45
|
+
**Why it matters**: [Business/technical value]
|
|
46
|
+
**Key Components**:
|
|
47
|
+
- **[Sub-concept A]**: [Definition]
|
|
48
|
+
- **[Sub-concept B]**: [Definition]
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## 🚫 Anti-Patterns (What NOT to call things)
|
|
53
|
+
|
|
54
|
+
| ❌ Avoid | ✅ Use Instead | Why |
|
|
55
|
+
|:---------|:---------------|:----|
|
|
56
|
+
| [e.g., "Helper"] | [e.g., "Validator"] | ["Helper" is vague; "Validator" describes function] |
|
|
57
|
+
| [e.g., "Manager"] | [e.g., "Service"] | ["Manager" is overused; "Service" is more precise] |
|
|
58
|
+
| [e.g., "Utils"] | [e.g., "Formatters"] | ["Utils" is a dumping ground; "Formatters" is specific] |
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## 🔗 Cross-References
|
|
63
|
+
|
|
64
|
+
- **Architecture**: See `docs/core/ARCHITECTURE.md` for system structure
|
|
65
|
+
- **Patterns**: See `docs/core/PATTERNS.md` for code conventions
|
|
66
|
+
- **Decisions**: See `docs/core/DECISIONS.md` for technology choices
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Implementation Patterns
|
|
2
|
+
|
|
3
|
+
## [Category: e.g., UI/Data/Auth] [Pattern Name]
|
|
4
|
+
|
|
5
|
+
**Rule**: [Short, imperative statement of the rule]
|
|
6
|
+
|
|
7
|
+
### ❌ Anti-Pattern (What NOT to do)
|
|
8
|
+
|
|
9
|
+
- [Description of common AI mistake]
|
|
10
|
+
- [Why it fails in this project]
|
|
11
|
+
|
|
12
|
+
### ✅ Canonical Example
|
|
13
|
+
|
|
14
|
+
**Source File**: `path/to/best-example-file.ts`
|
|
15
|
+
|
|
16
|
+
```typescript
|
|
17
|
+
// A concise, perfect implementation of the pattern
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### 🔗 References
|
|
21
|
+
|
|
22
|
+
- **Domain Logic**: `DOMAIN-LOGIC.md#[Section]`
|
|
23
|
+
- **Gotchas**: `TROUBLESHOOTING.md#[Section]`
|
|
24
|
+
|
|
25
|
+
#### 2. `templates/root/copilot-instructions.md`
|
|
26
|
+
|
|
27
|
+
The "Contract" that the user will place in their own `.github/` folder.
|
|
28
|
+
|
|
29
|
+
# AI Pair Programmer: Collaboration Protocol (TMS v2.0)
|
|
30
|
+
|
|
31
|
+
## 📖 Mandatory Read Order
|
|
32
|
+
|
|
33
|
+
AI agents MUST follow this order before proposing or writing code:
|
|
34
|
+
|
|
35
|
+
1. `.github/copilot-instructions.md` (This file)
|
|
36
|
+
2. `NEXT-TASKS.md` (Current context)
|
|
37
|
+
3. `docs/core/DOMAIN-LOGIC.md` (Domain rules)
|
|
38
|
+
4. `docs/core/PATTERNS.md` (Implementation standards)
|
|
39
|
+
|
|
40
|
+
## ⚡ Critical Rules
|
|
41
|
+
|
|
42
|
+
- **Domain**: [Describe the domain here]
|
|
43
|
+
- **Money/Math**: [e.g., Use integers in cents]
|
|
44
|
+
- **Types**: ALWAYS use strict TypeScript. No `any`.
|
|
45
|
+
|
|
46
|
+
## 🏗️ Technical Map
|
|
47
|
+
|
|
48
|
+
- **Gotchas**: `docs/core/TROUBLESHOOTING.md`
|
|
49
|
+
- **Past Decisions**: `docs/core/DECISIONS.md`
|
|
50
|
+
|
|
51
|
+
## 🧪 Operational Loop
|
|
52
|
+
|
|
53
|
+
1. Read `NEXT-TASKS.md` to understand the "Why" and "What."
|
|
54
|
+
2. Check `docs/core/PATTERNS.md` for existing canonical examples.
|
|
55
|
+
3. Propose -> Justify -> Recommend.
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
# Schema: Data Models & Relationships
|
|
2
|
+
|
|
3
|
+
<!-- This file documents your data models, database schema, and type definitions. -->
|
|
4
|
+
<!-- If your project doesn't use a database, you can document TypeScript types, API contracts, or state shape instead. -->
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Overview
|
|
9
|
+
|
|
10
|
+
**Database/Store Type**: [e.g., PostgreSQL, MongoDB, Redis, In-Memory]
|
|
11
|
+
**ORM/Query Tool**: [e.g., Prisma, TypeORM, Mongoose, Raw SQL]
|
|
12
|
+
**Schema Migration Strategy**: [e.g., Prisma Migrate, TypeORM migrations, Alembic]
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## Core Entities
|
|
17
|
+
|
|
18
|
+
<!-- List your main data entities/tables/collections. For each, document: -->
|
|
19
|
+
<!-- - Purpose (what it represents) -->
|
|
20
|
+
<!-- - Key fields -->
|
|
21
|
+
<!-- - Relationships to other entities -->
|
|
22
|
+
|
|
23
|
+
### [Entity Name 1: e.g., User]
|
|
24
|
+
|
|
25
|
+
**Purpose**: [e.g., Stores user account information and authentication data]
|
|
26
|
+
|
|
27
|
+
**Fields**:
|
|
28
|
+
|
|
29
|
+
| Field | Type | Required | Default | Notes |
|
|
30
|
+
|:------|:-----|:---------|:--------|:------|
|
|
31
|
+
| `id` | [e.g., UUID, Integer] | Yes | Auto-generated | Primary key |
|
|
32
|
+
| `email` | [e.g., String] | Yes | - | Unique, validated |
|
|
33
|
+
| `passwordHash` | [e.g., String] | Yes | - | bcrypt hashed |
|
|
34
|
+
| `createdAt` | [e.g., Timestamp] | Yes | NOW() | UTC timezone |
|
|
35
|
+
| `updatedAt` | [e.g., Timestamp] | Yes | NOW() | Auto-updated |
|
|
36
|
+
|
|
37
|
+
**Relationships**:
|
|
38
|
+
- [e.g., One User has many Posts (1:N)]
|
|
39
|
+
- [e.g., One User belongs to one Organization (N:1)]
|
|
40
|
+
|
|
41
|
+
**Indexes**:
|
|
42
|
+
- [e.g., `email` (unique)]
|
|
43
|
+
- [e.g., `createdAt` (for sorting)]
|
|
44
|
+
|
|
45
|
+
**Validation Rules**:
|
|
46
|
+
- [e.g., Email must match regex pattern]
|
|
47
|
+
- [e.g., Password minimum 8 characters]
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
### [Entity Name 2: e.g., Post]
|
|
52
|
+
|
|
53
|
+
**Purpose**: [e.g., User-generated content items]
|
|
54
|
+
|
|
55
|
+
**Fields**:
|
|
56
|
+
|
|
57
|
+
| Field | Type | Required | Default | Notes |
|
|
58
|
+
|:------|:-----|:---------|:--------|:------|
|
|
59
|
+
| `id` | [Type] | Yes | Auto-generated | Primary key |
|
|
60
|
+
| `userId` | [Type] | Yes | - | Foreign key → User.id |
|
|
61
|
+
| `title` | [String] | Yes | - | Max 200 chars |
|
|
62
|
+
| `content` | [Text] | Yes | - | Markdown supported |
|
|
63
|
+
| `publishedAt` | [Timestamp] | No | NULL | NULL = draft |
|
|
64
|
+
|
|
65
|
+
**Relationships**:
|
|
66
|
+
- [e.g., One Post belongs to one User (N:1)]
|
|
67
|
+
- [e.g., One Post has many Comments (1:N)]
|
|
68
|
+
|
|
69
|
+
**Indexes**:
|
|
70
|
+
- [e.g., `userId` (for user's posts lookup)]
|
|
71
|
+
- [e.g., `publishedAt` (for recent posts)]
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## Relationships
|
|
76
|
+
|
|
77
|
+
<!-- Document complex relationships, especially Many-to-Many (N:M) -->
|
|
78
|
+
|
|
79
|
+
### [Relationship Name: e.g., User ↔ Role (Many-to-Many)]
|
|
80
|
+
|
|
81
|
+
**Join Table**: [e.g., `user_roles`]
|
|
82
|
+
|
|
83
|
+
**Fields**:
|
|
84
|
+
|
|
85
|
+
| Field | Type | Required | Notes |
|
|
86
|
+
|:------|:-----|:---------|:------|
|
|
87
|
+
| `userId` | [Type] | Yes | FK → User.id |
|
|
88
|
+
| `roleId` | [Type] | Yes | FK → Role.id |
|
|
89
|
+
| `assignedAt` | [Timestamp] | Yes | When role was granted |
|
|
90
|
+
|
|
91
|
+
**Constraints**:
|
|
92
|
+
- [e.g., Unique constraint on (userId, roleId) - prevent duplicates]
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
## Enums & Constants
|
|
97
|
+
|
|
98
|
+
<!-- Document any enum types or constant values used in the schema -->
|
|
99
|
+
|
|
100
|
+
### [Enum Name: e.g., UserStatus]
|
|
101
|
+
|
|
102
|
+
**Values**:
|
|
103
|
+
- `ACTIVE` - [e.g., User can log in]
|
|
104
|
+
- `SUSPENDED` - [e.g., Temporarily blocked]
|
|
105
|
+
- `DELETED` - [e.g., Soft-deleted account]
|
|
106
|
+
|
|
107
|
+
**Storage**: [e.g., Stored as String in database]
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
## TypeScript Types
|
|
112
|
+
|
|
113
|
+
<!-- If using TypeScript, document your type definitions -->
|
|
114
|
+
<!-- This is especially important for frontend state or API contracts -->
|
|
115
|
+
|
|
116
|
+
### [Type Name: e.g., UserProfile]
|
|
117
|
+
|
|
118
|
+
**Purpose**: [e.g., Client-side user profile (excludes sensitive fields)]
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
interface UserProfile {
|
|
122
|
+
id: string
|
|
123
|
+
email: string
|
|
124
|
+
displayName: string | null
|
|
125
|
+
avatarUrl: string | null
|
|
126
|
+
createdAt: Date
|
|
127
|
+
// Note: passwordHash is NOT included (security)
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
**Derived From**: [e.g., Database User entity, with passwordHash excluded]
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
## Migration History
|
|
136
|
+
|
|
137
|
+
<!-- Track significant schema changes -->
|
|
138
|
+
|
|
139
|
+
### [Date: e.g., 2026-01-15] - [Change: e.g., Add User.avatarUrl field]
|
|
140
|
+
|
|
141
|
+
**Reason**: [e.g., Support profile pictures]
|
|
142
|
+
**Migration File**: [e.g., `migrations/20260115_add_avatar_url.sql`]
|
|
143
|
+
**Breaking Change**: [Yes/No]
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
### [Date: e.g., 2026-01-20] - [Change: e.g., Split User table into User + UserProfile]
|
|
148
|
+
|
|
149
|
+
**Reason**: [e.g., Separate auth data from profile data]
|
|
150
|
+
**Migration File**: [e.g., `migrations/20260120_split_user_profile.sql`]
|
|
151
|
+
**Breaking Change**: Yes
|
|
152
|
+
**Rollback Plan**: [e.g., Reverse migration available in same file]
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
## Data Flow Diagrams
|
|
157
|
+
|
|
158
|
+
<!-- Optional: Visual representations of how data moves through the system -->
|
|
159
|
+
|
|
160
|
+
### [Flow Name: e.g., User Registration]
|
|
161
|
+
|
|
162
|
+
```
|
|
163
|
+
1. User submits email + password
|
|
164
|
+
↓
|
|
165
|
+
2. Hash password with bcrypt
|
|
166
|
+
↓
|
|
167
|
+
3. INSERT into User table
|
|
168
|
+
↓
|
|
169
|
+
4. Send verification email
|
|
170
|
+
↓
|
|
171
|
+
5. Create UserProfile record
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
## Validation Rules
|
|
177
|
+
|
|
178
|
+
<!-- Document business logic constraints that aren't enforced at the DB level -->
|
|
179
|
+
|
|
180
|
+
### [Rule: e.g., Post Publishing]
|
|
181
|
+
|
|
182
|
+
**Condition**: User can only publish a post if:
|
|
183
|
+
- Post.title length >= 10 characters
|
|
184
|
+
- User.status === 'ACTIVE'
|
|
185
|
+
- User has 'PUBLISHER' role
|
|
186
|
+
|
|
187
|
+
**Enforcement Location**: [e.g., `src/services/postService.ts`]
|
|
188
|
+
|
|
189
|
+
---
|
|
190
|
+
|
|
191
|
+
## Performance Considerations
|
|
192
|
+
|
|
193
|
+
### Query Patterns
|
|
194
|
+
|
|
195
|
+
**Most Common Queries**:
|
|
196
|
+
1. [e.g., `SELECT * FROM posts WHERE userId = ? ORDER BY publishedAt DESC LIMIT 20`]
|
|
197
|
+
2. [e.g., `SELECT * FROM users WHERE email = ?`]
|
|
198
|
+
|
|
199
|
+
**Indexes Supporting These**:
|
|
200
|
+
- [e.g., Index on `posts.userId` + `posts.publishedAt`]
|
|
201
|
+
- [e.g., Unique index on `users.email`]
|
|
202
|
+
|
|
203
|
+
### Expected Scale
|
|
204
|
+
|
|
205
|
+
**Projected Data Volume** (Year 1):
|
|
206
|
+
- [e.g., Users: ~10,000]
|
|
207
|
+
- [e.g., Posts: ~100,000]
|
|
208
|
+
- [e.g., Comments: ~500,000]
|
|
209
|
+
|
|
210
|
+
**Growth Strategy**: [e.g., Partition posts table by year after 1M records]
|
|
211
|
+
|
|
212
|
+
---
|
|
213
|
+
|
|
214
|
+
## Security Considerations
|
|
215
|
+
|
|
216
|
+
### Sensitive Fields
|
|
217
|
+
|
|
218
|
+
**Never expose in API responses**:
|
|
219
|
+
- `User.passwordHash`
|
|
220
|
+
- [e.g., `User.resetToken`]
|
|
221
|
+
- [e.g., `Payment.cardNumber` (store only last 4 digits)]
|
|
222
|
+
|
|
223
|
+
**Encryption at Rest**:
|
|
224
|
+
- [e.g., `User.email` - encrypted in production DB]
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
## AI Agent Notes
|
|
229
|
+
|
|
230
|
+
**When generating database queries**:
|
|
231
|
+
- ⚠️ Always use parameterized queries (prevent SQL injection)
|
|
232
|
+
- ⚠️ All timestamps are stored in UTC (convert to user timezone in frontend)
|
|
233
|
+
- ⚠️ Soft deletes: Check `deletedAt IS NULL` in WHERE clauses
|
|
234
|
+
|
|
235
|
+
**Common Mistakes to Avoid**:
|
|
236
|
+
- ❌ Don't use `SELECT *` in production code (explicit columns only)
|
|
237
|
+
- ❌ Don't expose `passwordHash` in any API response
|
|
238
|
+
- ❌ Don't perform N+1 queries (use JOINs or eager loading)
|
|
239
|
+
|
|
240
|
+
---
|
|
241
|
+
|
|
242
|
+
## References
|
|
243
|
+
|
|
244
|
+
- **ORM Documentation**: [Link to Prisma/TypeORM/etc. docs]
|
|
245
|
+
- **Database Docs**: [Link to PostgreSQL/MongoDB/etc. docs]
|
|
246
|
+
- **Migration Guide**: [Link to your migration strategy doc]
|