|
1 | 1 | # AGENTS.md - Fieldstack Agent Guide |
2 | 2 |
|
3 | | -> Project Status: Planning/Documentation phase (implementation planned 2026-2027) |
4 | | -> This repo currently contains specifications and design docs. No source code yet. |
5 | | -
|
6 | | ---- |
7 | | - |
8 | | -## Repository Orientation |
9 | | - |
10 | | -- Primary docs: `docs/v2_FINANCIAL-LEDGER/` (mostly Korean). |
11 | | -- Public overview: `README.md`. |
12 | | -- Treat commands and conventions as planned until implementation lands. |
13 | | - |
14 | | ---- |
15 | | - |
16 | | -## Build / Lint / Test Commands |
17 | | - |
18 | | -**Current State**: No build system implemented yet. Commands below are planned. |
19 | | - |
20 | | -**Planned Dev/Build/Test/Lint (from docs)**: |
21 | | - |
22 | | -```bash |
23 | | -# Development (when implemented) |
24 | | -pnpm dev # Run dev workflow (see 98-build-process.md) |
25 | | -pnpm dev:web # Vite dev server (port 5173) |
26 | | -pnpm dev:api # Express backend (port 3000) |
27 | | - |
28 | | -# Production build |
29 | | -pnpm build # Build all packages (integrated mode) |
30 | | -pnpm build:web # Frontend only |
31 | | -pnpm build:api # Backend only |
32 | | -pnpm start # Start production server |
33 | | - |
34 | | -# Testing (planned: Vitest + React Testing Library) |
35 | | -pnpm test # Run all tests |
36 | | -pnpm test:unit # Unit tests only |
37 | | -pnpm test:e2e # E2E tests (Playwright) |
38 | | -pnpm test:watch # Watch mode |
39 | | - |
40 | | -# Linting (planned: ESLint + Prettier) |
41 | | -pnpm lint # Lint all code |
42 | | -pnpm lint:fix # Auto-fix issues |
43 | | -pnpm format # Format with Prettier |
44 | | - |
45 | | -# Type checking |
46 | | -pnpm typecheck # TypeScript type checking |
47 | | -``` |
48 | | - |
49 | | -**Single Test Runs**: |
50 | | -- No single-test command is documented yet. |
51 | | -- Once scripts exist, prefer project-defined commands in `package.json`. |
52 | | - |
53 | | ---- |
54 | | - |
55 | | -## Build Process Details (Docs) |
56 | | - |
57 | | -Reference: `docs/v2_FINANCIAL-LEDGER/deployment/98-build-process.md` |
58 | | - |
59 | | -**Root scripts (planned)**: |
60 | | - |
61 | | -```json |
62 | | -{ |
63 | | - "scripts": { |
64 | | - "dev": "pnpm --parallel dev", |
65 | | - "dev:api": "pnpm --filter api dev", |
66 | | - "dev:web": "pnpm --filter web dev", |
67 | | - "build": "pnpm build:web && pnpm build:api && pnpm postbuild", |
68 | | - "build:web": "pnpm --filter web build", |
69 | | - "build:api": "pnpm --filter api build", |
70 | | - "postbuild": "node scripts/copy-frontend.js", |
71 | | - "start": "cd apps/api && node dist/index.js", |
72 | | - "test": "pnpm --recursive test", |
73 | | - "lint": "pnpm --recursive lint" |
74 | | - } |
75 | | -} |
76 | | -``` |
77 | | - |
78 | | -**Build verification (planned)**: |
79 | | - |
80 | | -```bash |
81 | | -ls -la apps/web/dist |
82 | | -ls -la apps/api/dist |
83 | | -ls -la apps/api/public |
84 | | -du -sh apps/web/dist |
85 | | -du -sh apps/api/dist |
86 | | -du -sh apps/api/public |
87 | | -cd apps/api |
88 | | -node dist/index.js |
89 | | -``` |
90 | | - |
91 | | ---- |
92 | | - |
93 | | -## Code Style & Conventions (Planned) |
94 | | - |
95 | | -### TypeScript Strictness |
96 | | - |
97 | | -- Use strict TS settings (planned in `tsconfig.json`). |
98 | | -- Never use `any`, `@ts-ignore`, or `@ts-expect-error`. |
99 | | - |
100 | | -### Type Definitions |
101 | | - |
102 | | -- Prefer `interface` for object shapes. |
103 | | -- Use `type` for unions, intersections, utilities. |
104 | | -- Define module types in `types/index.ts`. |
105 | | - |
106 | | -### Imports |
107 | | - |
108 | | -Order (planned ESLint rule): |
109 | | -1. External libraries (`react`, `express`) |
110 | | -2. Internal packages (`@fieldstack/core`, `@fieldstack/controls`) |
111 | | -3. Relative imports (`./`, `../`) |
112 | | - |
113 | | -Use `import type` for types. |
114 | | - |
115 | | -### Naming Conventions |
116 | | - |
117 | | -| Item | Convention | Example | |
118 | | -| --- | --- | --- | |
119 | | -| Components | PascalCase | `MyComponent.tsx` | |
120 | | -| Hooks | `use` + camelCase | `useLedger.ts` | |
121 | | -| Services | camelCase | `ledgerService.ts` | |
122 | | -| Types/Interfaces | PascalCase | `LedgerItem` | |
123 | | -| Constants | UPPER_SNAKE_CASE | `MAX_FILE_SIZE` | |
124 | | -| Files | kebab-case or PascalCase | `ledger-list.tsx` | |
125 | | -| API routes | kebab-case | `/api/ledger-items` | |
126 | | - |
127 | | -### Error Handling |
128 | | - |
129 | | -- Backend: explicit try/catch with meaningful status + message. |
130 | | -- Frontend: user-friendly error messages; rethrow when caller needs it. |
131 | | -- Never leave empty catch blocks. |
132 | | -- Never log sensitive data (tokens, passwords). |
133 | | - |
134 | | -### Validation |
135 | | - |
136 | | -- Zod is preferred for input validation. |
137 | | -- Yup is listed as an alternative, but use Zod unless module docs require otherwise. |
138 | | - |
139 | | ---- |
140 | | - |
141 | | -## UI/UX Guidelines (Planned) |
142 | | - |
143 | | -- UI is fully separated from core/module business logic. |
144 | | -- Prefer `@fieldstack/controls` components for consistency. |
145 | | -- Tailwind CSS is the planned styling approach. |
146 | | -- Users can override UI with `apps/web/src/custom-ui/`. |
147 | | - |
148 | | -Design tokens (from `docs/v2_FINANCIAL-LEDGER/ui/design-system.md`): |
149 | | -- Primary color: blue scale (500 = `#3B82F6`). |
150 | | -- Semantic colors: success `#10B981`, warning `#F59E0B`, danger `#EF4444`. |
151 | | -- Fonts: Inter (text), JetBrains Mono (code). |
152 | | -- Breakpoints: `sm <= 640`, `md >= 768`, `lg >= 1024`. |
153 | | - |
154 | | ---- |
155 | | - |
156 | | -## Module Rules (Planned) |
157 | | - |
158 | | -- Modules are self-contained (no cross-module imports). |
159 | | -- Keep `frontend/`, `backend/`, `types/` within each module. |
160 | | -- Use Event Bus for inter-module communication. |
161 | | -- Core only forwards file uploads; modules validate/parse/process. |
162 | | -- Privacy-first: no telemetry, no SaaS, no data collection. |
163 | | - |
164 | | ---- |
165 | | - |
166 | | -## Testing Guidelines (Planned) |
167 | | - |
168 | | -- Backend: Vitest |
169 | | -- Frontend: React Testing Library |
170 | | -- E2E: Playwright (optional) |
171 | | -- Write tests for critical paths |
172 | | - |
173 | | ---- |
174 | | - |
175 | | -## Tooling & Infra (Planned) |
176 | | - |
177 | | -- Package manager: pnpm (workspace) |
178 | | -- Node.js: >= 20 |
179 | | -- TypeScript: >= 5 |
180 | | -- React: >= 18 |
181 | | -- Backend: Express (or Fastify) |
182 | | - |
183 | | ---- |
184 | | - |
185 | | -## Cursor / Copilot Rules |
186 | | - |
187 | | -- No `.cursor/rules/`, `.cursorrules`, or `.github/copilot-instructions.md` found. |
188 | | - |
189 | | ---- |
190 | | - |
191 | | -## Key References |
192 | | - |
193 | | -- `docs/v2_FINANCIAL-LEDGER/technical/tech-stack.md` |
194 | | -- `docs/v2_FINANCIAL-LEDGER/deployment/98-build-process.md` |
195 | | -- `docs/v2_FINANCIAL-LEDGER/ui/design-system.md` |
196 | | -- `docs/v2_FINANCIAL-LEDGER/ui/core-components.md` |
197 | | -- `README.md` |
198 | | - |
199 | | ---- |
200 | | - |
201 | | -Last Updated: 2026-02-03 |
| 3 | +This file provides high-signal, repo-specific guidance for AI agents working in the Fieldstack repository. Read this before taking action to avoid architectural mistakes. |
| 4 | + |
| 5 | +## Project Status & Environment |
| 6 | +- **Current Phase**: Phase 1.5 in progress. Core UI Shell is running but mostly mocked. Backend API endpoints are largely unimplemented. |
| 7 | +- **Workspace**: `pnpm` workspace with `node-linker=hoisted`. |
| 8 | +- **References**: Check `CLAUDE.md` and `docs/v2_FINANCIAL-LEDGER/` for phase-specific checklists and design tokens. |
| 9 | + |
| 10 | +## Developer Commands |
| 11 | + |
| 12 | +### Development Servers |
| 13 | +- `pnpm dev` — Runs web + api in parallel (includes setup wizard). |
| 14 | +- `pnpm dev:bypass` — **(Crucial)** Runs web + api but skips the installation wizard via `INSTALL_MODE=bypass`. Use this to test core UI directly. |
| 15 | +- `pnpm dev:web` / `pnpm dev:api` — Run frontend or backend individually. |
| 16 | +- `pnpm storybook` — Runs Storybook for `@fieldstack/controls` on **port 6007**. |
| 17 | + |
| 18 | +### Testing & Verification |
| 19 | +- `pnpm test` — Runs all tests recursively using Vitest. |
| 20 | +- `pnpm --filter <package> test` — Run tests for a specific workspace package (e.g., `api`, `core`). |
| 21 | +- `pnpm exec vitest run <path/to/test.ts>` — Run a single test file. |
| 22 | +- `pnpm lint` — Run ESLint across all workspace packages. |
| 23 | +- `pnpm typecheck` — Run TypeScript compiler checks. |
| 24 | +- `pnpm build` — Builds web, builds api, then copies web build to `apps/api/public` via `scripts/copy-frontend.js`. |
| 25 | + |
| 26 | +## Architecture Quirks |
| 27 | + |
| 28 | +### Frontend (`apps/web`) |
| 29 | +- **Hash Routing**: Uses Hash-based routing (`#login`, `#home`, `#admin`) managed by a custom state machine in `apps/web/src/main.tsx` (`effectiveRoute`). |
| 30 | +- **Auth State**: Authentication and session state are persisted in `sessionStorage` using the `fs_` prefix (e.g., `fs_auth`, `fs_admin`). |
| 31 | +- **Dev Mocks**: When testing auth UI locally, use `otp1234` for the OTP flow and `temp1234` for the force-password-change flow. |
| 32 | + |
| 33 | +### Backend (`apps/api`) |
| 34 | +- **Dynamic Module Loading**: Backend modules are dynamically scanned and loaded via `apps/api/src/loader/index.ts`. |
| 35 | +- **Module Requirements**: A backend module will only be loaded if it has a valid `module.json` manifest with `"enabled": true`. |
| 36 | + |
| 37 | +### Shared & UI Packages |
| 38 | +- **`packages/controls`**: All P0/P0.5 components are fully implemented (`ready: true`). Styled with `fs-` prefixed CSS classes and design tokens. Use `@fieldstack/controls` in `apps/web` — do not write inline component styles in views. |
| 39 | +- **Inter-module Communication**: Direct module-to-module imports are strictly forbidden. All cross-module communication must use the Event Bus. |
| 40 | + |
| 41 | +## Strict Code Rules |
| 42 | + |
| 43 | +- **TypeScript Strictness**: **NEVER** use `any`, `@ts-ignore`, or `@ts-expect-error`. If types are wrong, fix the types. |
| 44 | +- **Imports**: |
| 45 | + 1. External libraries (`react`, `express`) |
| 46 | + 2. Internal workspace packages (`@fieldstack/core`, `@fieldstack/controls`) |
| 47 | + 3. Relative imports (`./`, `../`) |
| 48 | + - Always use `import type` when importing types/interfaces. |
| 49 | +- **Naming Conventions**: |
| 50 | + - Components / Types / Interfaces: `PascalCase` |
| 51 | + - Hooks: `useCamelCase` |
| 52 | + - Constants: `UPPER_SNAKE_CASE` |
| 53 | + - Files / API Routes: `kebab-case` |
| 54 | +- **Validation**: Use Zod for schema and input validation. |
| 55 | +- **Error Handling**: Never leave empty `catch` blocks. Frontend should present user-friendly errors; backend should throw explicit HTTP statuses. Never log sensitive tokens. |
0 commit comments