Spaces:
Running
Running
File size: 3,876 Bytes
81aa0b5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | ---
name: fullstack-scaffold
description: Scaffold complete fullstack projects with proper structure. Generates package.json, requirements.txt, Dockerfiles, and config files for any framework.
language: any
tags: scaffold, fullstack, project, structure, framework
---
# Fullstack Project Scaffolding
When generating a fullstack application, always produce a complete, runnable project β not just snippets.
## Project structure rules
### Python (Flask/FastAPI/Django/Streamlit/Gradio)
```
project-name/
βββ app.py # Entry point (HF Spaces expects app.py)
βββ requirements.txt # Pinned dependencies
βββ README.md # With HF Space frontmatter if deploying
βββ .env.example # Document required env vars
βββ src/
β βββ __init__.py
β βββ routes/ # API routes
β βββ models/ # Data models
β βββ services/ # Business logic
β βββ utils/ # Helpers
βββ tests/
β βββ test_app.py
βββ static/ # Static assets (if web framework)
```
### Next.js / React (Vite)
```
project-name/
βββ package.json # name, version, scripts, deps
βββ next.config.js # (Next.js only) output: 'standalone'
βββ vite.config.js # (Vite only)
βββ tsconfig.json # (TypeScript)
βββ Dockerfile # Multi-stage build for HF Spaces
βββ .dockerignore
βββ README.md
βββ public/
β βββ (static assets)
βββ src/
βββ app/ # Next.js App Router
βββ pages/ # Next.js Pages Router (legacy)
βββ components/ # Reusable components
βββ lib/ # Utilities, helpers
βββ hooks/ # Custom hooks
βββ styles/ # Global CSS
βββ types/ # TypeScript types
```
### Express / NestJS
```
project-name/
βββ package.json
βββ Dockerfile
βββ .dockerignore
βββ README.md
βββ src/
β βββ index.js # Entry β app.listen(7860, '0.0.0.0')
β βββ routes/
β βββ middleware/
β βββ controllers/ # NestJS only
β βββ services/
β βββ models/
βββ tests/
```
## Port and host rules (critical for HF Spaces)
- All servers MUST listen on `0.0.0.0` (not `localhost` or `127.0.0.1`)
- All servers MUST use port `7860` (HF Spaces default)
- For sub-servers (Gradio subprocess), use 7861, 7862, etc.
## Dockerfile rules
For JS/TS projects, generate a Dockerfile:
- Use `node:20-slim` as base
- Multi-stage build: deps β builder β runner
- For SPAs (React/Vue), serve with nginx on port 7860
- For Next.js, use `output: 'standalone'` and copy `.next/standalone`
- Run as non-root user
For Python projects, the HF Space SDK auto-generates the runtime β no Dockerfile needed unless using Docker SDK.
## package.json rules
- Always include `name`, `version`, `private: true`
- Scripts: `dev`, `build`, `start` (start must bind 0.0.0.0:7860)
- Pin major versions: `"react": "^18.3.0"` not `"react": "latest"`
- Dev dependencies: TypeScript, types, build tools, linters
- Production dependencies: runtime libraries only
## requirements.txt rules
- Pin with `>=` to allow patch updates: `flask>=3.0.0`
- Group by category (web, db, ml, dev) with comments
- Always include the framework (flask, fastapi, gradio, etc.)
- Never include stdlib modules
## README.md rules
For HF Spaces, include frontmatter:
```yaml
---
title: App Name
emoji: π
colorFrom: blue
colorTo: purple
sdk: gradio # or docker, static, streamlit
app_file: app.py # or index.html, Dockerfile
pinned: false
---
```
## Don't include
- `node_modules/`
- `.next/` (build output)
- `__pycache__/`
- `.venv/`, `venv/`
- Lock files (let HF install fresh)
- `.env` (only `.env.example`)
|