An open API service indexing awesome lists of open source software.

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.

Awesome Lists containing this project

README

          

![backtool](https://socialify.git.ci/Amanbig/create-nextpy-app/image?font=Source+Code+Pro&language=1&name=1&owner=1&pattern=Brick+Wall&theme=Dark)

# 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.**