|
1 | | -# Arkstack Agent Workflows |
| 1 | +# Arkstack Scaffold Agent Workflows |
| 2 | + |
| 3 | +This file is for AI agents working inside applications scaffolded by Arkstack. It assumes the agent has access to the generated project only, not to the Arkstack framework monorepo. |
| 4 | + |
| 5 | +Read `SKILLS.md` first, then use these workflows to combine the available skills safely. |
| 6 | + |
| 7 | +## Operating Rules |
| 8 | + |
| 9 | +- Start from the scaffolded app root. |
| 10 | +- Inspect the local `package.json` before running commands. |
| 11 | +- Use the package manager indicated by the lockfile. |
| 12 | +- Detect whether the app is Express or H3 before editing routes, middleware, or runtime code. |
| 13 | +- Detect whether the app is full or lean before using database, auth, resource, or controller workflows. |
| 14 | +- Prefer `ark` generators when the project structure supports them. |
| 15 | +- Ask before destructive database, storage, overwrite, delete, publish, or release operations. |
| 16 | + |
| 17 | +## Understand the App |
| 18 | + |
| 19 | +1. Read `package.json`. |
| 20 | +2. Check for `pnpm-lock.yaml`, `package-lock.json`, `yarn.lock`, or Bun lockfiles. |
| 21 | +3. Identify the runtime: |
| 22 | + - Express: `@arkstack/driver-express`. |
| 23 | + - H3: `@arkstack/driver-h3`. |
| 24 | +4. Identify the scope: |
| 25 | + - Full: has `src/app`, `src/database`, `src/routes/api.ts`, and `arkormx.config.ts`. |
| 26 | + - Lean: lacks those full-template files. |
| 27 | +5. Read `src/routes/web.ts`, and read `src/routes/api.ts` if it exists. |
| 28 | +6. Read `src/core/app.ts`, `src/core/bootstrap.ts`, and `src/config/middleware.ts` only when runtime behavior matters. |
| 29 | + |
| 30 | +## Add a Simple Web Route |
| 31 | + |
| 32 | +1. Inspect `src/routes/web.ts`. |
| 33 | +2. Use the existing runtime driver import for `Router`. |
| 34 | +3. Add the route closure or controller mapping. |
| 35 | +4. If rendering HTML, use `view()` from `@arkstack/view` and keep templates in `src/resources/views`. |
| 36 | +5. Generate a view with `ark make:view <name>` when useful. |
| 37 | +6. Verify with the dev server, `ark route:list`, or the existing test suite. |
| 38 | + |
| 39 | +## Add an API Route in a Full Template |
| 40 | + |
| 41 | +1. Confirm `src/routes/api.ts` and `src/app/http/controllers` exist. |
| 42 | +2. Inspect nearby controllers and resources. |
| 43 | +3. Generate missing primitives: |
| 44 | + - `ark make:controller <Name> --api` |
| 45 | + - `ark make:resource resource <Name>` |
| 46 | + - `ark make:resource collection <Name>Collection` |
| 47 | + - `ark make:full-resource <Name> --model <Model>` for a model-backed resource set. |
| 48 | +4. Register the route in `src/routes/api.ts`. |
| 49 | +5. Move business logic into a service or focused helper when the controller action becomes more than request orchestration. |
| 50 | +6. Add or update tests. |
| 51 | +7. Verify with `ark route:list` and the local test command. |
2 | 52 |
|
3 | | -This file describes higher-order workflows for AI agents working inside Arkstack projects. It composes the lower-level capabilities documented in `SKILLS.md`. |
| 53 | +## Add an API Route in a Lean Template |
4 | 54 |
|
5 | | -Agents should read `SKILLS.md` first, then use this file to plan multi-step work. |
| 55 | +1. Confirm the app lacks `src/app` and `src/routes/api.ts`. |
| 56 | +2. Do not use controller/resource/model generators unless the user wants to expand the project structure. |
| 57 | +3. Add lightweight routes to `src/routes/web.ts`, or create `src/routes/api.ts` only if you also update bootstrap/app route loading as needed. |
| 58 | +4. Keep handlers small. Extract reusable behavior into local modules if it grows. |
| 59 | +5. Verify with the dev server, `ark route:list`, or tests. |
6 | 60 |
|
7 | | -## Operating Principles |
| 61 | +## Add a Database-Backed Feature |
8 | 62 |
|
9 | | -- Work from the project root. |
10 | | -- Inspect `package.json`, lockfiles, runtime dependencies, route files, and nearby source before changing code. |
11 | | -- Prefer Arkstack CLI generators for controllers, resources, models, migrations, views, and commands. |
12 | | -- Keep application logic runtime-agnostic unless the task is specifically about Express, H3, or another driver. |
13 | | -- Verify with the narrowest command that gives useful confidence. |
14 | | -- Ask before destructive operations. |
| 63 | +Use this only in full templates. |
| 64 | + |
| 65 | +1. Confirm `@arkstack/database`, `arkormx`, `src/database`, and `arkormx.config.ts` exist. |
| 66 | +2. Generate persistence files: |
| 67 | + - `ark make:model <Name>` |
| 68 | + - `ark make:migration <migration_name>` |
| 69 | + - `ark make:factory <Name>` when tests or seed data need it. |
| 70 | + - `ark make:seeder <Name>` when reusable seed data is needed. |
| 71 | +3. Edit the model, migration, factory, and seeder files. |
| 72 | +4. Add controllers, resources, routes, or services as needed. |
| 73 | +5. Update `.env.example` when adding database-related configuration. |
| 74 | +6. Ask before running migrations against any database that may contain user data. |
| 75 | +7. Run `ark models:sync` when schema-derived model types should be refreshed. |
| 76 | +8. Verify with tests and route inspection. |
| 77 | + |
| 78 | +## Add Authentication Behavior |
| 79 | + |
| 80 | +Use this only when `@arkstack/auth` and auth models exist. |
| 81 | + |
| 82 | +1. Inspect `src/app/models/User.ts`, `PersonalAccessToken.ts`, and `UserTwoFactor.ts` if present. |
| 83 | +2. Inspect auth middleware, route protection, and existing tests. |
| 84 | +3. Keep auth persistence changes synchronized across models and migrations. |
| 85 | +4. Use environment variables for secrets such as `JWT_SECRET` and keep `.env.example` current. |
| 86 | +5. Add tests for login, logout, protected routes, token/session behavior, and error responses. |
15 | 87 |
|
16 | | -## Add an API Endpoint |
| 88 | +## Add Notifications |
17 | 89 |
|
18 | | -1. Inspect existing routes under `src/routes`. |
19 | | -2. Run `pnpm ark route:list` if the app can boot. |
20 | | -3. Generate missing pieces: |
21 | | - - `pnpm ark make:controller <Name> --api` |
22 | | - - `pnpm ark make:resource resource <Name>` when shaping a single response. |
23 | | - - `pnpm ark make:resource collection <Name>Collection` when returning lists. |
24 | | - - `pnpm ark make:full-resource <Name> --model <Model>` for a complete CRUD-style surface. |
25 | | -4. Register or update routes in the appropriate route file. |
26 | | -5. Put business logic in services or framework-neutral modules when the endpoint is not trivial. |
27 | | -6. Add or update tests. |
28 | | -7. Verify with `pnpm test` and `pnpm ark route:list`. |
| 90 | +Use this only when `@arkstack/notifications` and `src/config/notifications.ts` exist. |
29 | 91 |
|
30 | | -## Add a Database-Backed Feature |
| 92 | +1. Inspect notification config and existing templates. |
| 93 | +2. Use configured mail, SMS, or database channels rather than hard-coding providers. |
| 94 | +3. Keep provider credentials in environment variables. |
| 95 | +4. Update `.env.example` for new required provider settings. |
| 96 | +5. Add tests around message formatting and dispatch boundaries. |
31 | 97 |
|
32 | | -1. Confirm the project is a full template with Arkormx/database support. |
33 | | -2. Generate model and persistence files: |
34 | | - - `pnpm ark make:model <Name>` |
35 | | - - `pnpm ark make:migration <migration_name>` |
36 | | - - `pnpm ark make:factory <Name>` when tests or seed data need it. |
37 | | - - `pnpm ark make:seeder <Name>` when reusable seed data is needed. |
38 | | -3. Edit the migration and model fields. |
39 | | -4. Add controllers, resources, services, or routes as needed. |
40 | | -5. Run migrations only after confirming the target database is safe. |
41 | | -6. Run `pnpm ark models:sync` when schema-derived model typing should be refreshed. |
42 | | -7. Verify with tests and route inspection. |
| 98 | +## Add File Storage |
43 | 99 |
|
44 | | -## Add a View-Rendered Page |
| 100 | +Use this only when `@arkstack/filesystem` and `src/config/filesystem.ts` exist. |
45 | 101 |
|
46 | | -1. Inspect existing routes and view naming conventions. |
47 | | -2. Generate the view with `pnpm ark make:view <path-or-name>`. |
48 | | -3. Add or update the controller action that renders the view. |
49 | | -4. Register the route. |
50 | | -5. Keep reusable view data preparation in services or helpers when it grows beyond a simple action. |
51 | | -6. Verify the route list and run tests if the project has HTTP coverage. |
| 102 | +1. Inspect filesystem disks and links. |
| 103 | +2. Use Arkstack filesystem abstractions instead of direct provider SDK calls when possible. |
| 104 | +3. Keep credentials in environment variables. |
| 105 | +4. Run `ark storage:link` only when public/local links are required. |
| 106 | +5. Ask before running `ark storage:link --force`. |
| 107 | +6. Test upload, URL generation, download, and cleanup behavior without assuming remote services are available. |
52 | 108 |
|
53 | 109 | ## Add Middleware |
54 | 110 |
|
55 | | -1. Inspect existing middleware in `src/app/http/middlewares`. |
56 | | -2. Decide whether the middleware is runtime-agnostic or driver-specific. |
57 | | -3. Implement the middleware using the existing driver conventions. |
58 | | -4. Register it where routes or runtime bootstrap expect middleware. |
59 | | -5. Run `pnpm ark route:list` when route-level middleware changes route behavior. |
60 | | -6. Add tests for auth, request mutation, error handling, or response behavior. |
61 | | - |
62 | | -## Work on Authentication |
63 | | - |
64 | | -1. Inspect the app models for `User`, `PersonalAccessToken`, and two-factor models if present. |
65 | | -2. Inspect auth config, middleware, and existing tests before changing behavior. |
66 | | -3. Keep session/device behavior aligned with `@arkstack/auth` conventions. |
67 | | -4. Update database migrations and models together when auth persistence changes. |
68 | | -5. Add tests for login, logout, protected routes, token/session behavior, and error responses. |
69 | | - |
70 | | -## Work on Notifications |
| 111 | +1. Inspect `src/config/middleware.ts`. |
| 112 | +2. Identify the runtime driver. |
| 113 | +3. In a full template, place app-specific middleware under `src/app/http/middlewares` when appropriate. |
| 114 | +4. In a lean template, keep middleware local and minimal unless the user wants more structure. |
| 115 | +5. Register middleware through the existing middleware config pattern. |
| 116 | +6. Add tests when middleware changes auth, request parsing, headers, errors, or response behavior. |
71 | 117 |
|
72 | | -1. Inspect notification classes, drivers, and templates. |
73 | | -2. Use the notification module's channel abstractions for mail, SMS, or database notifications. |
74 | | -3. Keep mail templates under the existing view/resource convention. |
75 | | -4. Use config/env values for provider credentials rather than hard-coding secrets. |
76 | | -5. Add tests around notification formatting and driver dispatch boundaries. |
| 118 | +## Add a View-Rendered Page |
77 | 119 |
|
78 | | -## Work on Filesystem Features |
| 120 | +1. Inspect `src/routes/web.ts`. |
| 121 | +2. Inspect existing views under `src/resources/views`. |
| 122 | +3. Generate the view with `ark make:view <name>` if the command is available. |
| 123 | +4. Add or update the route that returns `view('<name>', data)`. |
| 124 | +5. Keep reusable data preparation outside the route closure when it grows. |
| 125 | +6. Verify in dev mode or with route tests. |
79 | 126 |
|
80 | | -1. Inspect filesystem configuration before writing storage code. |
81 | | -2. Use the `@arkstack/filesystem` API instead of direct provider SDK calls when possible. |
82 | | -3. Run `pnpm ark storage:link` only when links are required. |
83 | | -4. Ask before using `pnpm ark storage:link --force`. |
84 | | -5. Test upload, download, URL, and cleanup behavior without assuming a remote provider is available. |
| 127 | +## Add a Custom Console Command |
85 | 128 |
|
86 | | -## Add a Custom CLI Command |
| 129 | +Use this in full templates or projects that already have `src/app/console/commands`. |
87 | 130 |
|
88 | | -1. Generate the command with `pnpm ark make:command <Name>`. |
| 131 | +1. Generate the command with `ark make:command <Name>`. |
89 | 132 | 2. Edit the generated signature, description, and `handle` method. |
90 | 133 | 3. Keep command output concise and script-friendly. |
91 | | -4. Add tests when the command mutates files, invokes app services, or orchestrates database work. |
92 | | -5. Verify with `pnpm ark --help` or `pnpm ark <signature> --help`. |
93 | | - |
94 | | -## Update Documentation |
95 | | - |
96 | | -1. Edit VitePress pages under `docs`. |
97 | | -2. Add new guide pages to `docs/.vitepress/config.ts` when they should appear in navigation. |
98 | | -3. Use concise examples that match the current CLI and folder structure. |
99 | | -4. Run `pnpm docs:build` after sidebar, frontmatter, or markdown changes. |
100 | | - |
101 | | -## Upgrade or Refactor a Package |
102 | | - |
103 | | -1. Inspect package exports in the relevant `packages/*/package.json`. |
104 | | -2. Inspect local tests for the package. |
105 | | -3. Keep public exports backward-compatible unless a breaking change is requested. |
106 | | -4. Update package README files when public behavior changes. |
107 | | -5. Run package tests, then root tests or builds when shared contracts are touched. |
108 | | - |
109 | | -## Debug a Failing App |
110 | | - |
111 | | -1. Reproduce with the failing script or the smallest relevant test. |
112 | | -2. Check recent changes, route registration, environment variables, and generated build output paths. |
113 | | -3. Use `pnpm ark route:list` for HTTP routing issues. |
114 | | -4. Use migration history and model sync commands for database shape issues. |
115 | | -5. Fix the smallest layer that owns the behavior. |
116 | | -6. Re-run the failing command and one adjacent verification. |
117 | | - |
118 | | -## Keep Projects Agent-Friendly |
119 | | - |
120 | | -- Keep `package.json` scripts accurate and runnable. |
121 | | -- Keep generated Arkstack primitives in their conventional directories. |
| 134 | +4. Add tests when the command mutates files, invokes services, or orchestrates database work. |
| 135 | +5. Verify with `ark --help` or `ark <signature> --help`. |
| 136 | + |
| 137 | +## Debug a Failing Scaffolded App |
| 138 | + |
| 139 | +1. Reproduce the failure with the smallest local script, command, or test. |
| 140 | +2. Check `.env` and `.env.example` for missing values. |
| 141 | +3. Inspect route files and run `ark route:list` for routing issues. |
| 142 | +4. Inspect `src/core/bootstrap.ts` for setup issues. |
| 143 | +5. Inspect `src/config/middleware.ts` for request parsing, CORS, logging, or auth issues. |
| 144 | +6. For database issues, inspect `arkormx.config.ts`, migration files, and model files before running any migration command. |
| 145 | +7. Fix the smallest owning layer. |
| 146 | +8. Re-run the failing command and one adjacent verification. |
| 147 | + |
| 148 | +## Keep the Project Agent-Friendly |
| 149 | + |
| 150 | +- Keep `package.json` scripts accurate. |
| 151 | +- Keep `.env.example` current. |
| 152 | +- Keep generated Arkstack files in conventional directories. |
| 153 | +- Document custom route loading, custom stubs, or unusual bootstrap logic. |
122 | 154 | - Add tests near the behavior they verify. |
123 | | -- Document custom commands, non-standard stubs, and unusual environment requirements. |
124 | | -- Keep `.env.example` current when adding config. |
125 | | -- Avoid mixing runtime-specific logic into services or models. |
126 | | -- Prefer small, named services over large controller methods when behavior grows. |
| 155 | +- Keep runtime-specific logic near routes, middleware, driver setup, or bootstrap. |
| 156 | +- Move growing business logic out of route closures and controller methods. |
| 157 | +- Avoid committing generated output, local logs, credentials, or dependency folders. |
0 commit comments