瀏覽代碼

Split settings into a shared .env and a private .env.local

.env is now tracked and holds only basic, non-secret settings; secrets
and all AI settings are blank. .env.local is ignored, holds everything
needed to run, and is loaded instead of .env when it exists.
Removes .env.example.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
feature/ai-generation
fahmisaad 6 天之前
父節點
當前提交
1ad83ac3fb
共有 7 個文件被更改,包括 68 次插入 和 39 次删除
  1. 20
    11
      .env
  2. 2
    1
      .gitignore
  3. 10
    9
      PROGRESS.md
  4. 21
    11
      README.md
  5. 9
    1
      bootstrap/app.php
  6. 1
    1
      composer.json
  7. 5
    5
      config/ai.php

.env.example → .env 查看文件

1
-APP_NAME=Laravel
1
+# This file IS uploaded to the repository. It holds basic, non-secret settings only.
2
+# Secret values (app key, passwords, API keys) and all AI settings are left blank here.
3
+#
4
+# For development, the app reads .env.local instead of this file when it exists.
5
+# .env.local is never uploaded and must hold every setting, including the secrets.
6
+# To create it: copy this file to .env.local, then fill in the blanks.
7
+
8
+APP_NAME="AI Commerce"
2
 APP_ENV=local
9
 APP_ENV=local
3
 APP_KEY=
10
 APP_KEY=
4
 APP_DEBUG=true
11
 APP_DEBUG=true
20
 LOG_DEPRECATIONS_CHANNEL=null
27
 LOG_DEPRECATIONS_CHANNEL=null
21
 LOG_LEVEL=debug
28
 LOG_LEVEL=debug
22
 
29
 
23
-DB_CONNECTION=sqlite
24
-# DB_HOST=127.0.0.1
25
-# DB_PORT=3306
26
-# DB_DATABASE=laravel
27
-# DB_USERNAME=root
28
-# DB_PASSWORD=
30
+DB_CONNECTION=mysql
31
+DB_HOST=127.0.0.1
32
+DB_PORT=3306
33
+DB_DATABASE=ai_commerce
34
+DB_USERNAME=root
35
+DB_PASSWORD=
29
 
36
 
30
 SESSION_DRIVER=database
37
 SESSION_DRIVER=database
31
 SESSION_LIFETIME=120
38
 SESSION_LIFETIME=120
66
 
73
 
67
 # AI. Each task picks its own provider and model. Change these lines to switch models; no code changes.
74
 # AI. Each task picks its own provider and model. Change these lines to switch models; no code changes.
68
 # Providers: claude, deepseek, fake (no API key needed, returns a sample design).
75
 # Providers: claude, deepseek, fake (no API key needed, returns a sample design).
69
-AI_GENERATE_PROVIDER=claude
70
-AI_GENERATE_MODEL=claude-sonnet-5-5
71
-AI_EDIT_PROVIDER=deepseek
72
-AI_EDIT_MODEL=deepseek-chat
76
+# Set these in .env.local, never here. This file is uploaded to the repository.
77
+AI_GENERATE_PROVIDER=
78
+AI_GENERATE_MODEL=
79
+AI_EDIT_PROVIDER=
80
+AI_EDIT_MODEL=
81
+AI_FAKE_DELAY=
73
 ANTHROPIC_API_KEY=
82
 ANTHROPIC_API_KEY=
74
 DEEPSEEK_API_KEY=
83
 DEEPSEEK_API_KEY=
75
 
84
 

+ 2
- 1
.gitignore 查看文件

12
 /resources/js/wayfinder
12
 /resources/js/wayfinder
13
 /vendor
13
 /vendor
14
 .DS_Store
14
 .DS_Store
15
-.env
15
+.env.local
16
+.env.*.local
16
 .env.backup
17
 .env.backup
17
 .env.production
18
 .env.production
18
 .phpactor.json
19
 .phpactor.json

+ 10
- 9
PROGRESS.md 查看文件

5
 
5
 
6
 **Last updated:** 2026-11-14
6
 **Last updated:** 2026-11-14
7
 **Current step:** Step 3 — AI generation (built; waiting for a real test with API keys)
7
 **Current step:** Step 3 — AI generation (built; waiting for a real test with API keys)
