telo3-ai 5.0.7 → 6.2.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/README.md +32 -791
- package/SKILL.md +36 -657
- package/bootstrap/TELO3.md +17 -0
- package/cli.js +223 -42
- package/hooks/inject-contract.mjs +23 -0
- package/hooks/session-start.example.json +15 -0
- package/index.js +48 -14
- package/package.json +32 -69
- package/references/accessibility-quality.md +92 -272
- package/references/ai-behavior.md +70 -332
- package/references/anti-slop.md +71 -0
- package/references/document-specification.md +110 -419
- package/references/legal-compliance.md +90 -395
- package/references/performance-quality.md +100 -351
- package/references/privacy-compliance.md +88 -464
- package/references/project-audit.md +79 -440
- package/references/security-quality.md +68 -220
- package/references/seo-quality.md +83 -339
- package/references/smart-skill-delegation.md +73 -419
- package/references/token-optimization.md +83 -450
- package/references/ui-quality.md +106 -481
- package/references/workflow.md +91 -447
- package/scripts/postinstall.mjs +27 -0
- package/src/activate.js +159 -0
- package/src/context.js +72 -0
- package/src/find-context.js +41 -0
- package/src/init.js +38 -0
- package/src/install.js +128 -0
- package/src/paths.js +20 -0
- package/src/status.js +30 -0
- package/src/tokens.js +10 -0
- package/src/validate.js +220 -0
- package/src/version.js +12 -0
- package/templates/architecture.md +17 -398
- package/templates/design.md +22 -631
- package/templates/memory.md +13 -351
- package/templates/prd.md +15 -295
- package/templates/rules.md +20 -600
- package/templates/tasks.md +10 -210
- package/AI-CONTEXT.md +0 -272
- package/ONBOARDING-SKILL.md +0 -738
- package/SKILL-METADATA.json +0 -237
- package/scripts/init-project-context.sh +0 -139
- package/scripts/validate-project-context.sh +0 -164
- package/skills/telo3/SKILL.md +0 -315
- package/skills/telo3-context/SKILL.md +0 -272
- package/skills/telo3-onboarding/SKILL.md +0 -738
package/src/validate.js
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context validation: required sections, unfilled placeholders,
|
|
3
|
+
* accidental secrets (reported by line, never by value), staleness.
|
|
4
|
+
* @license MIT
|
|
5
|
+
*/
|
|
6
|
+
import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs';
|
|
7
|
+
import { join, resolve } from 'node:path';
|
|
8
|
+
import { CONTEXT_DOCS, findContextDir } from './find-context.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Required section keys per document. Matched case-insensitively as
|
|
12
|
+
* substrings of markdown headings. Templates and examples must satisfy these.
|
|
13
|
+
*/
|
|
14
|
+
export const REQUIRED_SECTIONS = {
|
|
15
|
+
'prd.md': [
|
|
16
|
+
'project overview',
|
|
17
|
+
'problem statement',
|
|
18
|
+
'target users',
|
|
19
|
+
'goals',
|
|
20
|
+
'functional requirements',
|
|
21
|
+
'success criteria',
|
|
22
|
+
],
|
|
23
|
+
'architecture.md': [
|
|
24
|
+
'architecture overview',
|
|
25
|
+
'technology stack',
|
|
26
|
+
'project structure',
|
|
27
|
+
'architectural decisions',
|
|
28
|
+
],
|
|
29
|
+
'rules.md': ['core principles', 'security', 'testing', 'validation'],
|
|
30
|
+
'design.md': ['design philosophy', 'colors', 'typography', 'components', 'accessibility'],
|
|
31
|
+
'tasks.md': ['current sprint', 'backlog', 'completed recently'],
|
|
32
|
+
'memory.md': ['current state', 'recently completed work', 'important decisions', 'known issues'],
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const STALE_DAYS = 30;
|
|
36
|
+
const CODE_EXTENSIONS = new Set([
|
|
37
|
+
'.js', '.mjs', '.cjs', '.ts', '.tsx', '.jsx', '.py', '.go', '.rs', '.java',
|
|
38
|
+
'.rb', '.php', '.css', '.scss', '.html', '.vue', '.svelte', '.sql', '.sh',
|
|
39
|
+
]);
|
|
40
|
+
const SKIP_DIRS = new Set([
|
|
41
|
+
'node_modules', '.git', 'dist', 'build', 'coverage', '.next', '.nuxt', 'out', 'vendor', '__pycache__',
|
|
42
|
+
'.agents', '.qoder', '.claude', '.cursor', '.gemini', '_backup_v5.1.0', 'telo3-main', 'releases',
|
|
43
|
+
]);
|
|
44
|
+
|
|
45
|
+
/** Remove fenced code blocks so their contents are not scanned as prose. */
|
|
46
|
+
function stripFences(text) {
|
|
47
|
+
let fence = null;
|
|
48
|
+
return text.split('\n').map(line => {
|
|
49
|
+
const match = line.match(/^ {0,3}(`{3,}|~{3,})(.*)$/);
|
|
50
|
+
if (fence) {
|
|
51
|
+
if (match && match[1][0] === fence.char && match[1].length >= fence.size && !match[2].trim()) fence = null;
|
|
52
|
+
return '';
|
|
53
|
+
}
|
|
54
|
+
if (match) { fence = { char: match[1][0], size: match[1].length }; return ''; }
|
|
55
|
+
return line;
|
|
56
|
+
}).join('\n');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function headingsOf(text) {
|
|
60
|
+
const stripped = stripFences(text);
|
|
61
|
+
const matches = stripped.matchAll(/^#{1,6}\s+(.+)$/gm);
|
|
62
|
+
return [...matches].map((m) => m[1].trim());
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Count unfilled placeholders: [TODO ...], [Project Name], [UNKNOWN].
|
|
67
|
+
* Excludes code fences, inline code, checkboxes, links, images, footnotes.
|
|
68
|
+
*/
|
|
69
|
+
function countPlaceholders(text) {
|
|
70
|
+
const stripped = stripFences(text).replace(/`[^`\n]*`/g, '')
|
|
71
|
+
.replace(/^ {0,3}\[[^\]\n]+\]:[^\n]*$/gm, '')
|
|
72
|
+
.replace(/\[[^\]\n]+\][ \t]*\[[^\]\n]*\]/g, '')
|
|
73
|
+
.replace(/\[\^[^\]\n]+\]/g, '');
|
|
74
|
+
let count = 0;
|
|
75
|
+
for (const match of stripped.matchAll(/\[([^[\]\n]+)\](?!\()/g)) {
|
|
76
|
+
const inner = match[1];
|
|
77
|
+
if (/^\s*[xX]?\s*$/.test(inner)) continue; // checkbox
|
|
78
|
+
if (/^\^\d+$/.test(inner)) continue; // footnote
|
|
79
|
+
count++;
|
|
80
|
+
}
|
|
81
|
+
return count;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const SECRET_PATTERNS = [
|
|
85
|
+
{ label: 'credential assignment', re: /\b(?:api[_-]?key|apikey|[a-z0-9_]*(?:secret|token|password|passwd|pwd|access[_-]?key))["']?\s*[:=]\s*(?:['"][^'"\n]{8,}['"]|(?!\[|<|\$\{|process\.env\.|os\.environ|z\.)[^\s'",;}]{8,})/i },
|
|
86
|
+
{ label: 'AWS access key', re: /\bAKIA[0-9A-Z]{16}\b/ },
|
|
87
|
+
{ label: 'private key', re: /-----BEGIN (?:RSA |EC |DSA |OPENSSH )?PRIVATE KEY-----/ },
|
|
88
|
+
{ label: 'connection string with password', re: /\b(?:postgres|postgresql|mysql|mongodb|redis|amqp):\/\/[^\s:'"]+:[^\s'"]+@/i },
|
|
89
|
+
{ label: 'GitHub token', re: /\bghp_[A-Za-z0-9]{36}\b/ },
|
|
90
|
+
{ label: 'API secret key', re: /\bsk-[A-Za-z0-9]{20,}\b/ },
|
|
91
|
+
];
|
|
92
|
+
|
|
93
|
+
/** Redact detected credential lines and complete private-key blocks before context output. */
|
|
94
|
+
export function redactSecrets(text) {
|
|
95
|
+
const withoutKeys = text.replace(/-----BEGIN (?:RSA |EC |DSA |OPENSSH )?PRIVATE KEY-----[\s\S]*?(?:-----END (?:RSA |EC |DSA |OPENSSH )?PRIVATE KEY-----|$)/g, '[REDACTED: private key]');
|
|
96
|
+
return withoutKeys.split('\n').map(line => SECRET_PATTERNS.some(({ re }) => re.test(line)) ? '[REDACTED: possible credential]' : line).join('\n');
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Scan every line (including code blocks) for accidental secrets. */
|
|
100
|
+
function findSecrets(text) {
|
|
101
|
+
const found = [];
|
|
102
|
+
const lines = text.split('\n');
|
|
103
|
+
for (let i = 0; i < lines.length; i++) {
|
|
104
|
+
for (const { label, re } of SECRET_PATTERNS) {
|
|
105
|
+
if (re.test(lines[i])) {
|
|
106
|
+
found.push({ line: i + 1, pattern: label });
|
|
107
|
+
break; // one finding per line is enough
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return found;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Newest mtime among source-code files under root (bounded walk). */
|
|
115
|
+
function newestCodeMtime(root, contextDir) {
|
|
116
|
+
let newest = null;
|
|
117
|
+
let visited = 0;
|
|
118
|
+
let incomplete = false;
|
|
119
|
+
const walk = (dir, depth) => {
|
|
120
|
+
if (depth > 8 || visited > 4000) { incomplete = true; return; }
|
|
121
|
+
let entries;
|
|
122
|
+
try {
|
|
123
|
+
entries = readdirSync(dir, { withFileTypes: true });
|
|
124
|
+
} catch {
|
|
125
|
+
incomplete = true;
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
for (const entry of entries) {
|
|
129
|
+
if (visited > 4000) { incomplete = true; return; }
|
|
130
|
+
const full = join(dir, entry.name);
|
|
131
|
+
if (entry.isDirectory()) {
|
|
132
|
+
if (SKIP_DIRS.has(entry.name) || full === contextDir) continue;
|
|
133
|
+
walk(full, depth + 1);
|
|
134
|
+
} else if (entry.isFile()) {
|
|
135
|
+
visited++;
|
|
136
|
+
const dot = entry.name.lastIndexOf('.');
|
|
137
|
+
if (dot === -1 || !CODE_EXTENSIONS.has(entry.name.slice(dot))) continue;
|
|
138
|
+
try {
|
|
139
|
+
const mtime = statSync(full).mtimeMs;
|
|
140
|
+
if (newest === null || mtime > newest) newest = mtime;
|
|
141
|
+
} catch { incomplete = true; }
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
walk(root, 0);
|
|
146
|
+
return { mtime: newest, incomplete };
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export function validateContext(dir) {
|
|
150
|
+
const root = resolve(dir);
|
|
151
|
+
const contextDir = findContextDir(root);
|
|
152
|
+
if (!contextDir) {
|
|
153
|
+
return {
|
|
154
|
+
valid: false,
|
|
155
|
+
dir: null,
|
|
156
|
+
files: [],
|
|
157
|
+
errors: [{ message: 'No project context found. Run `telo3 init` to create it.' }],
|
|
158
|
+
warnings: [],
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const errors = [];
|
|
163
|
+
const warnings = [];
|
|
164
|
+
const files = [];
|
|
165
|
+
const scan = newestCodeMtime(root, contextDir);
|
|
166
|
+
const codeMtime = scan.mtime;
|
|
167
|
+
if (scan.incomplete) warnings.push({ message: 'Stale scan incomplete: traversal budget or inaccessible files; freshness is not fully verified.' });
|
|
168
|
+
|
|
169
|
+
for (const file of CONTEXT_DOCS) {
|
|
170
|
+
const path = join(contextDir, file);
|
|
171
|
+
if (!existsSync(path)) {
|
|
172
|
+
files.push({
|
|
173
|
+
file, exists: false, sections: 0,
|
|
174
|
+
missingSections: [...REQUIRED_SECTIONS[file]],
|
|
175
|
+
placeholders: 0, secrets: [], stale: null,
|
|
176
|
+
});
|
|
177
|
+
errors.push({ file, message: `Missing required document: ${file}` });
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const content = readFileSync(path, 'utf8');
|
|
182
|
+
const headings = headingsOf(content);
|
|
183
|
+
const lower = headings.map((h) => h.toLowerCase());
|
|
184
|
+
const missingSections = REQUIRED_SECTIONS[file].filter(
|
|
185
|
+
(key) => !lower.some((h) => h.includes(key)),
|
|
186
|
+
);
|
|
187
|
+
const placeholders = countPlaceholders(content);
|
|
188
|
+
const secrets = findSecrets(content);
|
|
189
|
+
|
|
190
|
+
let stale = null;
|
|
191
|
+
if (codeMtime !== null) {
|
|
192
|
+
const docMtime = statSync(path).mtimeMs;
|
|
193
|
+
const diffDays = Math.floor((codeMtime - docMtime) / 86400000);
|
|
194
|
+
if (diffDays >= STALE_DAYS) stale = diffDays;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
files.push({
|
|
198
|
+
file, exists: true, sections: headings.length,
|
|
199
|
+
missingSections, placeholders, secrets, stale,
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
for (const section of missingSections) {
|
|
203
|
+
errors.push({ file, message: `Missing required section: "${section}"` });
|
|
204
|
+
}
|
|
205
|
+
if (placeholders > 0) {
|
|
206
|
+
warnings.push({ file, message: `${placeholders} unfilled placeholder(s) — replace with real content` });
|
|
207
|
+
}
|
|
208
|
+
for (const secret of secrets) {
|
|
209
|
+
warnings.push({
|
|
210
|
+
file,
|
|
211
|
+
message: `Possible secret (${secret.pattern}) at line ${secret.line} — remove it; configure secrets via environment variables`,
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
if (stale !== null) {
|
|
215
|
+
warnings.push({ file, message: `Stale: last update predates recent code changes by ${stale} days` });
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
return { valid: errors.length === 0, dir: contextDir, files, errors, warnings, scanIncomplete: scan.incomplete };
|
|
220
|
+
}
|
package/src/version.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Single source of truth for the version: package.json.
|
|
3
|
+
* @license MIT
|
|
4
|
+
*/
|
|
5
|
+
import { readFileSync } from 'node:fs';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
|
|
8
|
+
const pkgPath = fileURLToPath(new URL('../package.json', import.meta.url));
|
|
9
|
+
|
|
10
|
+
export function getVersion() {
|
|
11
|
+
return JSON.parse(readFileSync(pkgPath, 'utf8')).version;
|
|
12
|
+
}
|
|
@@ -1,418 +1,37 @@
|
|
|
1
|
-
|
|
1
|
+
<!-- Lean skeleton. Document what IS built (code is truth for current state).
|
|
2
|
+
Update when structure/stack/data-flow changes. Required sections are validated. -->
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
> **Last Updated:** [Date]
|
|
5
|
-
|
|
6
|
-
---
|
|
4
|
+
# Architecture — [Project Name]
|
|
7
5
|
|
|
8
6
|
## Architecture Overview
|
|
9
7
|
|
|
10
|
-
|
|
11
|
-
[High-level description of the architecture. Is this a monolith, microservices, JAMstack, serverless, client-server, etc.?]
|
|
12
|
-
|
|
13
|
-
### Architecture Diagram
|
|
14
|
-
```
|
|
15
|
-
[ASCII diagram or reference to visual architecture diagram]
|
|
16
|
-
|
|
17
|
-
Example:
|
|
18
|
-
┌─────────────┐ ┌──────────────┐ ┌──────────────┐
|
|
19
|
-
│ Browser │─────▶│ Frontend │─────▶│ Backend │
|
|
20
|
-
│ (Client) │◀─────│ (Next.js) │◀─────│ (API) │
|
|
21
|
-
└─────────────┘ └──────────────┘ └──────────────┘
|
|
22
|
-
│ │
|
|
23
|
-
▼ ▼
|
|
24
|
-
┌──────────────┐ ┌──────────────┐
|
|
25
|
-
│ Vercel │ │ PostgreSQL │
|
|
26
|
-
└──────────────┘ └──────────────┘
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
### Core Principles
|
|
30
|
-
[What are the guiding architectural principles?]
|
|
31
|
-
|
|
32
|
-
- [Principle 1: e.g., "API-first design"]
|
|
33
|
-
- [Principle 2: e.g., "Stateless services"]
|
|
34
|
-
|
|
35
|
-
---
|
|
8
|
+
[TODO: System shape in 2-3 sentences — monolith/services, main components, how they talk.]
|
|
36
9
|
|
|
37
10
|
## Technology Stack
|
|
38
11
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
- **Framework:** [e.g., React 18, Vue 3, Svelte, Solid]
|
|
46
|
-
- **Meta-framework:** [e.g., Next.js 14, Nuxt 3, SvelteKit, none]
|
|
47
|
-
- **Styling:** [e.g., Tailwind CSS, CSS Modules, Styled Components]
|
|
48
|
-
- **UI Library:** [e.g., shadcn/ui, Radix, Headless UI, custom]
|
|
49
|
-
- **State Management:** [e.g., React Context, Zustand, Redux, Pinia, none]
|
|
50
|
-
- **Form Handling:** [e.g., React Hook Form, Formik, native]
|
|
51
|
-
- **Routing:** [e.g., Next.js App Router, React Router, Vue Router]
|
|
52
|
-
|
|
53
|
-
### Backend
|
|
54
|
-
- **Framework:** [e.g., Express, Fastify, FastAPI, Django, Rails, none]
|
|
55
|
-
- **API Style:** [e.g., REST, GraphQL, tRPC, gRPC]
|
|
56
|
-
- **API Documentation:** [e.g., OpenAPI/Swagger, GraphQL introspection]
|
|
57
|
-
|
|
58
|
-
### Database
|
|
59
|
-
- **Primary Database:** [e.g., PostgreSQL 16, MySQL, MongoDB, SQLite]
|
|
60
|
-
- **ORM/Query Builder:** [e.g., Prisma, Drizzle, SQLAlchemy, none]
|
|
61
|
-
- **Migrations:** [e.g., Prisma Migrate, Alembic, manual SQL]
|
|
62
|
-
- **Caching:** [e.g., Redis, in-memory, none]
|
|
63
|
-
|
|
64
|
-
### Authentication & Authorization
|
|
65
|
-
- **Authentication Provider:** [e.g., NextAuth.js, Auth0, Clerk, Supabase Auth, custom]
|
|
66
|
-
- **Session Management:** [e.g., JWT, cookies, sessions]
|
|
67
|
-
- **Authorization Pattern:** [e.g., RBAC, ABAC, simple ownership]
|
|
68
|
-
|
|
69
|
-
### External Services
|
|
70
|
-
- **Email:** [e.g., Resend, SendGrid, AWS SES, none]
|
|
71
|
-
- **File Storage:** [e.g., AWS S3, Cloudflare R2, local filesystem]
|
|
72
|
-
- **Payment Processing:** [e.g., Stripe, none]
|
|
73
|
-
- **Analytics:** [e.g., Vercel Analytics, Plausible, none]
|
|
74
|
-
- **Error Tracking:** [e.g., Sentry, none]
|
|
75
|
-
- **[Other services]:** [e.g., Algolia for search, Twilio for SMS]
|
|
76
|
-
|
|
77
|
-
### Deployment & Infrastructure
|
|
78
|
-
- **Hosting:** [e.g., Vercel, AWS, Railway, self-hosted]
|
|
79
|
-
- **Database Hosting:** [e.g., Vercel Postgres, Neon, AWS RDS, self-hosted]
|
|
80
|
-
- **CI/CD:** [e.g., GitHub Actions, none]
|
|
81
|
-
- **Monitoring:** [e.g., Vercel Monitoring, Datadog, none]
|
|
82
|
-
|
|
83
|
-
### Development Tools
|
|
84
|
-
- **TypeScript:** [Yes/No]
|
|
85
|
-
- **Linting:** [e.g., ESLint, Biome, none]
|
|
86
|
-
- **Formatting:** [e.g., Prettier, Biome, none]
|
|
87
|
-
- **Testing:** [e.g., Vitest, Jest, Playwright, Cypress, none]
|
|
88
|
-
- **Git Hooks:** [e.g., Husky, lint-staged, none]
|
|
89
|
-
|
|
90
|
-
---
|
|
12
|
+
| Layer | Choice | Why |
|
|
13
|
+
|-------|--------|-----|
|
|
14
|
+
| Frontend | [TODO] | [TODO] |
|
|
15
|
+
| Backend | [TODO] | [TODO] |
|
|
16
|
+
| Database | [TODO] | [TODO] |
|
|
17
|
+
| Hosting | [TODO] | [TODO] |
|
|
91
18
|
|
|
92
19
|
## Project Structure
|
|
93
20
|
|
|
94
|
-
### Directory Organization
|
|
95
|
-
|
|
96
|
-
```
|
|
97
|
-
project-root/
|
|
98
|
-
├── project-context/ # Project context documents (Telo3)
|
|
99
|
-
├── src/ # Source code
|
|
100
|
-
│ ├── app/ # [Framework-specific structure]
|
|
101
|
-
│ ├── components/ # React/Vue/Svelte components
|
|
102
|
-
│ ├── lib/ # Shared utilities
|
|
103
|
-
│ ├── styles/ # Global styles
|
|
104
|
-
│ └── types/ # TypeScript type definitions
|
|
105
|
-
├── public/ # Static assets
|
|
106
|
-
├── tests/ # Test files
|
|
107
|
-
├── docs/ # Additional documentation
|
|
108
|
-
├── package.json # Dependencies
|
|
109
|
-
├── tsconfig.json # TypeScript configuration
|
|
110
|
-
└── [Other config files]
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
### Key Directories
|
|
114
|
-
|
|
115
|
-
| Directory | Purpose | Naming Convention |
|
|
116
|
-
|-----------|---------|-------------------|
|
|
117
|
-
| `/src/app` | [e.g., Next.js App Router pages] | [e.g., kebab-case] |
|
|
118
|
-
| `/src/components` | [e.g., Reusable React components] | [e.g., PascalCase] |
|
|
119
|
-
| `/src/lib` | [e.g., Utility functions, API clients] | [e.g., camelCase] |
|
|
120
|
-
| `/src/types` | [e.g., TypeScript interfaces and types] | [e.g., PascalCase] |
|
|
121
|
-
|
|
122
|
-
---
|
|
123
|
-
|
|
124
|
-
## Data Architecture
|
|
125
|
-
|
|
126
|
-
### Data Model
|
|
127
|
-
[High-level description of core entities and relationships]
|
|
128
|
-
|
|
129
|
-
```
|
|
130
|
-
User ──< Posts ──< Comments
|
|
131
|
-
│
|
|
132
|
-
└──< Profile (1:1)
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
### Key Entities
|
|
136
|
-
|
|
137
|
-
#### User
|
|
138
|
-
- **Purpose:** [What this entity represents]
|
|
139
|
-
- **Key Fields:** id, email, passwordHash, createdAt
|
|
140
|
-
- **Relationships:** hasMany Posts, hasOne Profile
|
|
141
|
-
- **Access Control:** [Who can read/write]
|
|
142
|
-
|
|
143
|
-
#### [Entity Name]
|
|
144
|
-
- **Purpose:**
|
|
145
|
-
- **Key Fields:**
|
|
146
|
-
- **Relationships:**
|
|
147
|
-
- **Access Control:**
|
|
148
|
-
|
|
149
|
-
### Data Flow
|
|
150
|
-
|
|
151
|
-
#### Read Operations
|
|
152
|
-
[How does data flow from database to user?]
|
|
153
|
-
|
|
154
|
-
1. Client requests data via API
|
|
155
|
-
2. API handler validates request
|
|
156
|
-
3. Database query executed
|
|
157
|
-
4. Data transformed/serialized
|
|
158
|
-
5. Response returned to client
|
|
159
|
-
|
|
160
|
-
#### Write Operations
|
|
161
|
-
[How does data flow from user to database?]
|
|
162
|
-
|
|
163
|
-
1. Client submits data via API
|
|
164
|
-
2. API handler validates input
|
|
165
|
-
3. Business logic executed
|
|
166
|
-
4. Database transaction committed
|
|
167
|
-
5. Response returned to client
|
|
168
|
-
|
|
169
|
-
---
|
|
170
|
-
|
|
171
|
-
## API Architecture
|
|
172
|
-
|
|
173
|
-
### API Style
|
|
174
|
-
[REST, GraphQL, tRPC, etc.]
|
|
175
|
-
|
|
176
|
-
### Base URL
|
|
177
|
-
- **Production:** `https://api.example.com`
|
|
178
|
-
- **Development:** `http://localhost:3000/api`
|
|
179
|
-
|
|
180
|
-
### API Structure
|
|
181
|
-
|
|
182
|
-
#### REST Endpoints (if applicable)
|
|
183
|
-
| Endpoint | Method | Purpose | Auth Required |
|
|
184
|
-
|----------|--------|---------|---------------|
|
|
185
|
-
| `/api/users` | GET | List users | Yes |
|
|
186
|
-
| `/api/users/:id` | GET | Get user | Yes |
|
|
187
|
-
| `/api/users` | POST | Create user | No |
|
|
188
|
-
|
|
189
|
-
#### GraphQL Schema (if applicable)
|
|
190
|
-
[Reference to schema file or high-level schema description]
|
|
191
|
-
|
|
192
|
-
#### tRPC Routers (if applicable)
|
|
193
|
-
[List of tRPC routers and their purposes]
|
|
194
|
-
|
|
195
|
-
### API Conventions
|
|
196
|
-
- **Authentication:** [Bearer token, cookies, etc.]
|
|
197
|
-
- **Error Format:** [Standard error response structure]
|
|
198
|
-
- **Pagination:** [Cursor-based, offset-based, etc.]
|
|
199
|
-
- **Rate Limiting:** [Policy if implemented]
|
|
200
|
-
|
|
201
|
-
---
|
|
202
|
-
|
|
203
|
-
## Authentication & Authorization
|
|
204
|
-
|
|
205
|
-
### Authentication Flow
|
|
206
|
-
|
|
207
|
-
```
|
|
208
|
-
1. User submits credentials
|
|
209
|
-
2. Server validates credentials
|
|
210
|
-
3. Server generates session/token
|
|
211
|
-
4. Client stores session/token
|
|
212
|
-
5. Client includes token in subsequent requests
|
|
213
|
-
```
|
|
214
|
-
|
|
215
|
-
### Session Management
|
|
216
|
-
- **Storage:** [Where are sessions stored?]
|
|
217
|
-
- **Lifetime:** [How long are sessions valid?]
|
|
218
|
-
- **Refresh:** [How are sessions refreshed?]
|
|
219
|
-
|
|
220
|
-
### Authorization Strategy
|
|
221
|
-
[How are permissions enforced?]
|
|
222
|
-
|
|
223
|
-
- **Public routes:** [List or criteria]
|
|
224
|
-
- **Authenticated routes:** [List or criteria]
|
|
225
|
-
- **Role-based access:** [Roles and permissions]
|
|
226
|
-
|
|
227
|
-
### Security Boundaries
|
|
228
|
-
[What are the security zones in the system?]
|
|
229
|
-
|
|
230
|
-
- **Public:** [What is accessible without authentication?]
|
|
231
|
-
- **Authenticated:** [What requires login?]
|
|
232
|
-
- **Admin:** [What requires elevated privileges?]
|
|
233
|
-
|
|
234
|
-
---
|
|
235
|
-
|
|
236
|
-
## State Management
|
|
237
|
-
|
|
238
|
-
### Client-Side State
|
|
239
|
-
[How is state managed in the frontend?]
|
|
240
|
-
|
|
241
|
-
- **Global State:** [Tool/pattern used]
|
|
242
|
-
- **Server State:** [How is server data cached/synchronized?]
|
|
243
|
-
- **Form State:** [How are forms managed?]
|
|
244
|
-
- **URL State:** [Is state stored in URL params?]
|
|
245
|
-
|
|
246
|
-
### Server-Side State
|
|
247
|
-
[How is state managed on the backend?]
|
|
248
|
-
|
|
249
|
-
- **Session State:** [Where/how stored]
|
|
250
|
-
- **Application State:** [Any in-memory state?]
|
|
251
|
-
- **Database State:** [How is consistency maintained?]
|
|
252
|
-
|
|
253
|
-
---
|
|
254
|
-
|
|
255
|
-
## External Service Integration
|
|
256
|
-
|
|
257
|
-
### [Service Name]
|
|
258
|
-
- **Purpose:** [Why is this service used?]
|
|
259
|
-
- **Integration Method:** [API, SDK, webhook, etc.]
|
|
260
|
-
- **Configuration:** [Environment variables required]
|
|
261
|
-
- **Data Sharing:** [What data is sent to this service?]
|
|
262
|
-
- **Fallback:** [What happens if service is unavailable?]
|
|
263
|
-
|
|
264
|
-
---
|
|
265
|
-
|
|
266
|
-
## Environment Configuration
|
|
267
|
-
|
|
268
|
-
### Environment Variables
|
|
269
|
-
|
|
270
|
-
| Variable | Purpose | Required | Default |
|
|
271
|
-
|----------|---------|----------|---------|
|
|
272
|
-
| `DATABASE_URL` | PostgreSQL connection string | Yes | - |
|
|
273
|
-
| `NEXTAUTH_SECRET` | NextAuth.js session secret | Yes | - |
|
|
274
|
-
| `NEXTAUTH_URL` | Application URL | Yes | - |
|
|
275
|
-
| `[OTHER]` | [Description] | Yes/No | [Value] |
|
|
276
|
-
|
|
277
|
-
### Configuration Files
|
|
278
|
-
- `package.json` — Dependencies and scripts
|
|
279
|
-
- `tsconfig.json` — TypeScript compiler configuration
|
|
280
|
-
- `.env.local` — Local environment variables (not committed)
|
|
281
|
-
- `.env.example` — Environment variable template
|
|
282
|
-
- `[Other config files]`
|
|
283
|
-
|
|
284
|
-
---
|
|
285
|
-
|
|
286
|
-
## Build & Deployment
|
|
287
|
-
|
|
288
|
-
### Build Process
|
|
289
|
-
|
|
290
|
-
```bash
|
|
291
|
-
# Development
|
|
292
|
-
npm run dev
|
|
293
|
-
|
|
294
|
-
# Production build
|
|
295
|
-
npm run build
|
|
296
|
-
|
|
297
|
-
# Start production server
|
|
298
|
-
npm start
|
|
299
21
|
```
|
|
300
|
-
|
|
301
|
-
### Deployment Strategy
|
|
302
|
-
[How is the application deployed?]
|
|
303
|
-
|
|
304
|
-
- **Environments:** Development, Staging, Production
|
|
305
|
-
- **Deployment Method:** [Git-based, CI/CD pipeline, manual]
|
|
306
|
-
- **Rollback Strategy:** [How to revert if deployment fails]
|
|
307
|
-
|
|
308
|
-
### Database Migrations
|
|
309
|
-
[How are database schema changes managed?]
|
|
310
|
-
|
|
311
|
-
```bash
|
|
312
|
-
# Create migration
|
|
313
|
-
npm run db:migrate:create
|
|
314
|
-
|
|
315
|
-
# Run migrations
|
|
316
|
-
npm run db:migrate
|
|
317
|
-
|
|
318
|
-
# Rollback migration
|
|
319
|
-
npm run db:migrate:rollback
|
|
22
|
+
[TODO: folder tree, ~10 lines, real paths]
|
|
320
23
|
```
|
|
321
24
|
|
|
322
|
-
|
|
25
|
+
## Data Flow
|
|
323
26
|
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
### Frontend Performance
|
|
327
|
-
- **Code Splitting:** [Strategy used]
|
|
328
|
-
- **Image Optimization:** [How images are optimized]
|
|
329
|
-
- **Lazy Loading:** [What is lazy loaded]
|
|
330
|
-
- **Caching Strategy:** [Browser caching, service workers]
|
|
331
|
-
|
|
332
|
-
### Backend Performance
|
|
333
|
-
- **Database Indexing:** [Key indexes]
|
|
334
|
-
- **Query Optimization:** [Strategies used]
|
|
335
|
-
- **Caching:** [What is cached and where]
|
|
336
|
-
- **Rate Limiting:** [If implemented]
|
|
337
|
-
|
|
338
|
-
---
|
|
339
|
-
|
|
340
|
-
## Security Architecture
|
|
341
|
-
|
|
342
|
-
### Security Layers
|
|
343
|
-
1. **Network Security:** [HTTPS, CORS, rate limiting]
|
|
344
|
-
2. **Authentication:** [How users are authenticated]
|
|
345
|
-
3. **Authorization:** [How access is controlled]
|
|
346
|
-
4. **Input Validation:** [Where/how validation occurs]
|
|
347
|
-
5. **Output Encoding:** [How XSS is prevented]
|
|
348
|
-
6. **Secrets Management:** [How secrets are stored]
|
|
349
|
-
|
|
350
|
-
### Known Security Boundaries
|
|
351
|
-
[What are the trust boundaries in the system?]
|
|
352
|
-
|
|
353
|
-
- [Boundary 1: e.g., "Client code cannot be trusted"]
|
|
354
|
-
- [Boundary 2: e.g., "API validates all inputs"]
|
|
355
|
-
|
|
356
|
-
---
|
|
27
|
+
[TODO: How a request/event moves through the system. Note auth boundaries and data stores.]
|
|
357
28
|
|
|
358
29
|
## Architectural Decisions
|
|
359
30
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
**Decision:** [What was decided?]
|
|
364
|
-
**Context:** [What was the situation?]
|
|
365
|
-
**Rationale:** [Why was this decided?]
|
|
366
|
-
**Alternatives Considered:** [What else was considered?]
|
|
367
|
-
**Trade-offs:** [What are the downsides?]
|
|
368
|
-
**Status:** [Accepted / Superseded / Deprecated]
|
|
369
|
-
|
|
370
|
-
---
|
|
371
|
-
|
|
372
|
-
## Technical Debt
|
|
373
|
-
|
|
374
|
-
[Document known technical debt that should be addressed]
|
|
375
|
-
|
|
376
|
-
### High Priority
|
|
377
|
-
- [ ] [Debt item 1] — Impact: [Description]
|
|
378
|
-
|
|
379
|
-
### Medium Priority
|
|
380
|
-
- [ ] [Debt item 2] — Impact: [Description]
|
|
381
|
-
|
|
382
|
-
### Low Priority
|
|
383
|
-
- [ ] [Debt item 3] — Impact: [Description]
|
|
384
|
-
|
|
385
|
-
---
|
|
31
|
+
| Decision | Choice | Rationale | Date |
|
|
32
|
+
|----------|--------|-----------|------|
|
|
33
|
+
| [TODO] | [TODO] | [TODO] | [TODO] |
|
|
386
34
|
|
|
387
35
|
## Known Limitations
|
|
388
36
|
|
|
389
|
-
[
|
|
390
|
-
|
|
391
|
-
- **[Limitation 1]:** [Description and impact]
|
|
392
|
-
- **[Limitation 2]:** [Description and impact]
|
|
393
|
-
|
|
394
|
-
---
|
|
395
|
-
|
|
396
|
-
## Future Architectural Considerations
|
|
397
|
-
|
|
398
|
-
[Things to consider for future scaling or evolution]
|
|
399
|
-
|
|
400
|
-
- [Consideration 1: e.g., "May need to split into microservices at 10x scale"]
|
|
401
|
-
- [Consideration 2]
|
|
402
|
-
|
|
403
|
-
---
|
|
404
|
-
|
|
405
|
-
## References
|
|
406
|
-
|
|
407
|
-
- [Link to API documentation]
|
|
408
|
-
- [Link to database schema]
|
|
409
|
-
- [Link to deployment documentation]
|
|
410
|
-
- [Link to third-party service documentation]
|
|
411
|
-
|
|
412
|
-
---
|
|
413
|
-
|
|
414
|
-
## Document History
|
|
415
|
-
|
|
416
|
-
| Date | Author | Changes |
|
|
417
|
-
|------|--------|---------|
|
|
418
|
-
| [Date] | [Name] | Initial version |
|
|
37
|
+
- [TODO: constraints, tech debt, scale ceilings.]
|