├── .eslintignore ├── .eslintrc.cjs ├── .gitignore ├── .npmrc ├── .prettierignore ├── .prettierrc ├── .vscode └── settings.json ├── LICENSE ├── README.md ├── bun.lockb ├── package.json ├── postcss.config.cjs ├── src ├── app.d.ts ├── app.html ├── app.postcss ├── lib │ ├── index.ts │ └── interfaces │ │ ├── api.ts │ │ └── generate.ts └── routes │ ├── +layout.svelte │ ├── +layout.ts │ ├── +page.css │ ├── +page.svelte │ └── api │ └── generate │ └── +server.ts ├── static └── favicon.png ├── svelte.config.js ├── tailwind.config.ts ├── tsconfig.json └── vite.config.ts /.eslintignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | /build 4 | /.svelte-kit 5 | /package 6 | .env 7 | .env.* 8 | !.env.example 9 | 10 | # Ignore files for PNPM, NPM and YARN 11 | pnpm-lock.yaml 12 | package-lock.json 13 | yarn.lock 14 | -------------------------------------------------------------------------------- /.eslintrc.cjs: -------------------------------------------------------------------------------- 1 | /** @type { import("eslint").Linter.Config } */ 2 | module.exports = { 3 | root: true, 4 | extends: [ 5 | 'eslint:recommended', 6 | 'plugin:@typescript-eslint/recommended', 7 | 'plugin:svelte/recommended', 8 | 'prettier' 9 | ], 10 | parser: '@typescript-eslint/parser', 11 | plugins: ['@typescript-eslint'], 12 | parserOptions: { 13 | sourceType: 'module', 14 | ecmaVersion: 2020, 15 | extraFileExtensions: ['.svelte'] 16 | }, 17 | env: { 18 | browser: true, 19 | es2017: true, 20 | node: true 21 | }, 22 | overrides: [ 23 | { 24 | files: ['*.svelte'], 25 | parser: 'svelte-eslint-parser', 26 | parserOptions: { 27 | parser: '@typescript-eslint/parser' 28 | } 29 | } 30 | ] 31 | }; 32 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | /build 4 | /.svelte-kit 5 | /package 6 | .env 7 | .env.* 8 | !.env.example 9 | vite.config.js.timestamp-* 10 | vite.config.ts.timestamp-* 11 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | engine-strict=true 2 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | # Ignore files for PNPM, NPM and YARN 2 | pnpm-lock.yaml 3 | package-lock.json 4 | yarn.lock 5 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "useTabs": true, 3 | "singleQuote": true, 4 | "trailingComma": "none", 5 | "printWidth": 100, 6 | "plugins": ["prettier-plugin-svelte"], 7 | "overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }] 8 | } 9 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "prettier.documentSelectors": [ 3 | "**/*.svelte" 4 | ], 5 | "tailwindCSS.classAttributes": [ 6 | "class", 7 | "accent", 8 | "active", 9 | "animIndeterminate", 10 | "aspectRatio", 11 | "background", 12 | "badge", 13 | "bgBackdrop", 14 | "bgDark", 15 | "bgDrawer", 16 | "bgLight", 17 | "blur", 18 | "border", 19 | "button", 20 | "buttonAction", 21 | "buttonBack", 22 | "buttonClasses", 23 | "buttonComplete", 24 | "buttonDismiss", 25 | "buttonNeutral", 26 | "buttonNext", 27 | "buttonPositive", 28 | "buttonTextCancel", 29 | "buttonTextConfirm", 30 | "buttonTextFirst", 31 | "buttonTextLast", 32 | "buttonTextNext", 33 | "buttonTextPrevious", 34 | "buttonTextSubmit", 35 | "caretClosed", 36 | "caretOpen", 37 | "chips", 38 | "color", 39 | "controlSeparator", 40 | "controlVariant", 41 | "cursor", 42 | "display", 43 | "element", 44 | "fill", 45 | "fillDark", 46 | "fillLight", 47 | "flex", 48 | "flexDirection", 49 | "gap", 50 | "gridColumns", 51 | "height", 52 | "hover", 53 | "inactive", 54 | "indent", 55 | "justify", 56 | "meter", 57 | "padding", 58 | "position", 59 | "regionAnchor", 60 | "regionBackdrop", 61 | "regionBody", 62 | "regionCaption", 63 | "regionCaret", 64 | "regionCell", 65 | "regionChildren", 66 | "regionChipList", 67 | "regionChipWrapper", 68 | "regionCone", 69 | "regionContent", 70 | "regionControl", 71 | "regionDefault", 72 | "regionDrawer", 73 | "regionFoot", 74 | "regionFootCell", 75 | "regionFooter", 76 | "regionHead", 77 | "regionHeadCell", 78 | "regionHeader", 79 | "regionIcon", 80 | "regionInput", 81 | "regionInterface", 82 | "regionInterfaceText", 83 | "regionLabel", 84 | "regionLead", 85 | "regionLegend", 86 | "regionList", 87 | "regionListItem", 88 | "regionNavigation", 89 | "regionPage", 90 | "regionPanel", 91 | "regionRowHeadline", 92 | "regionRowMain", 93 | "regionSummary", 94 | "regionSymbol", 95 | "regionTab", 96 | "regionTrail", 97 | "ring", 98 | "rounded", 99 | "select", 100 | "shadow", 101 | "slotDefault", 102 | "slotFooter", 103 | "slotHeader", 104 | "slotLead", 105 | "slotMessage", 106 | "slotMeta", 107 | "slotPageContent", 108 | "slotPageFooter", 109 | "slotPageHeader", 110 | "slotSidebarLeft", 111 | "slotSidebarRight", 112 | "slotTrail", 113 | "spacing", 114 | "text", 115 | "track", 116 | "transition", 117 | "width", 118 | "zIndex" 119 | ] 120 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Cloudmate Co., Ltd. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Backend Generator AI 2 | 3 | ## Description 4 | 5 | This is a prototype of backend code generator using LLM. 6 | Use Ollama to run LLM locally. 7 | And provides a web interface for easy use. 8 | 9 | ## Caution 10 | 11 | - This is a prototype. 12 | - Generated code is may not work very nice. 13 | 14 | ## Prepare 15 | 16 | - Install [Ollama](https://ollama.ai/download) 17 | - `ollama pull codellama` 18 | 19 | ## Start server 20 | 21 | ```bash 22 | git clone https://github.com/cloudmatelabs/backend-generator-ai.git 23 | cd backend-generator-ai 24 | bun install 25 | bun run dev 26 | ``` 27 | 28 | and open http://localhost:5173 29 | 30 | If you not want to use bun, you can use `npm` or `yarn` or `pnpm`. 31 | 32 | ## Usage 33 | 34 | 1. Fill in the form and click "Generate" button. 35 | 2. Wait for a while and you will see the generated code. 36 | 37 | ## License 38 | 39 | [MIT](LICENSE) 40 | -------------------------------------------------------------------------------- /bun.lockb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahnlabcloudmatelabs/backend-generator-ai/2976f1a951bcd9be6ed1077da3305d04a6c59036/bun.lockb -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "backend-generator-ai", 3 | "version": "0.0.1-alpha", 4 | "private": true, 5 | "scripts": { 6 | "dev": "vite dev", 7 | "build": "vite build", 8 | "preview": "vite preview", 9 | "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json", 10 | "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch", 11 | "lint": "prettier --check . && eslint .", 12 | "format": "prettier --write ." 13 | }, 14 | "devDependencies": { 15 | "@skeletonlabs/skeleton": "2.7.0", 16 | "@skeletonlabs/tw-plugin": "0.3.1", 17 | "@sveltejs/adapter-auto": "^3.1.0", 18 | "@sveltejs/kit": "^2.0.0", 19 | "@sveltejs/vite-plugin-svelte": "^3.0.0", 20 | "@tailwindcss/forms": "0.5.7", 21 | "@tailwindcss/typography": "0.5.10", 22 | "@types/eslint": "8.56.0", 23 | "@types/marked": "^6.0.0", 24 | "@types/node": "20.10.6", 25 | "@typescript-eslint/eslint-plugin": "^6.0.0", 26 | "@typescript-eslint/parser": "^6.0.0", 27 | "autoprefixer": "10.4.16", 28 | "eslint": "^8.56.0", 29 | "eslint-config-prettier": "^9.1.0", 30 | "eslint-plugin-svelte": "^2.35.1", 31 | "postcss": "8.4.33", 32 | "prettier": "^3.1.1", 33 | "prettier-plugin-svelte": "^3.1.2", 34 | "svelte": "^4.2.7", 35 | "svelte-check": "^3.6.0", 36 | "tailwindcss": "3.4.0", 37 | "tslib": "^2.4.1", 38 | "typescript": "^5.0.0", 39 | "vite": "^5.0.3", 40 | "vite-plugin-tailwind-purgecss": "0.2.0" 41 | }, 42 | "type": "module", 43 | "dependencies": { 44 | "@floating-ui/dom": "1.5.3", 45 | "@langchain/community": "^0.0.14", 46 | "@langchain/core": "^0.1.8", 47 | "highlight.js": "^11.9.0", 48 | "marked": "^11.1.1", 49 | "marked-highlight": "^2.1.0" 50 | } 51 | } -------------------------------------------------------------------------------- /postcss.config.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: { 3 | tailwindcss: {}, 4 | autoprefixer: {}, 5 | }, 6 | } -------------------------------------------------------------------------------- /src/app.d.ts: -------------------------------------------------------------------------------- 1 | // See https://kit.svelte.dev/docs/types#app 2 | // for information about these interfaces 3 | // and what to do when importing types 4 | declare namespace App { 5 | // interface Locals {} 6 | // interface PageData {} 7 | // interface Error {} 8 | // interface Platform {} 9 | } 10 | -------------------------------------------------------------------------------- /src/app.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 | %sveltekit.head% 8 | 9 | 10 |257 | {generatedError} 258 |259 | {/if} 260 | -------------------------------------------------------------------------------- /src/routes/api/generate/+server.ts: -------------------------------------------------------------------------------- 1 | import { Ollama } from "@langchain/community/llms/ollama"; 2 | import type { RequestHandler } from './$types'; 3 | 4 | import type { GenerateRequest } from "$lib/interfaces/generate"; 5 | 6 | export const POST: RequestHandler = async ({request}) => { 7 | const { 8 | language, 9 | framework, 10 | etc, 11 | modelSchema, 12 | apis, 13 | }: GenerateRequest = await request.json() 14 | const model = new Ollama({ 15 | model: "codellama" 16 | }) 17 | 18 | const prompt = `You are specialist at backend development. 19 | 20 | --- 21 | 22 | - Language: ${language} 23 | ${framework ? '- Framework: ' + framework : ''} 24 | ${etc ? etc : ''} 25 | 26 | [Database Schema] 27 | 28 | \`\`\`sql 29 | ${modelSchema} 30 | \`\`\` 31 | 32 | [API] 33 | 34 | ${apis.map((api) => `- Path: ${api.path} 35 | - Method: ${api.method} 36 | - Request Example 37 | \`\`\`json 38 | ${api.requestExample} 39 | \`\`\` 40 | - Response Example: 41 | \`\`\`json 42 | ${api.responseExample} 43 | \`\`\` 44 | - Description: ${api.description}`).join('\n')} 45 | 46 | --- 47 | 48 | Generate backend code from this document. 49 | Let's think step by step` 50 | 51 | const response = await model.stream(prompt) 52 | 53 | const stream = new ReadableStream({ 54 | start (controller) { 55 | function push() { 56 | response.next() 57 | .then(({value, done}) => { 58 | if (done) { 59 | controller.close() 60 | return 61 | } 62 | 63 | controller.enqueue(value) 64 | push() 65 | }) 66 | } 67 | 68 | push() 69 | }, 70 | 71 | cancel (reason) { 72 | response.cancel(reason) 73 | } 74 | }) 75 | 76 | return new Response(stream, { 77 | headers: { 78 | "Content-Type": "text/event-stream" 79 | } 80 | }) 81 | } 82 | -------------------------------------------------------------------------------- /static/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahnlabcloudmatelabs/backend-generator-ai/2976f1a951bcd9be6ed1077da3305d04a6c59036/static/favicon.png -------------------------------------------------------------------------------- /svelte.config.js: -------------------------------------------------------------------------------- 1 | import adapter from '@sveltejs/adapter-auto'; 2 | import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'; 3 | 4 | /** @type {import('@sveltejs/kit').Config} */ 5 | const config = { 6 | extensions: ['.svelte'], 7 | // Consult https://kit.svelte.dev/docs/integrations#preprocessors 8 | // for more information about preprocessors 9 | preprocess: [vitePreprocess()], 10 | 11 | kit: { 12 | // adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list. 13 | // If your environment is not supported or you settled on a specific environment, switch out the adapter. 14 | // See https://kit.svelte.dev/docs/adapters for more information about adapters. 15 | adapter: adapter() 16 | } 17 | }; 18 | export default config; -------------------------------------------------------------------------------- /tailwind.config.ts: -------------------------------------------------------------------------------- 1 | import { join } from 'path' 2 | import type { Config } from 'tailwindcss' 3 | import forms from '@tailwindcss/forms'; 4 | import typography from '@tailwindcss/typography'; 5 | import { skeleton } from '@skeletonlabs/tw-plugin' 6 | 7 | export default { 8 | darkMode: 'class', 9 | content: ['./src/**/*.{html,js,svelte,ts}', join(require.resolve('@skeletonlabs/skeleton'), '../**/*.{html,js,svelte,ts}')], 10 | theme: { 11 | extend: {}, 12 | }, 13 | plugins: [ 14 | forms, 15 | typography, 16 | skeleton({ 17 | themes: { 18 | preset: [ 19 | { 20 | name: 'skeleton', 21 | enhancements: true, 22 | }, 23 | ], 24 | }, 25 | }), 26 | ], 27 | } satisfies Config; 28 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./.svelte-kit/tsconfig.json", 3 | "compilerOptions": { 4 | "allowJs": true, 5 | "checkJs": true, 6 | "esModuleInterop": true, 7 | "forceConsistentCasingInFileNames": true, 8 | "resolveJsonModule": true, 9 | "skipLibCheck": true, 10 | "sourceMap": true, 11 | "strict": true, 12 | "moduleResolution": "bundler" 13 | } 14 | // Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias 15 | // 16 | // If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes 17 | // from the referenced tsconfig.json - TypeScript does not merge them in 18 | } 19 | -------------------------------------------------------------------------------- /vite.config.ts: -------------------------------------------------------------------------------- 1 | import { purgeCss } from 'vite-plugin-tailwind-purgecss'; 2 | import { sveltekit } from '@sveltejs/kit/vite'; 3 | import { defineConfig } from 'vite'; 4 | 5 | export default defineConfig({ 6 | plugins: [sveltekit(), purgeCss({ 7 | safelist: { 8 | // any selectors that begin with "hljs-" will not be purged 9 | greedy: [/^hljs-/], 10 | }, 11 | }), 12 | ], 13 | }); --------------------------------------------------------------------------------