Skip to main content

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 YouTube

Learning 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

Prompt Engineering Guides​

  1. Anthropic's Prompt Engineering Guide

    • Why recommended: Comprehensive guide on effective prompting techniques from Claude's creators
  2. LangChain Prompt Engineering

    • Why recommended: Practical patterns for structured prompting in production applications
  3. OpenAI Cookbook: Code Generation

    • Why recommended: Real-world examples and best practices for code generation

Context & Architecture​

  1. Anthropic: Long Context Window Best Practices

    • Why recommended: Techniques for effectively using long context windows for entire codebases
  2. GitHub: Awesome AI Coding

    • Why recommended: Curated list of tools, patterns, and best practices for AI-assisted development
  3. Cursor Composer: Multi-File Editing Patterns

    • Why recommended: Official guide on organizing projects for multi-file AI editing

Advanced Techniques​

  1. 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​


Need help? Check out our Quick Start or Resources!