Goal
Create a minimal working web interface that demonstrates successful communication with an AI provider API. This stage proves your hosting environment is configured correctly, your API key works, and the fundamental request/response cycle functions as expected.
By the end of this stage, you'll have a simple chat interface where you can type a message and receive a response from the AI. No conversation storage, no configuration files, no advanced features—just the core connection working reliably.
This foundation is critical. Everything else builds on this basic cycle.
Before You Begin
Pre-flight checklist:
-
Read all documentation in the
docs/folder (especiallyarchitecture.mdandtesting.md) -
Create a TODO list for tracking implementation progress through all
build stages (store in
docs/TODO.mdor your preferred location)
Components to Build
1. HTML Chat Interface
A web page with a message input field, a send button, and an area to display the conversation. This is the user-facing interface where messages are typed and AI responses appear.
Why it exists: Provides the basic UI for interaction. Doesn't need to be polished yet—focus on functionality.
2. Client-Side JavaScript
Code that captures user input, sends it to your API proxy, receives the response, and displays it in the interface.
Why it exists: Handles the browser-side logic. Manages the conversation flow and updates the UI with responses.
3. API Proxy (Server-Side PHP)
A PHP component that receives requests from your client JavaScript, forwards them to the AI provider's API with your API key, and returns the response.
Why it exists: Keeps your API key secure (never exposed to the browser). Centralizes the connection to the AI provider. This is a critical security boundary.
4. System Instruction (Hardcoded)
A basic system instruction that shapes the AI's behavior. For Stage 1, this will be hardcoded directly in your API proxy. Something simple like "You are a helpful assistant" is sufficient—the goal is to prove the instruction mechanism works, not to perfect the pedagogical approach yet. Ask the user if they want a more substantial system instruction at this stage.
Why it exists: Even at this early stage, the AI needs some instruction on how to behave. This will become configurable and modular in later stages, but for now, a simple hardcoded instruction proves the concept.
Implementation Tasks
Use the following tasks as a guide. Create your own TODO list and track progress as you work.
Environment Setup
- Ensure PHP is available and functioning on your hosting environment
- Verify your AI provider API key is stored in an environment variable (not in code)
-
Confirm you can access environment variables from PHP using
getenv()
Build the HTML Interface
- Create an HTML page with a message input field and send button
- Include a display area for conversation messages
- Add basic styling so the interface is usable (doesn't need to be beautiful)
Build Client-Side JavaScript
- Capture user message when send button is clicked
- Send the message to your API proxy via HTTP request
- Receive the response from the proxy
- Display both the user message and AI response in the conversation area
- Handle loading states (show user that request is in progress)
- Handle basic errors (show user if something goes wrong)
Build the API Proxy
- Create a PHP endpoint that receives requests from the client
- Retrieve the AI provider API key from environment variable
- Format the request according to your AI provider's API specification
- Include the hardcoded system instruction in the request
- Send the request to the AI provider API
- Receive and parse the response
- Return the AI's response to the client
- Include basic error handling (catch failed API requests and return meaningful errors)
Add the System Instruction
- Create a simple system instruction (e.g., "You are a helpful assistant") or use one provided by the user
- Hardcode it in your API proxy for now
Test the Complete Flow
- Send a test message through the interface
- Verify the response appears correctly
- Test with different message types to confirm consistent behavior
- Verify error messages appear if the API is unreachable
Success Indicators
When Stage 1 is complete, you should observe these behaviors:
Basic Functionality
- ✓ You can type a message in the input field and click send
- ✓ The AI provider returns a response that appears in the conversation area
- ✓ Both user messages and AI responses are clearly distinguishable
- ✓ The interface shows a loading indicator while waiting for the response
System Instruction Working
- ✓ The AI responds in an appropriate manner (based on your hardcoded instruction)
- ✓ The AI's behavior reflects the guidance you provided in the system instruction
Error Handling
- ✓ If you intentionally break the API connection (wrong endpoint, invalid key), you see an error message instead of a broken interface
- ✓ Errors are displayed to the user in a clear, understandable way
Technical Validation
- ✓ Your API key is never visible in browser developer tools or page source
- ✓ The API proxy successfully retrieves the key from the environment variable
- ✓ Network requests in browser developer tools show communication between client and your proxy (not directly to the AI provider)
Testing and Verification
Before proceeding to Stage 2:
- Test the happy path: Send several different messages and verify appropriate responses
- Test error conditions: Temporarily break your API key or endpoint and verify errors are handled gracefully
- Verify security: Check browser developer tools to confirm your API key is never exposed
- Review your code: Ensure you understand what each component does and why it exists
Consult testing.md for additional verification strategies
and troubleshooting guidance.
What You've Accomplished
With Stage 1 complete, you have:
- Proven your hosting environment works for this type of application
- Secured your API key server-side (critical security practice)
- Established the basic request/response cycle that everything else builds on
- Created a working foundation for conversation storage and configuration
You've built something functional, tested it, and understand how it works. This is the hardest part—everything from here adds features to a working system.
STOP: Before Proceeding to Stage 2
Do not move forward until:
- ✓ You can reliably send messages and receive appropriate AI responses
- ✓ You understand what each component does and why it exists
- ✓ You've verified your API key is secure and never exposed to the browser
- ✓ Error conditions are handled gracefully
- ✓ You've tested the system according to the success indicators above
When Stage 1 is working completely:
- Update your TODO list - mark Stage 1 tasks complete, add any notes or learnings
- Create a git commit with your working Stage 1 code
- Update any other contextual documents you're maintaining (notes, decisions, etc.)
- Proceed to
stage-2-context.md