{"slug": "i-built-contextforge-with-gemma-4-a-project-memory-generator-for-developers-and", "title": "I Built ContextForge with Gemma 4: A Project Memory Generator for Developers and AI Coding Agents", "summary": "ContextForge is a developer tool that uses Google's Gemma 4 model (via the Gemini API) to automatically scan a codebase and generate AI-ready project documentation, including files like README.md, SETUP.md, ARCHITECTURE.md, and a specialized AGENT.md for preserving context across AI coding sessions. The tool accepts a ZIP upload or built-in sample project, processes files through a FastAPI backend and React frontend, and produces structured documentation designed to help both human developers and AI coding agents understand a project without needing to rediscover it from scratch. The project is available on GitHub and can be run locally using Docker Compose, with a mock mode available for testing without a Gemini API key.", "body_md": "*This is a submission for the Gemma 4 Challenge: Build with Gemma 4.*\n\n## What I Built\n\nContextForge is a developer tool that scans a codebase and generates practical, AI-ready project documentation using Gemma 4 through the Gemini API.\n\nThe goal is simple: when a developer or AI coding agent opens a project, they should not have to rediscover the whole repository from scratch. ContextForge generates `README.md`\n\n, `SETUP.md`\n\n, `ARCHITECTURE.md`\n\n, and especially `AGENT.md`\n\n, a durable handoff file designed for future AI coding sessions.\n\n## The problem: AI coding agents lose context\n\nAI coding agents are useful, but their context is fragile.\n\nWhen a chat is cleared, a session expires, or a different agent starts working on the same repository, a lot of hard-won project understanding disappears:\n\n- what framework the app uses\n- which files matter most\n- how to run the project locally\n- what generated folders should be ignored\n- what assumptions are still uncertain\n- what safety rules an agent should follow before editing\n\nTraditional README files help humans, but they are not always enough for AI agents. Agents need a project map, editing constraints, validation steps, and warnings about risky areas.\n\nThat is why ContextForge focuses on `AGENT.md`\n\n.\n\n## What ContextForge does\n\nContextForge takes a ZIP upload or a built-in sample project and generates documentation from the actual files in the codebase.\n\nThe MVP can:\n\n- upload a ZIP file\n- load a built-in Django sample project\n- safely extract and scan files\n- ignore folders like\n`.git`\n\n,`node_modules`\n\n,`.venv`\n\n,`dist`\n\n,`build`\n\n,`.next`\n\n, and`coverage`\n\n- detect the tech stack\n- build a structured prompt for Gemma 4\n- generate:\n`README.md`\n\n`AGENT.md`\n\n`SETUP.md`\n\n`ARCHITECTURE.md`\n\n- display generated docs in tabs\n- copy each generated document\n- download all generated docs as a ZIP\n\nThe output is meant to be practical rather than marketing-heavy. If ContextForge is unsure about something, the prompt asks the model to mark that uncertainty instead of inventing details.\n\n## Demo\n\nThe project is available on GitHub and can be run locally with Docker Compose:\n\n```\ngit clone https://github.com/bryko254/contextforge.git\ncd contextforge\ncp backend/.env.example backend/.env\ncp frontend/.env.example frontend/.env\ndocker compose up --build\n```\n\nThen open `http://localhost:5173`\n\n.\n\nThe judge-friendly demo flow is:\n\n- Open the ContextForge frontend.\n- Click\n**Try sample project**. - The backend scans the built-in Django task API sample.\n- ContextForge detects Python, Django, PostgreSQL, Docker, and pip.\n- The app asks Gemma 4 to generate docs.\n- The UI displays:\n`README.md`\n\n`AGENT.md`\n\n`SETUP.md`\n\n`ARCHITECTURE.md`\n\n- Open\n`AGENT.md`\n\nand show the AI-agent-focused project handoff. - Copy a generated document.\n- Download all docs as a ZIP.\n- Optionally upload a small ZIP project and run the same flow.\n\nThe app also supports mock mode, so the UI can be tested without a Gemini API key. For judging the real AI flow, run with `USE_MOCK_AI=false`\n\nand provide `GEMINI_API_KEY`\n\n.\n\n## Code\n\nRepository: [https://github.com/bryko254/contextforge](https://github.com/bryko254/contextforge)\n\nThe project is structured as a small full-stack app:\n\n-\n`backend/`\n\n: FastAPI API, ZIP handling, scanning, stack detection, prompt construction, and Gemma API client. -\n`frontend/`\n\n: React/Vite UI for uploads, sample generation, document tabs, copy buttons, and ZIP export. -\n`sample-projects/django-api-demo/`\n\n: built-in Django REST Framework sample used for the default demo. -\n`docs/dev-to-submission-draft.md`\n\n: this DEV submission draft.\n\n## How I Used Gemma 4\n\nContextForge uses `gemma-4-26b-a4b-it`\n\nthrough the Gemini API. I chose this model because ContextForge is not trying to write arbitrary code; it is doing structured documentation synthesis over selected codebase context.\n\nThe model needs to:\n\n- read selected project files\n- follow a strict JSON response schema\n- avoid inventing dependencies\n- summarize architecture clearly\n- generate instructions for both humans and AI coding agents\n\nGemma 4 works well for this kind of grounded, instruction-following task. The hosted demo uses the Gemini API so judges can try the app without running a local model.\n\nThe architecture is intentionally isolated behind a `gemma_client.py`\n\nservice, so the project can later support local Gemma 4 inference for private repositories.\n\nThe Gemma 4 call is at the heart of the pipeline:\n\n- The backend scans selected files from the uploaded or sample project.\n- The scanner filters out large, generated, binary, and irrelevant files.\n- Stack detection summarizes languages, frameworks, databases, infrastructure, and package managers.\n- ContextForge builds a structured prompt with file summaries, selected file content, and safety rules.\n- Gemma 4 returns valid JSON containing\n`readme`\n\n,`agent_md`\n\n,`setup`\n\n,`architecture`\n\n, and`summary`\n\n. - The backend validates the JSON schema before returning it to the frontend.\n\n## Architecture\n\nThe app has a small full-stack architecture:\n\n```\nUser\n  |\n  | ZIP upload or sample project\n  v\nReact + Vite frontend\n  |\n  | HTTP request\n  v\nFastAPI backend\n  |\n  | safe ZIP extraction / sample project path\n  v\nScanner\n  |\n  | selected files + file tree\n  v\nStack detector\n  |\n  | structured stack summary\n  v\nPrompt builder\n  |\n  | documentation prompt\n  v\nGemma 4 via Gemini API\n  |\n  | JSON response\n  v\nGenerated docs UI\n```\n\nThe backend is responsible for file handling, scan limits, prompt construction, and API calls. The frontend is responsible for upload controls, loading states, docs tabs, copy buttons, and ZIP download.\n\n## How the codebase scanner works\n\nThe scanner is intentionally simple and safe for an MVP.\n\nIt walks an extracted project directory recursively and ignores noisy or risky paths, including:\n\n`.git`\n\n`node_modules`\n\n`venv`\n\n`.venv`\n\n`__pycache__`\n\n`dist`\n\n`build`\n\n`vendor`\n\n`.next`\n\n`.turbo`\n\n`coverage`\n\nIt also skips binary and large files such as databases, images, PDFs, and ZIPs.\n\nThe scanner only reads text/code files and applies limits:\n\n- maximum individual file size: 80KB\n- maximum collected content: about 300KB\n\nImportant files are prioritized, including:\n\n`README.md`\n\n`package.json`\n\n`requirements.txt`\n\n`pyproject.toml`\n\n`Dockerfile`\n\n`docker-compose.yml`\n\n`manage.py`\n\n`settings.py`\n\n`urls.py`\n\n`models.py`\n\n`views.py`\n\n`serializers.py`\n\n- folders like\n`src`\n\n,`app`\n\n, and`routes`\n\nThe scanner returns a file tree summary, selected file contents, skipped file count, and total collected size.\n\n## How AGENT.md is generated\n\n`AGENT.md`\n\nis generated from the same scan context as the other docs, but the prompt gives it a specific job.\n\nIt asks Gemma 4 to write `AGENT.md`\n\nfor future AI coding agents. That means the output should include:\n\n- project map\n- important directories and files\n- setup and validation guidance\n- safe development rules\n- uncertain assumptions\n- areas that need extra caution\n\nThis is the core idea behind ContextForge: make project context durable across AI coding sessions.\n\nFor example, after a chat is cleared, the next agent can open `AGENT.md`\n\nand immediately understand how to move safely inside the repository.\n\n## Challenges faced\n\nThe biggest challenge was deciding how much code context to send to the model.\n\nSending everything is risky and inefficient. Sending too little gives weak documentation. The MVP solves this with a scanner that prioritizes important files, skips generated/binary folders, and keeps a strict total content limit.\n\nAnother challenge was making the model output predictable. ContextForge asks Gemma 4 for valid JSON with a fixed schema, then the backend validates that response before sending it to the frontend.\n\nI also had to handle security basics around ZIP uploads. The backend checks for path traversal before extracting archives and cleans temporary folders after processing.\n\nFinally, I wanted the project to work without a real API key during local testing, so I added `USE_MOCK_AI=true`\n\n.\n\n## What I would improve next\n\nNext improvements I would make:\n\n- add GitHub repository cloning from the frontend\n- support local Gemma 4 inference for private repositories\n- add richer language-specific parsing\n- generate docs from diffs after code changes\n- add server-side history for generated docs\n- support more output formats for different agent ecosystems\n- improve prompt compression for large repositories\n- add background jobs for larger scans\n\nThe local inference path is especially important. The hosted demo uses Gemini API for easy judging, but private repositories should eventually be able to use local Gemma 4 inference without sending selected code context to an external API.", "url": "https://wpnews.pro/news/i-built-contextforge-with-gemma-4-a-project-memory-generator-for-developers-and", "canonical_source": "https://dev.to/brykoech254/i-built-contextforge-with-gemma-4-a-project-memory-generator-for-developers-and-ai-coding-agents-2dlm", "published_at": "2026-05-23 11:06:00+00:00", "updated_at": "2026-05-23 11:34:59.755299+00:00", "lang": "en", "topics": ["developer-tools", "artificial-intelligence", "large-language-models", "open-source"], "entities": ["ContextForge", "Gemma 4", "Gemini API", "GitHub", "Docker Compose"], "alternates": {"html": "https://wpnews.pro/news/i-built-contextforge-with-gemma-4-a-project-memory-generator-for-developers-and", "markdown": "https://wpnews.pro/news/i-built-contextforge-with-gemma-4-a-project-memory-generator-for-developers-and.md", "text": "https://wpnews.pro/news/i-built-contextforge-with-gemma-4-a-project-memory-generator-for-developers-and.txt", "jsonld": "https://wpnews.pro/news/i-built-contextforge-with-gemma-4-a-project-memory-generator-for-developers-and.jsonld"}}