How ishan9678/codecraft works
Project type and purpose
• This is a full-stack web application named CodeCraft.
• Purpose: AI-powered code generation and iterative refinement using LLMs and a compiler API.
File structure
• Top-level “frontend” and “backend” folders, plus a docker-compose.yml at root.
• backend/src contains:
• llama_agent.py – FastAPI app entrypoint
• executor.py – runs code via Judge0 API
• generator.py – orchestrates code generation calls
• pipeline.py – implements the feedback loop
• db.py / db_models.py – ORM setup for PostgreSQL via Alembic migrations
• frontend/ contains a Next.js app (app/, components/, hooks/, lib/) with Tailwind CSS and custom UI components.
• .github/workflows/deploy.yml – CI/CD pipeline
• docker-compose.yml – service definitions for backend, frontend, and Postgres
Extract architecture from the README
• Frontend: Next.js, talking to backend via REST (CORS_ORIGINS).
• Backend: FastAPI, PostgreSQL, Judge0 API (COMPILER_API_ENDPOINT), Groq API (LLM).
• Workflow steps: user input → test case generation → code gen → compile/execute → verification → feedback loop.
Main components and their interactions
a. Frontend (Next.js)
• Hosts UI for inputs (question, language, iterations)
• Sends REST requests to backend (e.g., POST /generate)
b. Backend (FastAPI service)
• llama_agent: HTTP endpoints
• pipeline: orchestrates test generation, code generation, compilation/execution, verification, and refinement
• executor: HTTP client to Judge0 API for compile & run
• generator: calls LLM API (Groq/OpenAI) for code and test cases
• database (PostgreSQL via SQLAlchemy/Alembic): stores questions, iterations, code versions, results
c. External services
• Judge0 CE (compiler API)
• LLM provider (Groq API)
d. Infrastructure
• Docker Compose orchestrates three containers: frontend, backend, database
• CI/CD via GitHub Actions deploys to production (docker-compose in cloud or similar)
Architectural patterns and design principles
• Layered separation: UI layer, application layer (FastAPI), data layer (Postgres)
• Single-responsibility per module: pipeline vs. executor vs. generator vs. db
• Stateless API server, state persisted in DB
• Externalized dependencies (Judge0, LLM) treated as “cloud services”