8
-**Next action:** Add the Anthropic and DeepSeek API keys to `.env`, switch the two providers from `fake` to `claude` and `deepseek`, and test a real generation and a real edit. Then start Step 4
8
+**Next action:** In `.env.local` (keys are already added), switch the two providers from `fake` to `claude` and `deepseek`, and test a real generation and a real edit. Then start Step 4
9
 
9
 
10
 Status marks: `[ ]` not started · `[~]` in progress · `[x]` done
10
 Status marks: `[ ]` not started · `[~]` in progress · `[x]` done
11
 
11
 
59
 
59
 
60
 - All AI calls go through one place in the code (the "AI layer"). No other code talks to an AI provider directly.
60
 - All AI calls go through one place in the code (the "AI layer"). No other code talks to an AI provider directly.
61
 - Each provider (Claude, DeepSeek, others later) is one small "driver" class behind the same interface.
61
 - Each provider (Claude, DeepSeek, others later) is one small "driver" class behind the same interface.
62
-- Each task has its own setting in `.env`: which provider and which model. Example:
62
+- Each task has its own setting in `.env.local`: which provider and which model. Example:
63
     - `AI_GENERATE_PROVIDER=claude`, `AI_GENERATE_MODEL=claude-sonnet-5-5`
63
     - `AI_GENERATE_PROVIDER=claude`, `AI_GENERATE_MODEL=claude-sonnet-5-5`
64
     - `AI_EDIT_PROVIDER=deepseek`, `AI_EDIT_MODEL=deepseek-chat`
64
     - `AI_EDIT_PROVIDER=deepseek`, `AI_EDIT_MODEL=deepseek-chat`
65
 - Prompts and the store plan format are ours and do not depend on any provider.
65
 - Prompts and the store plan format are ours and do not depend on any provider.
76
 
76
 
77
 ### How AI generation works (added in Step 3)
77
 ### How AI generation works (added in Step 3)
78
 
78
 
79
-- All AI calls go through `AiManager`. It reads `config/ai.php`, which reads `.env`.
80
-- Three providers exist: `claude`, `deepseek`, and `fake`. The `fake` one needs no key and costs nothing: it returns the built-in sample design. Local `.env` uses `fake` until the real keys are added.
79
+- All AI calls go through `AiManager`. It reads `config/ai.php`, which reads `.env.local`.
80
+- Three providers exist: `claude`, `deepseek`, and `fake`. The `fake` one needs no key and costs nothing: it returns the built-in sample design. `.env.local` uses `fake` until the real test.
81
 - The DeepSeek driver speaks a common format that many providers share, so most new providers need only a few lines in `config/ai.php`.
81
 - The DeepSeek driver speaks a common format that many providers share, so most new providers need only a few lines in `config/ai.php`.
82
 - A full design: the AI gets our rules (built from `PlanSchema.php`) and the brand description, and answers with a store plan.
82
 - A full design: the AI gets our rules (built from `PlanSchema.php`) and the brand description, and answers with a store plan.
83
 - A chat edit: the AI gets the current plan and the request, and answers with only what to change. We apply that to the plan.
83
 - A chat edit: the AI gets the current plan and the request, and answers with only what to change. We apply that to the plan.
129
 
129
 
130
 ### Step 3 — AI generation
130
 ### Step 3 — AI generation
131
 
131
 
132
-- [x] Swappable AI layer: one interface, one driver per provider, provider and model chosen per task in `.env`
132
+- [x] Swappable AI layer: one interface, one driver per provider, provider and model chosen per task in the settings file
133
 - [x] Test: switch the generation model in settings and confirm it works with no code change (automated test)
133
 - [x] Test: switch the generation model in settings and confirm it works with no code change (automated test)
