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`)