|
1 | | -# java-api-generator |
2 | | -# java-api-generator |
| 1 | +# Java API Generator – AI-powered API creation |
| 2 | + |
| 3 | +## 🔹 Overview |
| 4 | +Java API Generator is a tool that automates the creation of Java APIs using **Spring Boot**, **Freemarker templates**, and **AI-driven code generation**. |
| 5 | + |
| 6 | +With this tool, you can: |
| 7 | +✅ **Generate a Java Controller** automatically from an entity name. |
| 8 | +✅ **Create a complete Java class** from a text prompt using AI. |
| 9 | +✅ **Build a fully functional API**, packaged in a ZIP file, ready to run. |
| 10 | + |
| 11 | +--- |
| 12 | + |
| 13 | +## ⚙️ Tech Stack |
| 14 | +- **Java 21** (Records, String Templates, Pattern Matching) |
| 15 | +- **Spring Boot 3** (Backend and API structure) |
| 16 | +- **Freemarker** (Template engine for dynamic code generation) |
| 17 | +- **Mistral AI** (via Hugging Face API for AI-powered class generation) |
| 18 | +- **Swagger/OpenAPI** (for API documentation and testing) |
| 19 | + |
| 20 | +--- |
| 21 | + |
| 22 | +## 🛠 Installation & Usage |
| 23 | + |
| 24 | +### 1️⃣ Clone the repository |
| 25 | +```sh |
| 26 | +git clone https://github.com/sbrunomello/java-api-generator.git |
| 27 | +cd java-api-generator |
| 28 | +``` |
| 29 | + |
| 30 | +### 2️⃣ Set up environment variables |
| 31 | +Create a `.env` file in the root directory and configure your Hugging Face API key: |
| 32 | +```ini |
| 33 | +AI_API_URL=https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct |
| 34 | +AI_API_KEY=your_huggingface_api_key |
| 35 | +``` |
| 36 | + |
| 37 | +### 3️⃣ Run the application |
| 38 | +Make sure you have **Java 21+** installed, then execute: |
| 39 | +```sh |
| 40 | +./mvnw spring-boot:run |
| 41 | +``` |
| 42 | + |
| 43 | +### 4️⃣ Test the API |
| 44 | +Once the application is running, access **Swagger UI** to test the endpoints: |
| 45 | +📌 `http://localhost:8080/swagger-ui.html` |
| 46 | + |
| 47 | +--- |
| 48 | + |
| 49 | +## 🎯 API Endpoints |
| 50 | + |
| 51 | +### 📌 Generate a Java Controller |
| 52 | +**Endpoint:** `POST /api/generator/generate` |
| 53 | +**Params:** |
| 54 | +- `packageName` (e.g., `"com.example"`) |
| 55 | +- `entityName` (e.g., `"User"`) |
| 56 | + |
| 57 | +📌 **Example Request:** |
| 58 | +```sh |
| 59 | +curl -X POST "http://localhost:8080/api/generator/generate?packageName=com.example&entityName=User" |
| 60 | +``` |
| 61 | + |
| 62 | +--- |
| 63 | + |
| 64 | +### 📌 Generate a Java Class using AI |
| 65 | +**Endpoint:** `POST /api/generator/generate-ai` |
| 66 | +**Params:** |
| 67 | +- `className` (e.g., `"OrderService"`) |
| 68 | +- `prompt` (e.g., `"Create a service class to manage orders"`) |
| 69 | + |
| 70 | +📌 **Example Request:** |
| 71 | +```sh |
| 72 | +curl -X POST "http://localhost:8080/api/generator/generate-ai?className=OrderService&prompt=Create+a+service+class+to+manage+orders" |
| 73 | +``` |
| 74 | + |
| 75 | +--- |
| 76 | + |
| 77 | +### 📌 Generate a Complete API Project |
| 78 | +**Endpoint:** `GET /api/generator/simple-api` |
| 79 | +**Params:** |
| 80 | +- `projectName` (e.g., `"MyProject"`) |
| 81 | +- `packageName` (e.g., `"com.example"`) |
| 82 | + |
| 83 | +📌 **Example Request:** |
| 84 | +```sh |
| 85 | +curl -X GET "http://localhost:8080/api/generator/simple-api?projectName=MyProject&packageName=com.example" |
| 86 | +``` |
| 87 | + |
| 88 | +This will return a **ZIP file** containing a fully structured Spring Boot API project. |
| 89 | + |
| 90 | +--- |
| 91 | + |
| 92 | +## 🔜 Next Steps |
| 93 | +🚀 Build a **front-end in Angular** for better usability. |
| 94 | +🚀 Integrate **AI-powered class generation** into complete API creation. |
| 95 | +🚀 Replace cloud-based AI with a **local AI model**, making code generation **faster, more secure, and fully independent**. |
| 96 | + |
| 97 | +--- |
| 98 | + |
| 99 | +## 👨💻 Contributing |
| 100 | +Pull requests are welcome! If you’d like to contribute: |
| 101 | +1. **Fork the repository**. |
| 102 | +2. **Create a new branch** (`git checkout -b feature-branch`). |
| 103 | +3. **Commit your changes** (`git commit -m "Add new feature"`). |
| 104 | +4. **Push the branch** (`git push origin feature-branch`). |
| 105 | +5. **Open a Pull Request**. |
| 106 | + |
| 107 | +--- |
0 commit comments