134
 - [x] Claude Sonnet 5.5 for first store generation (built with Anthropic's official PHP package; not yet run against the real service)
134
 - [x] Claude Sonnet 5.5 for first store generation (built with Anthropic's official PHP package; not yet run against the real service)
135
 - [x] DeepSeek for small edits (built; not yet run against the real service)
135
 - [x] DeepSeek for small edits (built; not yet run against the real service)
206
 | Check frontend                      | `npm run check` and `npm run types:check`  |
206
 | Check frontend                      | `npm run check` and `npm run types:check`  |
207
 | Rebuild frontend for tests          | `npm run build`                            |
207
 | Rebuild frontend for tests          | `npm run build`                            |
208
 
208
 
209
-- Database: MySQL, database `ai_commerce`, settings in `.env`.
209
+- Settings files: `.env` is uploaded to the repository and holds only basic, non-secret settings (secrets and all AI settings are blank). `.env.local` is never uploaded and holds everything needed to run, including keys. When `.env.local` exists the app reads it instead of `.env`, so it must be complete. This is set up in `bootstrap/app.php`.
210
+- Database: MySQL, database `ai_commerce`, settings in `.env.local`.
210
 - Local test login: created by `php artisan db:seed`. Email is in `database/seeders/DatabaseSeeder.php`, password in `database/factories/UserFactory.php`.
211
 - Local test login: created by `php artisan db:seed`. Email is in `database/seeders/DatabaseSeeder.php`, password in `database/factories/UserFactory.php`.
211
-- AI: local `.env` uses the `fake` provider. To use real AI, set `AI_GENERATE_PROVIDER=claude` and `AI_EDIT_PROVIDER=deepseek`, and fill in `ANTHROPIC_API_KEY` and `DEEPSEEK_API_KEY`.
212
+- AI: `.env.local` currently uses the `fake` provider. To use real AI, set `AI_GENERATE_PROVIDER=claude` and `AI_EDIT_PROVIDER=deepseek`, and fill in `ANTHROPIC_API_KEY` and `DEEPSEEK_API_KEY`.
212
 - AI jobs need the background worker. `composer run dev` starts it. Without it, a job waits and is marked failed after 10 minutes.
213
 - AI jobs need the background worker. `composer run dev` starts it. Without it, a job waits and is marked failed after 10 minutes.
213
 - Emails (such as verification links) are written to `storage/logs/laravel.log`, not sent.
214
 - Emails (such as verification links) are written to `storage/logs/laravel.log`, not sent.
214
-- Code repository: `https://git.mirfalah.my/mirfalah-tech/ai_commerce.git` (remote name `origin`). The `.env` file is never uploaded.
215
+- Code repository: `https://git.mirfalah.my/mirfalah-tech/ai_commerce.git` (remote name `origin`). The `.env.local` file is never uploaded.
215
 
216
 
216
 ## 4b. Where things are in the code
217
 ## 4b. Where things are in the code
217
 
218
 
239
 
240
 
240
 ## 5. Open questions
241
 ## 5. Open questions
241
 
242
 
242
-- Anthropic API key and DeepSeek API key: needed in `.env` for the real test of Step 3
243
 - Hosting provider (decide at Step 8)
243
 - Hosting provider (decide at Step 8)
244
 
244
 
245
 ## 6. Later improvements
245
 ## 6. Later improvements
263
 | 2026-11-14 | Step 2 done on branch `feature/store-sections-renderer`: store plan format and validator, 10 sections with 2 variants each, renderer, dashboard preview, sample design. 69 tests pass; storefront checked in the browser on desktop and mobile.                                                         | Step 3: swappable AI layer and store generation                 |
263
 | 2026-11-14 | Step 2 done on branch `feature/store-sections-renderer`: store plan format and validator, 10 sections with 2 variants each, renderer, dashboard preview, sample design. 69 tests pass; storefront checked in the browser on desktop and mobile.                                                         | Step 3: swappable AI layer and store generation                 |
264
 | 2026-11-14 | First commit made and pushed to the private repository on git.mirfalah.my (branch `feature/store-sections-renderer`).                                                                                                                                                                                   | Step 3: swappable AI layer and store generation                 |
264
 | 2026-11-14 | First commit made and pushed to the private repository on git.mirfalah.my (branch `feature/store-sections-renderer`).                                                                                                                                                                                   | Step 3: swappable AI layer and store generation                 |
265
 | 2026-11-14 | Step 3 built on branch `feature/ai-generation`: swappable AI layer (Claude, DeepSeek, fake), full store generation, chat edits, background job with progress screen, plan limits. 92 tests pass; whole flow checked in the browser with the fake provider. Not yet run against real Claude or DeepSeek. | Add API keys, run the real test, then Step 4                    |
265
 | 2026-11-14 | Step 3 built on branch `feature/ai-generation`: swappable AI layer (Claude, DeepSeek, fake), full store generation, chat edits, background job with progress screen, plan limits. 92 tests pass; whole flow checked in the browser with the fake provider. Not yet run against real Claude or DeepSeek. | Add API keys, run the real test, then Step 4                    |
266
+| 2026-11-14 | Split settings into `.env` (uploaded, no secrets, AI settings blank) and `.env.local` (private, complete). Removed `.env.example`.                                                                                                                                                                      | Real AI test, then Step 4                                       |

+ 21
- 11
README.md 查看文件

63
 
63
 
64
 2. Create an empty MySQL database named `ai_commerce`.
64
 2. Create an empty MySQL database named `ai_commerce`.
65
 
65
 
66
-3. Inside the project folder, copy the example settings file:
66
+3. Inside the project folder, create your private settings file from the shared one:
67
 
67
 
68
     ```bash
68
     ```bash
69
-    cp .env.example .env
69
+    cp .env .env.local
70
     ```
70
     ```
71
 
71
 
72
-4. Open `.env` and set the database lines (the example file uses SQLite by default):
72
+4. Open `.env.local` and fill in the blanks. At least the database user and password, and the AI lines:
73
 
73
 
74
     ```
74
     ```
75
-    APP_NAME="AI Commerce"
76
-    DB_CONNECTION=mysql
77
-    DB_HOST=127.0.0.1
78
-    DB_PORT=3306
79
-    DB_DATABASE=ai_commerce
80
     DB_USERNAME=your_mysql_user
75
     DB_USERNAME=your_mysql_user
81
     DB_PASSWORD=your_mysql_password
76
     DB_PASSWORD=your_mysql_password
77
+    AI_GENERATE_PROVIDER=fake
78
+    AI_GENERATE_MODEL=claude-sonnet-5-5
79
+    AI_EDIT_PROVIDER=fake
80
+    AI_EDIT_MODEL=deepseek-chat
81
+    ANTHROPIC_API_KEY=
82
+    DEEPSEEK_API_KEY=
82
     ```
83
     ```
83
 
84
 
85
+    Use `fake` to work without API keys. Use `claude` and `deepseek`, with the two keys filled in, for real AI. The app key (`APP_KEY`) is created for you in the next step.
86
+
84
 5. Install everything, create the tables and build the frontend:
87
 5. Install everything, create the tables and build the frontend:
85
 
88
 
86
     ```bash
89
     ```bash
95
 
98
 
96
     The email is in `database/seeders/DatabaseSeeder.php` and the password is in `database/factories/UserFactory.php`.
99
     The email is in `database/seeders/DatabaseSeeder.php` and the password is in `database/factories/UserFactory.php`.
97
 
100
 
98
-The `.env` file holds passwords and API keys. It is never uploaded to the repository, so each machine needs its own.
101
+### The two settings files
102
+
103
+| File         | Uploaded to the repository? | What it holds                                                           |
104
+| ------------ | --------------------------- | ----------------------------------------------------------------------- |
105
+| `.env`       | Yes                         | Basic, non-secret settings. Secrets and all AI settings are blank       |
106
+| `.env.local` | No, never                   | Everything needed to run, including the app key, passwords and API keys |
107
+
108
+When `.env.local` exists, the app reads it **instead of** `.env` (it does not combine the two). So `.env.local` must hold every setting. Never put a real key or password in `.env`.
99
 
109
 
100
 ## Run the app
110
 ## Run the app
101
 
111
 
145
 
155
 
146
 - All AI calls go through one place in the code, the "AI layer".
156
 - All AI calls go through one place in the code, the "AI layer".
147
 - Each provider (Claude, DeepSeek, others later) is one small driver class.
157
 - Each provider (Claude, DeepSeek, others later) is one small driver class.
148
-- Each task picks its provider and model in `.env`:
158
+- Each task picks its provider and model in `.env.local`:
149
 
159
 
150
     ```
160
     ```
151
     AI_GENERATE_PROVIDER=claude
161
     AI_GENERATE_PROVIDER=claude
162
     AI_EDIT_PROVIDER=fake
172
     AI_EDIT_PROVIDER=fake
163
     ```
173
     ```
164
 
174
 
165
-- API keys go in `.env` as `ANTHROPIC_API_KEY` and `DEEPSEEK_API_KEY`.
175
+- API keys go in `.env.local` as `ANTHROPIC_API_KEY` and `DEEPSEEK_API_KEY`. Never in `.env`.
166
 - AI work runs in the background, so the worker must be running. `composer run dev` starts it.
176
 - AI work runs in the background, so the worker must be running. `composer run dev` starts it.
167
 - Settings are in `config/ai.php`. Plan limits are in `config/plans.php`.
177
 - Settings are in `config/ai.php`. Plan limits are in `config/plans.php`.
168
 
178
 

+ 9
- 1
bootstrap/app.php 查看文件

8
 use Illuminate\Http\Middleware\AddLinkHeadersForPreloadedAssets;
8
 use Illuminate\Http\Middleware\AddLinkHeadersForPreloadedAssets;
9
 use Illuminate\Http\Request;
9
 use Illuminate\Http\Request;
10
 
10
 
11
-return Application::configure(basePath: dirname(__DIR__))
11
+$app = Application::configure(basePath: dirname(__DIR__))
12
     ->withRouting(
12
     ->withRouting(
13
         web: __DIR__.'/../routes/web.php',
13
         web: __DIR__.'/../routes/web.php',
14
         commands: __DIR__.'/../routes/console.php',
14
         commands: __DIR__.'/../routes/console.php',
28
             fn (Request $request) => $request->is('api/*') || $request->expectsJson(),
28
             fn (Request $request) => $request->is('api/*') || $request->expectsJson(),
29
         );
29
         );
30
     })->create();
