|
1 | 1 | # next-api-ai-template |
2 | | -A full-stack AI-powered starter template with Next.js frontend, Express backend, and a dedicated AI module. Structured into app/, api/, and ai/ for clean development, rapid prototyping, and seamless integration. |
| 2 | + |
| 3 | +A full-stack AI-powered starter template with **Next.js frontend**, **Express backend**, and a **Python AI module**. |
| 4 | +Structured into `app/`, `api/`, and `ai/` for clean development, rapid prototyping, and seamless integration. |
| 5 | + |
| 6 | +--- |
| 7 | + |
| 8 | +## Tech Stack |
| 9 | + |
| 10 | +- **Frontend:** Next.js (TypeScript, pnpm) |
| 11 | +- **Backend:** Express.js (Node.js, pnpm) |
| 12 | +- **AI Service:** Python (Flask) |
| 13 | +- **Containerization:** Docker + Docker Compose |
| 14 | +- **CI/CD:** GitHub Actions (ready for build + push caching) |
| 15 | + |
| 16 | +--- |
| 17 | + |
| 18 | +## Folder Structure |
| 19 | + |
| 20 | +``` |
| 21 | +. |
| 22 | +├── app/ # Next.js frontend |
| 23 | +│ └── Dockerfile |
| 24 | +├── api/ # Express backend |
| 25 | +│ └── Dockerfile |
| 26 | +├── ai/ # Python Flask microservice |
| 27 | +│ ├── main.py |
| 28 | +│ ├── requirements.txt |
| 29 | +│ └── Dockerfile |
| 30 | +├── docker-compose.yml |
| 31 | +└── pnpm-workspace.yaml |
| 32 | +``` |
| 33 | + |
| 34 | +--- |
| 35 | + |
| 36 | +## Getting Started |
| 37 | + |
| 38 | +### Clone the repo |
| 39 | + |
| 40 | +```bash |
| 41 | +git clone https://github.com/upayanmazumder/next-api-ai-template.git |
| 42 | +cd next-api-ai-template |
| 43 | +``` |
| 44 | + |
| 45 | +### Run with Docker |
| 46 | + |
| 47 | +Build and start all services: |
| 48 | + |
| 49 | +```bash |
| 50 | +docker compose up --build |
| 51 | +``` |
| 52 | + |
| 53 | +Then open: |
| 54 | + |
| 55 | +- **Frontend:** [http://localhost:3000](http://localhost:3000) |
| 56 | +- **API:** [http://localhost:4000](http://localhost:4000) |
| 57 | +- **AI:** [http://localhost:5000](http://localhost:5000) |
| 58 | + |
| 59 | +--- |
| 60 | + |
| 61 | +## How It Works |
| 62 | + |
| 63 | +- **Next.js (`app/`)** → Handles UI + user interactions. |
| 64 | +- **Express (`api/`)** → Acts as middleware and routes frontend requests to AI service. |
| 65 | +- **Flask (`ai/`)** → Processes AI logic or ML inference and returns responses to the API. |
| 66 | + |
| 67 | +Each layer is isolated, containerized, and easily swappable. |
| 68 | + |
| 69 | +--- |
| 70 | + |
| 71 | +## Example Flow |
| 72 | + |
| 73 | +1. Frontend sends text → `/api/analyze` |
| 74 | +2. Express forwards it to Flask at `/predict` |
| 75 | +3. Flask responds with mock or real AI prediction |
| 76 | +4. Response bubbles back to UI instantly |
| 77 | + |
| 78 | +--- |
| 79 | + |
| 80 | +## Docker Compose Overview |
| 81 | + |
| 82 | +| Service | Port | Description | |
| 83 | +| ------- | ---- | ---------------- | |
| 84 | +| `app` | 3000 | Next.js frontend | |
| 85 | +| `api` | 4000 | Express backend | |
| 86 | +| `ai` | 5000 | Flask AI service | |
| 87 | + |
| 88 | +Each service includes caching, health checks, and restart policies. |
| 89 | +You can deploy them independently or as a full stack. |
| 90 | + |
| 91 | +--- |
| 92 | + |
| 93 | +## Development Notes |
| 94 | + |
| 95 | +- Uses `pnpm` for efficient dependency management. |
| 96 | +- Python virtual env not needed — handled via Docker. |
| 97 | +- Ready for GitHub Actions auto-build (with GHA cache). |
| 98 | + |
| 99 | +--- |
| 100 | + |
| 101 | +## Commands |
| 102 | + |
| 103 | +```bash |
| 104 | +# Run locally (no docker) |
| 105 | +cd app && pnpm dev |
| 106 | +cd api && pnpm run dev |
| 107 | +cd ai && python main.py |
| 108 | + |
| 109 | +# Run all with docker |
| 110 | +docker compose up |
| 111 | +``` |
| 112 | + |
| 113 | +--- |
| 114 | + |
| 115 | +## Future Ideas |
| 116 | + |
| 117 | +- Add real model inference (OpenAI / Ollama / HuggingFace) |
| 118 | +- Add shared types via `common/` |
| 119 | +- Integrate PostgreSQL or Redis service |
| 120 | +- Deploy to Fly.io, Railway, or Render |
| 121 | + |
| 122 | +--- |
| 123 | + |
| 124 | +## License |
| 125 | + |
| 126 | +Licensed under the [MIT License](LICENSE). |
0 commit comments