https://github.com/amanbig/create-nextpy-app
A powerful command-line tool for creating full-stack applications with NextJS frontend and Python backend. Choose between FastAPI for traditional routing or RunAPI for Next.js-inspired file-based routing.
https://github.com/amanbig/create-nextpy-app
fastapi git hacktoberfest javascript nextjs python tailwindcss typescript
Last synced: 3 months ago
JSON representation
A powerful command-line tool for creating full-stack applications with NextJS frontend and Python backend. Choose between FastAPI for traditional routing or RunAPI for Next.js-inspired file-based routing.
- Host: GitHub
- URL: https://github.com/amanbig/create-nextpy-app
- Owner: Amanbig
- License: mit
- Created: 2025-08-26T14:47:05.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2025-12-27T18:55:06.000Z (6 months ago)
- Last Synced: 2026-03-30T02:44:33.097Z (3 months ago)
- Topics: fastapi, git, hacktoberfest, javascript, nextjs, python, tailwindcss, typescript
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/create-nextpy-app
- Size: 149 KB
- Stars: 5
- Watchers: 0
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README

# NextPy CLI
A powerful command-line tool for creating full-stack applications with NextJS frontend and Python backend. Choose between **FastAPI** for traditional routing or **RunAPI** for Next.js-inspired file-based routing.
## ๐ Quick Start
```bash
# Using npx (recommended)
npx create-nextpy-app
# Or install globally
npm install -g create-next```bash
# Clone the repository
git clone https://github.com/Amanbig/create-nextpy-app.git
cd create-nextpy-app
# Install dependencies
npm install
# Test locally
npm link
create-nextpy-app --help
```te-nextpy-app
```
## โจ Features
- ๐ฏ **Interactive Setup**: Guided project creation with prompts
- ๐ **Dual Backend Options**:
- **FastAPI**: Traditional routing with explicit route definitions
- **RunAPI**: File-based routing inspired by Next.js (routes folder structure)
- ๐ **Full-Stack Integration**: Complete NextJS + Python backend communication
- ๐ **API Routes**: Pre-configured NextJS API routes that proxy to Python backend
- ๐จ **Styling Options**: Optional Tailwind CSS integration
- ๐ป **Language Support**: JavaScript or TypeScript for frontend
- ๐ **Development Ready**: Concurrent dev servers with npm scripts
- ๐ **Demo Included**: Simple GET request demo to test backend connectivity
- ๐ **Language Choice**: Support for both TypeScript and JavaScript
- ๐ง **Cross-Platform**: Works on Windows, macOS, and Linux
- ๐ **Python Detection**: Automatically detects `python` or `python3` commands
- ๐ฆ **Package Scripts**: Convenient npm scripts to run both frontend and backend
- ๐ **Documentation**: Comprehensive README files for each component
- ๐ **Demo Components**: Sample components showing frontend-backend communication
- ๐ก๏ธ **Robust Error Handling**: Graceful handling of missing dependencies
- ๐ **Git Integration**: Automatic git initialization with fallback handling
- ๐ **Smart Releases**: Automated publishing only when version changes
## ๐ Usage
### Interactive Mode (Recommended)
```bash
npx create-nextpy-app
```
The CLI will prompt you for:
- Project name
- Language choice (TypeScript or JavaScript)
- Tailwind CSS preference
- API framework choice (FastAPI or RunAPI)
### Command Line Options
```bash
npx create-nextpy-app [options]
Options:
-p, --project Specify project name
-l, --language Specify language (JavaScript, TypeScript)
-t, --tailwind Specify whether to use tailwind (Yes, No)
-r, --api Specify API framework (FastAPI, RunAPI)
-f, --force Force overwrite of existing files without prompting
-h, --help Display help for command
-V, --version Display version number
```
### Examples
```bash
# Create TypeScript project with Tailwind CSS and RunAPI
npx create-nextpy-app -p my-app -l TypeScript -t Yes -r RunAPI
# Create JavaScript project with FastAPI (traditional routing)
npx create-nextpy-app -p my-api -l JavaScript -t No -r FastAPI
# Quick setup with RunAPI (file-based routing like Next.js)
npx create-nextpy-app -p my-runapi-app -r RunAPI
npx create-nextpy-app --project my-app --language TypeScript --tailwind Yes
# Create JavaScript project without Tailwind CSS
npx create-nextpy-app -p simple-app -l JavaScript -t No
# Interactive mode (prompts for all options)
npx create-nextpy-app
```
## ๐ Generated Project Structure
```
my-project/
โโโ package.json # Root package.json with convenient scripts
โโโ README.md # Project documentation
โโโ frontend/ # NextJS application
โ โโโ src/
โ โ โโโ app/
โ โ โ โโโ api/
โ โ โ โ โโโ backend/
โ โ โ โ โโโ route.ts/js # API route to Python backend
โ โ โ โโโ page.tsx/jsx # Main page with demo
โ โ โ โโโ layout.tsx/jsx # Root layout
โ โ โโโ components/
โ โ โ โโโ BackendDemo.tsx/jsx # Demo component
โ โ โโโ lib/
โ โ โโโ api.ts/js # API utilities
โ โโโ .env.local # Environment variables
โ โโโ package.json # Frontend dependencies
โ โโโ README.md # Frontend documentation
โโโ backend/ # Python backend (FastAPI or RunAPI)
โโโ app.py (FastAPI) # FastAPI server
โ OR
โโโ routes/ (RunAPI) # RunAPI file-based routes
โ โโโ index.py # GET /
โ โโโ api/ # API routes
โโโ main.py (RunAPI) # RunAPI app entry point
โโโ requirements.txt # Python dependencies
โโโ package.json # Cross-platform npm scripts
โโโ .env # Backend environment variables
โโโ .gitignore # Git ignore rules
โโโ venv/ # Python virtual environment
โโโ README.md # Backend documentation
```
## ๐ Backend Architecture: FastAPI vs RunAPI
Choose the backend framework that best fits your development style:
### FastAPI (Traditional Routing)
Perfect for developers who prefer explicit route definitions and traditional API structures.
```python
# backend/app.py
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def read_root():
return {"message": "Hello from FastAPI!"}
@app.get("/api/users")
def get_users():
return {"users": []}
@app.post("/api/users")
def create_user(user: dict):
return {"created": user}
```
**FastAPI Benefits:**
- โ
Explicit route definitions
- โ
Mature ecosystem
- โ
Extensive documentation
- โ
Built-in OpenAPI/Swagger docs
- โ
Great for complex API logic
### RunAPI (File-based Routing)
Perfect for developers who love Next.js and want the same intuitive file-based routing for APIs.
```
backend/
โโโ routes/
โ โโโ index.py # GET /
โ โโโ api/
โ โโโ users.py # GET,POST /api/users
โ โโโ users/
โ โโโ [id].py # GET,PUT,DELETE /api/users/{id}
โโโ main.py
```
```python
# backend/routes/index.py
from runapi import JSONResponse
async def get():
return JSONResponse({"message": "Hello from RunAPI!"})
# backend/routes/api/users.py
from runapi import JSONResponse, Request
async def get():
return JSONResponse({"users": []})
async def post(request: Request):
body = await request.json()
return JSONResponse({"created": body})
```
**RunAPI Benefits:**
- โ
File structure = API structure
- โ
Next.js-inspired developer experience
- โ
Dynamic routes with `[id].py` syntax
- โ
Built on FastAPI (same performance)
- โ
Perfect for developers familiar with Next.js
### When to Choose Which?
| Choose FastAPI | Choose RunAPI |
|----------------|---------------|
| Traditional API development | Next.js-style file routing |
| Complex route logic | Clean, organized structure |
| Team familiar with FastAPI | Team loves Next.js approach |
| Existing FastAPI codebase | New projects |
| Need maximum control | Want rapid development |
## ๐ฏ What Gets Created
### Frontend (NextJS)
- โก **NextJS 15** with App Router
- ๐จ **Tailwind CSS** (optional)
- ๐ **TypeScript/JavaScript** support
- ๐ **API Routes** that proxy to Python backend
- ๐งฉ **Demo Component** with simple GET request example
- ๐ฑ **Responsive Design** with modern UI
- โ ๏ธ **Error Handling** with user feedback
- ๐ง **ESLint** configuration
### Backend (FastAPI or RunAPI)
- ๐ **FastAPI**: Traditional routing with automatic OpenAPI docs
- ๐ **RunAPI**: File-based routing inspired by Next.js
- ๐ **CORS** configured for NextJS frontend
- ๐ **Virtual Environment** automatically created
- ๐ฆ **Dependencies** installed automatically
- ๐ **Hot Reload** with development server
- ๐ง **Cross-Platform** npm scripts
- ๐ **Sample GET Endpoint** for testing connectivity
### Project Root
- ๐ฆ **Convenient Scripts** to run both frontend and backend
- ๐ **Comprehensive Documentation**
- ๐ง **Cross-Platform Compatibility**
- ๐ฏ **Single Command Setup**
## ๐ Generated npm Scripts
After creating a project, you can use these convenient scripts:
### Root Directory
```bash
# Run both frontend and backend together
npm run dev
# Run only frontend
npm run frontend
# Run only backend
npm run backend
# Build frontend for production
npm run build
# Install all dependencies
npm run install:all
```
### Frontend Directory
```bash
cd frontend
# Development server
npm run dev
# Production build
npm run build
# Production server
npm start
# Linting
npm run lint
```
### Backend Directory
```bash
cd backend
# Development with hot reload
npm run dev # Works for both FastAPI and RunAPI
# FastAPI: Traditional uvicorn server
npm start # uvicorn app:app --host 0.0.0.0 --port 8000
# RunAPI: Built-in dev server with file watching
# (npm run dev automatically uses 'runapi dev' for RunAPI projects)
# Production server
npm start # Uses 'runapi start' (no reload)
# Install Python dependencies
npm run install
```
## ๐ ๏ธ System Requirements
### Required
- **Node.js** 18.0.0 or higher
- **npm** 8.0.0 or higher
- **Python** 3.8 or higher
### Optional
- **Git** (for version control - automatically initialized if available)
## ๐ Cross-Platform Support
The CLI automatically detects your operating system and uses appropriate commands:
| Platform | Python Command | Virtual Environment | Package Manager |
|----------|---------------|-------------------|-----------------|
| **Windows** | `python` | `venv\Scripts\` | `pip` |
| **macOS** | `python3` | `venv/bin/` | `pip3` |
| **Linux** | `python3` | `venv/bin/` | `pip3` |
## ๐จ Architecture
The generated application follows this architecture pattern:
```
โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโ
โ Frontend โโโโโถโ NextJS API Routesโโโโโถโ Python Backend โ
โ (React) โ โ (/api/backend) โ โ (FastAPI / RunAPI) โ
โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโ
```
### Benefits of This Architecture
1. **๐ Security**: Frontend never directly exposes backend URLs
2. **๐ง Flexibility**: Add authentication, rate limiting, etc. in API routes
3. **๐ Type Safety**: Full TypeScript support throughout
4. **โก Performance**: Server-side request processing
5. **๐ Environment Management**: Different backend URLs per environment
## ๐จ Troubleshooting
### Common Issues
#### 1. Python Not Found
```bash
Error: Python not found. Please install Python and ensure it's in your PATH.
```
**Solution**: Install Python from [python.org](https://python.org) and add to PATH
#### 2. Git Not Available
```bash
โ ๏ธ Git not found or failed to initialize. You can initialize git manually later with: git init
```
**Solution**: This is not an error! The CLI continues without git and you can:
- Install Git from [git-scm.com](https://git-scm.com)
- Initialize git manually later: `cd your-project && git init`
- The project works perfectly without git
#### 3. Virtual Environment Creation Failed
```bash
Error: python -m venv venv
```
**Solutions**:
- Ensure Python is properly installed
- Try `python3 -m venv venv` manually
- Check Python version: `python --version`
#### 4. RunAPI Installation Failed
```bash
Error: Failed to install runapi
```
**Solutions**:
- Ensure Python virtual environment is activated
- Try manual installation: `pip install runapi`
- Check Python version compatibility (3.8+)
#### 5. RunAPI Init Command Failed
```bash
Error: runapi init command failed
```
**Solutions**:
- Ensure RunAPI is properly installed: `pip list | grep runapi`
- Try running manually: `python -m runapi init .`
- Check virtual environment is activated
#### 6. File-based Routes Not Loading (RunAPI)
**Symptoms**: Routes in `routes/` folder not accessible
**Solutions**:
- Ensure files follow naming convention: `index.py`, `users.py`, `[id].py`
- Check that functions are properly exported: `async def get():`
- Verify `main.py` exists and creates RunAPI app
- Restart the development server: `runapi dev`
#### 7. NextJS Creation Timeout
```bash
NextJS creation timed out.
```
**Solutions**:
- Check internet connection
- Clear npm cache: `npm cache clean --force`
- Try manual creation with provided command
#### 8. Port Already in Use
```bash
Error: Port 3000/8000 already in use
```
**Solutions**:
- Kill existing processes on those ports
- Change ports in configuration files
### Error Handling Features
The CLI includes robust error handling for common scenarios:
- **๐ Python Detection**: Automatically tries `python` then `python3`
- **๐ Git Graceful Fallback**: Continues without git if not available
- **โฑ๏ธ Timeout Management**: Handles slow network connections
- **๐ง Cross-Platform**: Adapts commands for your operating system
- **๐ Clear Messages**: Provides helpful error messages and solutions
- **๐ง Framework Detection**: Automatically configures for FastAPI or RunAPI
- **๐ File Structure Validation**: Ensures proper RunAPI route structure
### Getting Help
1. **Check the logs**: The CLI provides detailed error messages
2. **Manual setup**: Use the manual setup instructions if CLI fails
3. **Clear cache**: Clear npm cache and try again
4. **Check system requirements**: Ensure all requirements are met
5. **Framework-specific help**:
- FastAPI: Check [FastAPI documentation](https://fastapi.tiangolo.com/)
- RunAPI: Check [RunAPI repository](https://github.com/Amanbig/runapi)
6. **Test backend directly**: Visit `http://localhost:8000` to check if backend is running
7. **Test API routes**: Visit `http://localhost:3000/api/backend` to test NextJS โ Python connection
## ๐ง Development
### Building from Source
```bash
# Clone the repository
git clone https://github.com/Amanbig/create-nextpy-app.git
cd create-nextpy-app
# Install dependencies
npm install
# Test locally
npm link
create-nextpy-app --help
```
### Release Workflow
The project includes an automated release workflow with smart version detection:
#### ๐ Automated Publishing
- **Triggers**: Only when `package.json` version is changed on main branch
- **Publishes to**:
- [npmjs.com](https://www.npmjs.com/package/create-nextpy-app)
- [GitHub Packages](https://github.com/Amanbig/create-nextpy-app/packages)
- **Creates**: Automatic GitHub releases with changelogs
#### ๐ Release Process
1. Update version in `package.json`:
```bash
npm version patch # or minor, major
```
2. Push to main branch:
```bash
git push && git push --tags
```
3. GitHub Actions automatically:
- Detects version change
- Builds and tests the package
- Publishes to npm and GitHub Packages
- Creates a GitHub release
#### ๐ก๏ธ Safety Features
- **Version Change Detection**: Only publishes when version actually changes
- **Dual Publishing**: Available on both npm and GitHub Packages
- **Dynamic Scoping**: Automatically creates scoped packages for GitHub
- **Release Notes**: Auto-generated with installation instructions
### Contributing
1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Add tests if applicable
5. Submit a pull request
## ๐ Documentation
Each generated project includes comprehensive documentation:
- **Project README**: Overview and quick start guide
- **Frontend README**: NextJS-specific documentation
- **Backend README**: Framework-specific documentation
- **FastAPI**: Traditional API development with OpenAPI docs
- **RunAPI**: File-based routing guide with examples
- **API Documentation**: Auto-generated docs
- **FastAPI**: Swagger UI at `/docs` and ReDoc at `/redoc`
- **RunAPI**: Built-in documentation with route discovery
## ๐ฏ Use Cases
### Perfect For
- ๐ **Rapid Prototyping**: Quickly create full-stack prototypes
- ๐ **Learning Projects**: Learn NextJS + Python integration
- ๐ข **Startup MVPs**: Fast MVP development with file-based routing
- ๐ **Educational**: Teaching full-stack development
- ๐ฌ **Experimentation**: Try new ideas quickly
- ๐ฏ **Next.js Developers**: Familiar file-based routing for APIs
### Example Projects
- **Data Dashboards**: Frontend visualization with Python data processing
- **API Wrappers**: NextJS frontend for existing Python APIs
- **Machine Learning Apps**: ML models in Python with React frontend
- **CRUD Applications**: Database operations with modern UI
- **Microservices**: RunAPI for clean, organized API structure
- **E-commerce APIs**: File-based routes for products, users, orders
## ๐ฎ Roadmap
### Core Features
- [ ] Database integration options (PostgreSQL, MongoDB)
- [ ] Authentication templates (JWT, OAuth)
- [ ] Deployment configurations (Docker, Vercel, AWS)
- [ ] Testing setup (Jest, Pytest)
- [ ] CI/CD pipeline templates
- [ ] Additional frontend frameworks (Vue, Svelte)
### RunAPI Enhancements
- [ ] WebSocket support for real-time features
- [ ] Middleware templates (rate limiting, caching)
- [ ] Dynamic route templates with advanced patterns
- [ ] RunAPI plugin system integration
- [ ] Background task examples with RunAPI
- [ ] Database ORM integration examples
### FastAPI Enhancements
- [ ] Advanced FastAPI templates with dependencies
- [ ] FastAPI middleware examples
- [ ] Custom response models and validation
- [ ] FastAPI background tasks integration
## ๐ License
MIT License - see LICENSE file for details
## ๐ค Contributing
Contributions are welcome! Please read our contributing guidelines and submit pull requests to our repository.
## ๐ Support
- ๐ง **Email**: [amanpreetsinghjhiwant7@gmail.com]
- ๐ **Issues**: [GitHub Issues](https://github.com/Amanbig/create-nextpy-app/issues)
- ๐ฌ **Discussions**: [GitHub Discussions](https://github.com/Amanbig/create-nextpy-app/discussions)
---
**Made with โค๏ธ for developers who want to build full-stack applications quickly and efficiently.**