30
     })->create();
31
+
32
+// Development settings live in .env.local (never uploaded to the repository).
33
+// When that file exists it is used instead of .env, which holds only basic, non-secret settings.
34
+if (is_file($app->environmentPath().'/.env.local')) {
35
+    $app->loadEnvironmentFrom('.env.local');
36
+}
37
+
38
+return $app;

+ 1
- 1
composer.json 查看文件

44
     "scripts": {
44
     "scripts": {
45
         "setup": [
45
         "setup": [
46
             "composer install",
46
             "composer install",
47
-            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\"",
47
+            "@php -r \"file_exists('.env.local') || copy('.env', '.env.local');\"",
48
             "@php artisan key:generate",
48
             "@php artisan key:generate",
49
             "@php artisan migrate --force",
49
             "@php artisan migrate --force",
50
             "npm install",
50
             "npm install",

+ 5
- 5
config/ai.php 查看文件

25
     'tasks' => [
25
     'tasks' => [
26
         // Designing a whole store from the brand description.
26
         // Designing a whole store from the brand description.
27
         'generate' => [
27
         'generate' => [
28
-            'provider' => env('AI_GENERATE_PROVIDER', 'claude'),
29
-            'model' => env('AI_GENERATE_MODEL', 'claude-sonnet-5-5'),
28
+            'provider' => env('AI_GENERATE_PROVIDER') ?: 'claude',
29
+            'model' => env('AI_GENERATE_MODEL') ?: 'claude-sonnet-5-5',
30
             'max_tokens' => 16000,
30
             'max_tokens' => 16000,
31
         ],
31
         ],
32
 
32
 
33
         // Small changes asked for by chat ("make the banner darker").
33
         // Small changes asked for by chat ("make the banner darker").
34
         'edit' => [
34
         'edit' => [
35
-            'provider' => env('AI_EDIT_PROVIDER', 'deepseek'),
36
-            'model' => env('AI_EDIT_MODEL', 'deepseek-chat'),
35
+            'provider' => env('AI_EDIT_PROVIDER') ?: 'deepseek',
36
+            'model' => env('AI_EDIT_MODEL') ?: 'deepseek-chat',
37
             'max_tokens' => 6000,
37
             'max_tokens' => 6000,
38
         ],
38
         ],
39
     ],
39
     ],
49
         'deepseek' => [
49
         'deepseek' => [
50
             'driver' => OpenAiCompatibleDriver::class,
50
             'driver' => OpenAiCompatibleDriver::class,
51
             'api_key' => env('DEEPSEEK_API_KEY'),
51
             'api_key' => env('DEEPSEEK_API_KEY'),
52
-            'base_url' => env('DEEPSEEK_BASE_URL', 'https://api.deepseek.com'),
52
+            'base_url' => env('DEEPSEEK_BASE_URL') ?: 'https://api.deepseek.com',
53
             // The most this provider can write in one answer.
53
             // The most this provider can write in one answer.
54
             'max_output_tokens' => 8000,
54
             'max_output_tokens' => 8000,
55
         ],
55
         ],

Loading…
取消
儲存