Sfoglia il codice sorgente

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 giorni fa
parent
commit
1ad83ac3fb
7 ha cambiato i file con 68 aggiunte e 39 eliminazioni
  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 Vedi File

@@ -1,4 +1,11 @@
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 9
 APP_ENV=local
3 10
 APP_KEY=
4 11
 APP_DEBUG=true
@@ -20,12 +27,12 @@ LOG_STACK=single
20 27
 LOG_DEPRECATIONS_CHANNEL=null
21 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 37
 SESSION_DRIVER=database
31 38
 SESSION_LIFETIME=120
@@ -66,10 +73,12 @@ VITE_APP_NAME="${APP_NAME}"
66 73
 
67 74
 # AI. Each task picks its own provider and model. Change these lines to switch models; no code changes.
68 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 82
 ANTHROPIC_API_KEY=
74 83
 DEEPSEEK_API_KEY=
75 84
 

+ 2
- 1
.gitignore Vedi File

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

+ 10
- 9
PROGRESS.md Vedi File

@@ -5,7 +5,7 @@ Update it at the end of every work session.
5 5
 
6 6
 **Last updated:** 2026-11-14
7 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 10
 Status marks: `[ ]` not started · `[~]` in progress · `[x]` done
11 11
 
@@ -59,7 +59,7 @@ Changing from Claude to another AI model (or back) must be a settings change, no
59 59
 
60 60
 - All AI calls go through one place in the code (the "AI layer"). No other code talks to an AI provider directly.
61 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 63
     - `AI_GENERATE_PROVIDER=claude`, `AI_GENERATE_MODEL=claude-sonnet-5-5`
64 64
     - `AI_EDIT_PROVIDER=deepseek`, `AI_EDIT_MODEL=deepseek-chat`
65 65
 - Prompts and the store plan format are ours and do not depend on any provider.
@@ -76,8 +76,8 @@ Changing from Claude to another AI model (or back) must be a settings change, no
76 76
 
77 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 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 82
 - A full design: the AI gets our rules (built from `PlanSchema.php`) and the brand description, and answers with a store plan.
83 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,7 +129,7 @@ Changing from Claude to another AI model (or back) must be a settings change, no
129 129
 
130 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 133
 - [x] Test: switch the generation model in settings and confirm it works with no code change (automated test)
134 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 135
 - [x] DeepSeek for small edits (built; not yet run against the real service)
@@ -206,12 +206,13 @@ Then, from the project folder:
206 206
 | Check frontend                      | `npm run check` and `npm run types:check`  |
207 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 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 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 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 217
 ## 4b. Where things are in the code
217 218
 
@@ -239,7 +240,6 @@ Then, from the project folder:
239 240
 
240 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 243
 - Hosting provider (decide at Step 8)
244 244
 
245 245
 ## 6. Later improvements
@@ -263,3 +263,4 @@ Add one line per work session: date, what was done, what is next.
263 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 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 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 Vedi File

@@ -63,24 +63,27 @@ You need: PHP 8.3 or 8.4, Composer, Node 24 + npm, and MySQL.
63 63
 
64 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 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 75
     DB_USERNAME=your_mysql_user
81 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 87
 5. Install everything, create the tables and build the frontend:
85 88
 
86 89
     ```bash
@@ -95,7 +98,14 @@ You need: PHP 8.3 or 8.4, Composer, Node 24 + npm, and MySQL.
95 98
 
96 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 110
 ## Run the app
101 111
 
@@ -145,7 +155,7 @@ Changing from Claude to another AI model is a settings change, not a code rewrit
145 155
 
146 156
 - All AI calls go through one place in the code, the "AI layer".
147 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 161
     AI_GENERATE_PROVIDER=claude
@@ -162,7 +172,7 @@ Changing from Claude to another AI model is a settings change, not a code rewrit
162 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 176
 - AI work runs in the background, so the worker must be running. `composer run dev` starts it.
167 177
 - Settings are in `config/ai.php`. Plan limits are in `config/plans.php`.
168 178
 

+ 9
- 1
bootstrap/app.php Vedi File

@@ -8,7 +8,7 @@ use Illuminate\Foundation\Configuration\Middleware;
8 8
 use Illuminate\Http\Middleware\AddLinkHeadersForPreloadedAssets;
9 9
 use Illuminate\Http\Request;
10 10
 
11
-return Application::configure(basePath: dirname(__DIR__))
11
+$app = Application::configure(basePath: dirname(__DIR__))
12 12
     ->withRouting(
13 13
         web: __DIR__.'/../routes/web.php',
14 14
         commands: __DIR__.'/../routes/console.php',
@@ -28,3 +28,11 @@ return Application::configure(basePath: dirname(__DIR__))
28 28
             fn (Request $request) => $request->is('api/*') || $request->expectsJson(),
29 29
         );
30 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 Vedi File

@@ -44,7 +44,7 @@
44 44
     "scripts": {
45 45
         "setup": [
46 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 48
             "@php artisan key:generate",
49 49
             "@php artisan migrate --force",
50 50
             "npm install",

+ 5
- 5
config/ai.php Vedi File

@@ -25,15 +25,15 @@ return [
25 25
     'tasks' => [
26 26
         // Designing a whole store from the brand description.
27 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 30
             'max_tokens' => 16000,
31 31
         ],
32 32
 
33 33
         // Small changes asked for by chat ("make the banner darker").
34 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 37
             'max_tokens' => 6000,
38 38
         ],
39 39
     ],
@@ -49,7 +49,7 @@ return [
49 49
         'deepseek' => [
50 50
             'driver' => OpenAiCompatibleDriver::class,
51 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 53
             // The most this provider can write in one answer.
54 54
             'max_output_tokens' => 8000,
55 55
         ],

Loading…
Annulla
Salva