Stage 2: Context & Architecture
Master how to provide effective context to AI for better code
Why Context Mattersβ
AI coding assistants' performance depends entirely on the context you provide. This stage teaches you how to organize projects and prompts to maximize AI effectiveness.
This complete course from freeCodeCamp teaches you how to effectively use AI for programming. Learn how to provide the right context, structure prompts, and leverage AI tools to build real applications.
Watch on YouTubeLearning Outcomesβ
In this stage, you will:
- Design AI-friendly project architecture
- Provide effective context in prompts
- Understand RAG (Retrieval-Augmented Generation) techniques
- Organize code for better AI comprehension
- Make good use of documentation and examples
Three Levels of Contextβ
1. Immediate Contextβ
Information provided directly in the current conversation
Good immediate context example:
"I'm developing a Python script to process Excel files.
Current code:
[paste code]
Problem: Getting error 'KeyError: Department' when running
Excel file columns: Name, Department Name, Hire Date
Please help me fix this issue."
2. Project Contextβ
Project structure, tech stack, existing code
Project structure example:
my-automation/
βββ scripts/
β βββ excel_processor.py
β βββ email_sender.py
βββ data/
β βββ employees.xlsx
βββ config.yaml
βββ README.md
Tell AI:
"This is a Python automation project using pandas for data processing,
configuration is in config.yaml, please follow the existing code style..."
3. Domain Contextβ
Business rules, industry terminology, specific constraints
Domain context example:
"Our company's business rules:
- Employees are divided into A/B/C levels
- Level A employees get 15 days annual leave, B gets 10 days, C gets 7 days
- Less than one year of employment is calculated proportionally
- Attendance must be submitted before the 25th of each month
Please help me write an annual leave calculation function based on these rules."
Tips for Providing Contextβ
Tip 1: Give AI a Roleβ
"You are an experienced Python developer focused on data processing and office automation.
Your coding style emphasizes readability and simplicity, preferring pandas and openpyxl.
Please help me..."
Tip 2: Provide Examplesβ
Input example:
| Name | Region | Sales |
|------|--------|-------|
| John | East | 50000 |
| Jane | South | 30000 |
Expected output:
| Region | Total Sales | Count | Average Sales |
|--------|-------------|-------|---------------|
| East | 50000 | 1 | 50000 |
| South | 30000 | 1 | 30000 |
Tip 3: Request in Stepsβ
Don't:
"Help me write a complete report generation system"
Do this instead:
"Step 1: First help me write a function to read Excel
Step 2: Then write a data cleaning function
Step 3: Finally write a summary statistics function"
Tip 4: Specify Constraintsβ
Constraint example:
"Please help me write a data export script with these requirements:
- Python 3.8 compatible
- Cannot use third-party libraries (standard library only)
- Memory usage under 100MB
- Processing time under 5 minutes
- Support for interrupt recovery"
Project Architecture Best Practicesβ
Clear File Structureβ
Recommended project structure:
office-automation/
βββ README.md # Project description (AI reads first)
βββ requirements.txt # Dependency list
βββ config/
β βββ settings.yaml # Configuration file
βββ src/
β βββ __init__.py
β βββ excel_handler.py # Excel processing
β βββ email_sender.py # Email sending
β βββ report_generator.py # Report generation
βββ templates/
β βββ email_template.html
βββ tests/
β βββ test_excel_handler.py
βββ data/
βββ .gitkeep
Meaningful Namingβ
# Bad naming
def process(d):
return d['a'] + d['b']
# Good naming
def calculate_total_sales(sales_record):
"""Calculate total sales for a sales record"""
return sales_record['base_sales'] + sales_record['bonus_sales']
Self-Documenting Codeβ
# Good docstrings help AI understand code intent
def generate_monthly_report(
data_file: str,
output_path: str,
month: int,
include_charts: bool = True
) -> str:
"""
Generate monthly sales report
Args:
data_file: Input Excel file path
output_path: Output directory
month: Report month (1-12)
include_charts: Whether to include charts
Returns:
Path to generated report file
Example:
>>> generate_monthly_report('sales.xlsx', './reports', 12)
'./reports/2025-12-report.xlsx'
"""
pass
Recommended Resourcesβ
Prompt Engineering Guidesβ
-
Anthropic's Prompt Engineering Guide
- Why recommended: Comprehensive guide on effective prompting techniques from Claude's creators
-
- Why recommended: Practical patterns for structured prompting in production applications
-
OpenAI Cookbook: Code Generation
- Why recommended: Real-world examples and best practices for code generation
Context & Architectureβ
-
Anthropic: Long Context Window Best Practices
- Why recommended: Techniques for effectively using long context windows for entire codebases
-
- Why recommended: Curated list of tools, patterns, and best practices for AI-assisted development
-
Cursor Composer: Multi-File Editing Patterns
- Why recommended: Official guide on organizing projects for multi-file AI editing
Advanced Techniquesβ
- RAG for Code: Retrieval-Augmented Generation
- Why recommended: Techniques for providing relevant context from large codebases
Practical Templatesβ
Task Request Templateβ
## Task Description
[Clearly describe what you want to achieve]
## Background Information
- Project type: [e.g., Python office automation]
- Tech stack: [e.g., pandas, openpyxl]
- Environment: [e.g., Windows 10, Python 3.9]
## Input Data
[Provide sample data or data structure description]
## Expected Output
[Describe the desired result format]
## Constraints
[List any limitations or requirements]
## Existing Code
[Paste relevant code here if any]
README Templateβ
# Project Name
## Overview
[One-sentence description of what the project does]
## Features
- Feature 1
- Feature 2
## Tech Stack
- Python 3.9+
- pandas, openpyxl
## Installation
\`\`\`bash
pip install -r requirements.txt
\`\`\`
## Usage
\`\`\`bash
python main.py --input data.xlsx --output report.xlsx
\`\`\`
## Configuration
Edit config.yaml to set parameters
## File Structure
[Brief description of main files]
Next Stepsβ
Congratulations! You've completed the three stages of the foundational learning path:
- β Stage 0: Mastered AI conversation and prompt fundamentals
- β Stage 1: Understood AI's reality and limitations
- β Stage 2: Learned to provide effective context
Continue Learningβ
- Explore AI Coding Tools - Discover powerful AI coding assistants
- Check out Prompt Engineering - Master the art of prompting
- Browse our Course - Deep-dive into AI coding fundamentals
Need help? Check out our Quick Start or Resources!