Skip to content

coeus-solutions/api-code-generator-langgraph

Repository files navigation

API LangGraph - React Code Generation API

This project provides an API service that generates React TypeScript code based on natural language descriptions. It uses LangGraph for workflow management and GPT-4o for code generation.

Features

  • Generate complete React TypeScript applications from text descriptions
  • Automatic styling with Tailwind CSS
  • Streaming API responses
  • Modern code generation with best practices
  • Type-safe code generation
  • Responsive design patterns

Getting Started

Prerequisites

  • Python 3.8 or higher
  • Node.js 16 or higher
  • OpenAI API key

Installation

  1. Clone the repository:
git clone https://github.com/yourusername/api-langraph.git
cd api-langraph
  1. Install Python dependencies:
pip install -r requirements.txt
  1. Set up environment variables:
cp .env.example .env
# Edit .env and add your OpenAI API key

Running the API

  1. Start the FastAPI server:
uvicorn main:app --reload
  1. The API will be available at http://localhost:8000

API Endpoints

POST /generate-code

Generates React TypeScript code based on a description.

Request Body:

{
  "description": "string"
}

Response: Server-sent events stream with the following format:

{
  "description": "string",
  "code": "string (JSON with file contents)",
  "status": "string",
  "review_feedback": "string"
}

GET /health

Health check endpoint.

Response:

{
  "status": "healthy"
}

Testing

Run the test script to verify the API functionality:

python test_api.py

Project Structure

  • main.py - FastAPI application and API endpoints
  • workflow.py - LangGraph workflow definition and code generation logic
  • test_api.py - API testing script
  • requirements.txt - Python dependencies

Generated Code Structure

The API generates a complete React TypeScript project with the following structure:

src/
  ├── App.tsx
  ├── index.tsx
  ├── App.css
  ├── index.css
  └── react-app-env.d.ts
public/
  └── index.html
package.json
tsconfig.json
tailwind.config.js
postcss.config.js
.gitignore

Error Handling

The API includes comprehensive error handling:

  • Invalid JSON format detection
  • Missing required files validation
  • Code generation error handling
  • API request/response validation

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • OpenAI for GPT-4o
  • LangGraph for workflow management
  • FastAPI for the web framework
  • React and TypeScript communities

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published