packwise-skills 1.0.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.cursorrules +23 -23
- package/CLAUDE.md +25 -25
- package/LICENSE +21 -0
- package/README.md +404 -295
- package/audit.md +224 -224
- package/bin/packwise.js +322 -155
- package/install.sh +123 -0
- package/package.json +32 -31
- package/skill.md +944 -719
- package/sub-skills/ai/local-llm.md +183 -183
- package/sub-skills/ai/python-ml.md +164 -164
- package/sub-skills/backend/go-server.md +184 -184
- package/sub-skills/backend/java-spring.md +241 -241
- package/sub-skills/backend/node-server.md +164 -164
- package/sub-skills/backend/php-laravel.md +175 -175
- package/sub-skills/backend/python-server.md +164 -164
- package/sub-skills/backend/rust-backend.md +118 -118
- package/sub-skills/cli/python-cli.md +236 -236
- package/sub-skills/cli/sdk-library.md +497 -497
- package/sub-skills/cloud/ci-cd-pipelines.md +350 -350
- package/sub-skills/cloud/docker.md +191 -191
- package/sub-skills/cloud/kubernetes.md +277 -277
- package/sub-skills/cloud/payment-integration.md +307 -307
- package/sub-skills/cross-platform/multiplatform.md +252 -252
- package/sub-skills/desktop/electron.md +783 -783
- package/sub-skills/desktop/game-dev.md +443 -443
- package/sub-skills/desktop/native-app.md +123 -123
- package/sub-skills/desktop/scenarios.md +443 -443
- package/sub-skills/desktop/smart-platforms.md +324 -324
- package/sub-skills/desktop/tauri.md +428 -428
- package/sub-skills/desktop/vr-ar.md +252 -252
- package/sub-skills/desktop/web-to-desktop.md +153 -153
- package/sub-skills/embedded/car-infotainment.md +129 -129
- package/sub-skills/embedded/esp32.md +184 -184
- package/sub-skills/embedded/ros.md +150 -150
- package/sub-skills/embedded/stm32.md +160 -160
- package/sub-skills/mobile/android.md +322 -322
- package/sub-skills/mobile/capacitor.md +232 -232
- package/sub-skills/mobile/flutter-mobile.md +138 -138
- package/sub-skills/mobile/harmonyos.md +150 -150
- package/sub-skills/mobile/ios.md +245 -245
- package/sub-skills/mobile/react-native.md +443 -443
- package/sub-skills/mobile/wearables.md +230 -230
- package/sub-skills/plugins/browser-extension.md +308 -308
- package/sub-skills/plugins/jetbrains-plugin.md +226 -226
- package/sub-skills/plugins/vscode-extension.md +204 -204
- package/sub-skills/security/security-tools.md +174 -174
- package/sub-skills/web/monorepo.md +274 -274
- package/sub-skills/web/pwa.md +220 -220
- package/sub-skills/web/serverless-edge.md +295 -295
- package/sub-skills/web/spa.md +266 -266
- package/sub-skills/web/ssr.md +228 -228
- package/sub-skills/web/wasm.md +243 -243
|
@@ -1,164 +1,164 @@
|
|
|
1
|
-
# Python Backend Build Sub-Skill
|
|
2
|
-
|
|
3
|
-
Build Python backend services (FastAPI/Django/Flask/Litestar).
|
|
4
|
-
|
|
5
|
-
**Current version**: Python 3.12+ / 3.13 (2025-2026)
|
|
6
|
-
|
|
7
|
-
## When to Use
|
|
8
|
-
|
|
9
|
-
- REST API / GraphQL API
|
|
10
|
-
- Web application backend
|
|
11
|
-
- AI/ML model serving
|
|
12
|
-
- Data processing service
|
|
13
|
-
- Research/academic projects
|
|
14
|
-
- Admin panels / internal tools
|
|
15
|
-
|
|
16
|
-
## Framework Quick Start
|
|
17
|
-
|
|
18
|
-
### FastAPI (Recommended for new projects)
|
|
19
|
-
|
|
20
|
-
```python
|
|
21
|
-
from fastapi import FastAPI
|
|
22
|
-
app = FastAPI()
|
|
23
|
-
|
|
24
|
-
@app.get("/health")
|
|
25
|
-
async def health():
|
|
26
|
-
return {"status": "ok"}
|
|
27
|
-
|
|
28
|
-
@app.get("/api/users/{user_id}")
|
|
29
|
-
async def get_user(user_id: int):
|
|
30
|
-
return {"user_id": user_id}
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
```bash
|
|
34
|
-
uvicorn app:app --host 0.0.0.0 --port 8000 --workers 4
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
### Django (Full-featured, batteries-included)
|
|
38
|
-
|
|
39
|
-
```bash
|
|
40
|
-
django-admin startproject myproject
|
|
41
|
-
cd myproject
|
|
42
|
-
python manage.py migrate
|
|
43
|
-
python manage.py collectstatic
|
|
44
|
-
python manage.py runserver
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
### Flask (Lightweight, minimal)
|
|
48
|
-
|
|
49
|
-
```python
|
|
50
|
-
from flask import Flask
|
|
51
|
-
app = Flask(__name__)
|
|
52
|
-
|
|
53
|
-
@app.route("/health")
|
|
54
|
-
def health():
|
|
55
|
-
return {"status": "ok"}
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
### Framework Comparison
|
|
59
|
-
|
|
60
|
-
| Framework | Performance | Async | ORM | Admin | Best For |
|
|
61
|
-
|-----------|------------|-------|-----|-------|---------|
|
|
62
|
-
| FastAPI | Highest | Native | SQLAlchemy | Via admin | APIs, microservices, ML serving |
|
|
63
|
-
| Django | Good | ASGI (since 4.1) | Built-in | Built-in | Full-stack web apps, CMS |
|
|
64
|
-
| Flask | Moderate | Via extensions | SQLAlchemy | Via extensions | Simple APIs, microservices |
|
|
65
|
-
| Litestar | High | Native | SQLAlchemy | Built-in | FastAPI alternative |
|
|
66
|
-
|
|
67
|
-
## Build & Package
|
|
68
|
-
|
|
69
|
-
```bash
|
|
70
|
-
# FastAPI/Flask: run directly, no compilation needed
|
|
71
|
-
# Django:
|
|
72
|
-
python manage.py collectstatic # Collect static files
|
|
73
|
-
python manage.py migrate # Database migration
|
|
74
|
-
|
|
75
|
-
# Production WSGI/ASGI server
|
|
76
|
-
# FastAPI/ASGI:
|
|
77
|
-
pip install uvicorn[standard]
|
|
78
|
-
uvicorn app:app --host 0.0.0.0 --port 8000 --workers 4
|
|
79
|
-
|
|
80
|
-
# Django/Flask/WSGI:
|
|
81
|
-
pip install gunicorn
|
|
82
|
-
gunicorn -w 4 -b 0.0.0.0:8000 myapp.wsgi:application
|
|
83
|
-
|
|
84
|
-
# Gunicorn + Uvicorn workers (async WSGI)
|
|
85
|
-
gunicorn app:app -w 4 -k uvicorn.workers.UvicornWorker -b 0.0.0.0:8000
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
## Docker
|
|
89
|
-
|
|
90
|
-
```dockerfile
|
|
91
|
-
FROM python:3.13-slim AS builder
|
|
92
|
-
WORKDIR /app
|
|
93
|
-
COPY requirements.txt .
|
|
94
|
-
RUN pip install --no-cache-dir --prefix=/install -r requirements.txt
|
|
95
|
-
|
|
96
|
-
FROM python:3.13-slim
|
|
97
|
-
WORKDIR /app
|
|
98
|
-
COPY --from=builder /install /usr/local
|
|
99
|
-
COPY . .
|
|
100
|
-
RUN groupadd -r appuser && useradd -r -g appuser appuser && \
|
|
101
|
-
chown -R appuser:appuser /app
|
|
102
|
-
USER appuser
|
|
103
|
-
EXPOSE 8000
|
|
104
|
-
HEALTHCHECK --interval=30s --timeout=3s CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/health')" || exit 1
|
|
105
|
-
CMD ["gunicorn", "-w", "4", "-k", "uvicorn.workers.UvicornWorker", "-b", "0.0.0.0:8000", "app:app"]
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
## Dependency Management
|
|
109
|
-
|
|
110
|
-
```bash
|
|
111
|
-
# pip + requirements.txt (traditional)
|
|
112
|
-
pip freeze > requirements.txt
|
|
113
|
-
pip install -r requirements.txt
|
|
114
|
-
|
|
115
|
-
# Poetry (recommended for new projects)
|
|
116
|
-
poetry init
|
|
117
|
-
poetry add fastapi uvicorn sqlalchemy
|
|
118
|
-
poetry export -f requirements.txt --output requirements.txt
|
|
119
|
-
|
|
120
|
-
# uv (fastest, Rust-based, pip-compatible)
|
|
121
|
-
pip install uv
|
|
122
|
-
uv pip install fastapi uvicorn
|
|
123
|
-
uv pip compile requirements.in -o requirements.txt
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
## Gunicorn + Nginx
|
|
127
|
-
|
|
128
|
-
```bash
|
|
129
|
-
# Gunicorn (production WSGI server)
|
|
130
|
-
gunicorn -w 4 -b 127.0.0.1:8000 myapp.wsgi:application
|
|
131
|
-
|
|
132
|
-
# Nginx reverse proxy
|
|
133
|
-
# upstream backend { server 127.0.0.1:8000; }
|
|
134
|
-
# server {
|
|
135
|
-
# listen 80;
|
|
136
|
-
# server_name example.com;
|
|
137
|
-
# location / { proxy_pass http://backend; proxy_set_header Host $host; }
|
|
138
|
-
# }
|
|
139
|
-
```
|
|
140
|
-
|
|
141
|
-
## Cloud Platforms
|
|
142
|
-
|
|
143
|
-
| Platform | Method | Best For |
|
|
144
|
-
|----------|--------|---------|
|
|
145
|
-
| Railway | Git push | Quick deploy |
|
|
146
|
-
| Render | Git push | Quick deploy |
|
|
147
|
-
| Fly.io | Docker | Global deploy |
|
|
148
|
-
| AWS Lambda | Mangum (ASGI adapter) | Serverless |
|
|
149
|
-
| Vercel | Serverless Functions | FastAPI (limited) |
|
|
150
|
-
| Aliyun FC | Serverless | China market |
|
|
151
|
-
|
|
152
|
-
## Common Pitfalls
|
|
153
|
-
|
|
154
|
-
| Issue | Fix |
|
|
155
|
-
|-------|-----|
|
|
156
|
-
| Dependency install failure | Pin exact versions; use `pip-compile` for locked deps |
|
|
157
|
-
| Database migration | Run `alembic upgrade head` or `python manage.py migrate` in production |
|
|
158
|
-
| Static files 404 | Nginx serves static files directly; Django: `collectstatic` |
|
|
159
|
-
| Async not working | FastAPI: use `async def`; Django: enable ASGI; Flask: use Quart for async |
|
|
160
|
-
| Python version mismatch | Specify `python:3.13-slim` in Dockerfile; match local and production |
|
|
161
|
-
| `ModuleNotFoundError` | Ensure virtualenv activated; check `sys.path` |
|
|
162
|
-
| WSGI vs ASGI confusion | FastAPI = ASGI (uvicorn); Django = WSGI (gunicorn) or ASGI (uvicorn) |
|
|
163
|
-
| CORS error | FastAPI: `CORSMiddleware`; Django: `django-cors-headers`; Flask: `flask-cors` |
|
|
164
|
-
| Memory leak in workers | Gunicorn: `--max-requests 1000` to restart workers periodically |
|
|
1
|
+
# Python Backend Build Sub-Skill
|
|
2
|
+
|
|
3
|
+
Build Python backend services (FastAPI/Django/Flask/Litestar).
|
|
4
|
+
|
|
5
|
+
**Current version**: Python 3.12+ / 3.13 (2025-2026)
|
|
6
|
+
|
|
7
|
+
## When to Use
|
|
8
|
+
|
|
9
|
+
- REST API / GraphQL API
|
|
10
|
+
- Web application backend
|
|
11
|
+
- AI/ML model serving
|
|
12
|
+
- Data processing service
|
|
13
|
+
- Research/academic projects
|
|
14
|
+
- Admin panels / internal tools
|
|
15
|
+
|
|
16
|
+
## Framework Quick Start
|
|
17
|
+
|
|
18
|
+
### FastAPI (Recommended for new projects)
|
|
19
|
+
|
|
20
|
+
```python
|
|
21
|
+
from fastapi import FastAPI
|
|
22
|
+
app = FastAPI()
|
|
23
|
+
|
|
24
|
+
@app.get("/health")
|
|
25
|
+
async def health():
|
|
26
|
+
return {"status": "ok"}
|
|
27
|
+
|
|
28
|
+
@app.get("/api/users/{user_id}")
|
|
29
|
+
async def get_user(user_id: int):
|
|
30
|
+
return {"user_id": user_id}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
uvicorn app:app --host 0.0.0.0 --port 8000 --workers 4
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Django (Full-featured, batteries-included)
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
django-admin startproject myproject
|
|
41
|
+
cd myproject
|
|
42
|
+
python manage.py migrate
|
|
43
|
+
python manage.py collectstatic
|
|
44
|
+
python manage.py runserver
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Flask (Lightweight, minimal)
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
from flask import Flask
|
|
51
|
+
app = Flask(__name__)
|
|
52
|
+
|
|
53
|
+
@app.route("/health")
|
|
54
|
+
def health():
|
|
55
|
+
return {"status": "ok"}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Framework Comparison
|
|
59
|
+
|
|
60
|
+
| Framework | Performance | Async | ORM | Admin | Best For |
|
|
61
|
+
|-----------|------------|-------|-----|-------|---------|
|
|
62
|
+
| FastAPI | Highest | Native | SQLAlchemy | Via admin | APIs, microservices, ML serving |
|
|
63
|
+
| Django | Good | ASGI (since 4.1) | Built-in | Built-in | Full-stack web apps, CMS |
|
|
64
|
+
| Flask | Moderate | Via extensions | SQLAlchemy | Via extensions | Simple APIs, microservices |
|
|
65
|
+
| Litestar | High | Native | SQLAlchemy | Built-in | FastAPI alternative |
|
|
66
|
+
|
|
67
|
+
## Build & Package
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
# FastAPI/Flask: run directly, no compilation needed
|
|
71
|
+
# Django:
|
|
72
|
+
python manage.py collectstatic # Collect static files
|
|
73
|
+
python manage.py migrate # Database migration
|
|
74
|
+
|
|
75
|
+
# Production WSGI/ASGI server
|
|
76
|
+
# FastAPI/ASGI:
|
|
77
|
+
pip install uvicorn[standard]
|
|
78
|
+
uvicorn app:app --host 0.0.0.0 --port 8000 --workers 4
|
|
79
|
+
|
|
80
|
+
# Django/Flask/WSGI:
|
|
81
|
+
pip install gunicorn
|
|
82
|
+
gunicorn -w 4 -b 0.0.0.0:8000 myapp.wsgi:application
|
|
83
|
+
|
|
84
|
+
# Gunicorn + Uvicorn workers (async WSGI)
|
|
85
|
+
gunicorn app:app -w 4 -k uvicorn.workers.UvicornWorker -b 0.0.0.0:8000
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Docker
|
|
89
|
+
|
|
90
|
+
```dockerfile
|
|
91
|
+
FROM python:3.13-slim AS builder
|
|
92
|
+
WORKDIR /app
|
|
93
|
+
COPY requirements.txt .
|
|
94
|
+
RUN pip install --no-cache-dir --prefix=/install -r requirements.txt
|
|
95
|
+
|
|
96
|
+
FROM python:3.13-slim
|
|
97
|
+
WORKDIR /app
|
|
98
|
+
COPY --from=builder /install /usr/local
|
|
99
|
+
COPY . .
|
|
100
|
+
RUN groupadd -r appuser && useradd -r -g appuser appuser && \
|
|
101
|
+
chown -R appuser:appuser /app
|
|
102
|
+
USER appuser
|
|
103
|
+
EXPOSE 8000
|
|
104
|
+
HEALTHCHECK --interval=30s --timeout=3s CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/health')" || exit 1
|
|
105
|
+
CMD ["gunicorn", "-w", "4", "-k", "uvicorn.workers.UvicornWorker", "-b", "0.0.0.0:8000", "app:app"]
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Dependency Management
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
# pip + requirements.txt (traditional)
|
|
112
|
+
pip freeze > requirements.txt
|
|
113
|
+
pip install -r requirements.txt
|
|
114
|
+
|
|
115
|
+
# Poetry (recommended for new projects)
|
|
116
|
+
poetry init
|
|
117
|
+
poetry add fastapi uvicorn sqlalchemy
|
|
118
|
+
poetry export -f requirements.txt --output requirements.txt
|
|
119
|
+
|
|
120
|
+
# uv (fastest, Rust-based, pip-compatible)
|
|
121
|
+
pip install uv
|
|
122
|
+
uv pip install fastapi uvicorn
|
|
123
|
+
uv pip compile requirements.in -o requirements.txt
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Gunicorn + Nginx
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
# Gunicorn (production WSGI server)
|
|
130
|
+
gunicorn -w 4 -b 127.0.0.1:8000 myapp.wsgi:application
|
|
131
|
+
|
|
132
|
+
# Nginx reverse proxy
|
|
133
|
+
# upstream backend { server 127.0.0.1:8000; }
|
|
134
|
+
# server {
|
|
135
|
+
# listen 80;
|
|
136
|
+
# server_name example.com;
|
|
137
|
+
# location / { proxy_pass http://backend; proxy_set_header Host $host; }
|
|
138
|
+
# }
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Cloud Platforms
|
|
142
|
+
|
|
143
|
+
| Platform | Method | Best For |
|
|
144
|
+
|----------|--------|---------|
|
|
145
|
+
| Railway | Git push | Quick deploy |
|
|
146
|
+
| Render | Git push | Quick deploy |
|
|
147
|
+
| Fly.io | Docker | Global deploy |
|
|
148
|
+
| AWS Lambda | Mangum (ASGI adapter) | Serverless |
|
|
149
|
+
| Vercel | Serverless Functions | FastAPI (limited) |
|
|
150
|
+
| Aliyun FC | Serverless | China market |
|
|
151
|
+
|
|
152
|
+
## Common Pitfalls
|
|
153
|
+
|
|
154
|
+
| Issue | Fix |
|
|
155
|
+
|-------|-----|
|
|
156
|
+
| Dependency install failure | Pin exact versions; use `pip-compile` for locked deps |
|
|
157
|
+
| Database migration | Run `alembic upgrade head` or `python manage.py migrate` in production |
|
|
158
|
+
| Static files 404 | Nginx serves static files directly; Django: `collectstatic` |
|
|
159
|
+
| Async not working | FastAPI: use `async def`; Django: enable ASGI; Flask: use Quart for async |
|
|
160
|
+
| Python version mismatch | Specify `python:3.13-slim` in Dockerfile; match local and production |
|
|
161
|
+
| `ModuleNotFoundError` | Ensure virtualenv activated; check `sys.path` |
|
|
162
|
+
| WSGI vs ASGI confusion | FastAPI = ASGI (uvicorn); Django = WSGI (gunicorn) or ASGI (uvicorn) |
|
|
163
|
+
| CORS error | FastAPI: `CORSMiddleware`; Django: `django-cors-headers`; Flask: `flask-cors` |
|
|
164
|
+
| Memory leak in workers | Gunicorn: `--max-requests 1000` to restart workers periodically |
|
|
@@ -1,118 +1,118 @@
|
|
|
1
|
-
# Rust Backend Build Sub-Skill
|
|
2
|
-
|
|
3
|
-
Build and package Rust backend services (Axum/Actix-Web/Rocket/Warp).
|
|
4
|
-
|
|
5
|
-
**Current version**: Rust 1.82+ / Axum 0.7 / Actix-Web 4.x (2025-2026)
|
|
6
|
-
|
|
7
|
-
## When to Use
|
|
8
|
-
|
|
9
|
-
- High-performance API services
|
|
10
|
-
- Microservices requiring low latency and minimal memory
|
|
11
|
-
- WebSocket servers
|
|
12
|
-
- System-level services (CLI backends, daemons)
|
|
13
|
-
- Security-sensitive backends (memory safety guaranteed by compiler)
|
|
14
|
-
|
|
15
|
-
## Build
|
|
16
|
-
|
|
17
|
-
```bash
|
|
18
|
-
# Standard build
|
|
19
|
-
cargo build --release
|
|
20
|
-
# Output: target/release/myapp
|
|
21
|
-
|
|
22
|
-
# With version embedding
|
|
23
|
-
cargo build --release
|
|
24
|
-
# In build.rs:
|
|
25
|
-
# println!("cargo:rustc-env=APP_VERSION={}", env!("CARGO_PKG_VERSION"));
|
|
26
|
-
|
|
27
|
-
# Static binary (no system dependencies)
|
|
28
|
-
RUSTFLAGS='-C target-feature=+crt-static' cargo build --release --target x86_64-unknown-linux-gnu
|
|
29
|
-
|
|
30
|
-
# Cross-compile
|
|
31
|
-
cargo install cross
|
|
32
|
-
cross build --release --target x86_64-unknown-linux-gnu
|
|
33
|
-
cross build --release --target aarch64-unknown-linux-gnu
|
|
34
|
-
cross build --release --target x86_64-pc-windows-gnu
|
|
35
|
-
cross build --release --target x86_64-apple-darwin
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
## Framework Quick Start
|
|
39
|
-
|
|
40
|
-
### Axum (Recommended — Tokio team)
|
|
41
|
-
|
|
42
|
-
```rust
|
|
43
|
-
use axum::{routing::get, Router};
|
|
44
|
-
use std::net::SocketAddr;
|
|
45
|
-
|
|
46
|
-
#[tokio::main]
|
|
47
|
-
async fn main() {
|
|
48
|
-
let app = Router::new()
|
|
49
|
-
.route("/", get(|| async { "Hello, World!" }))
|
|
50
|
-
.route("/health", get(|| async { "OK" }));
|
|
51
|
-
|
|
52
|
-
let addr = SocketAddr::from(([0, 0, 0, 0], 8080));
|
|
53
|
-
axum::serve(tokio::net::TcpListener::bind(addr).await.unwrap(), app)
|
|
54
|
-
.await
|
|
55
|
-
.unwrap();
|
|
56
|
-
}
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
### Actix-Web (Highest raw performance)
|
|
60
|
-
|
|
61
|
-
```rust
|
|
62
|
-
use actix_web::{web, App, HttpServer, HttpResponse};
|
|
63
|
-
|
|
64
|
-
#[actix_web::main]
|
|
65
|
-
async fn main() -> std::io::Result<()> {
|
|
66
|
-
HttpServer::new(|| {
|
|
67
|
-
App::new()
|
|
68
|
-
.route("/", web::get().to(|| async { HttpResponse::Ok().body("Hello!") }))
|
|
69
|
-
.route("/health", web::get().to(|| async { HttpResponse::Ok().body("OK") }))
|
|
70
|
-
})
|
|
71
|
-
.bind("0.0.0.0:8080")?
|
|
72
|
-
.run()
|
|
73
|
-
.await
|
|
74
|
-
}
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
## Docker
|
|
78
|
-
|
|
79
|
-
```dockerfile
|
|
80
|
-
FROM rust:1.82-slim AS builder
|
|
81
|
-
WORKDIR /app
|
|
82
|
-
COPY Cargo.toml Cargo.lock ./
|
|
83
|
-
# Cache dependencies (create dummy src)
|
|
84
|
-
RUN mkdir src && echo 'fn main(){}' > src/main.rs && cargo build --release && rm -rf src
|
|
85
|
-
COPY src/ src/
|
|
86
|
-
RUN touch src/main.rs && cargo build --release
|
|
87
|
-
|
|
88
|
-
FROM debian:bookworm-slim
|
|
89
|
-
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates && \
|
|
90
|
-
rm -rf /var/lib/apt/lists/* && \
|
|
91
|
-
groupadd -r appuser && useradd -r -g appuser appuser
|
|
92
|
-
COPY --from=builder /app/target/release/myapp /myapp
|
|
93
|
-
USER appuser
|
|
94
|
-
EXPOSE 8080
|
|
95
|
-
HEALTHCHECK --interval=30s --timeout=3s CMD curl -f http://localhost:8080/health || exit 1
|
|
96
|
-
CMD ["/myapp"]
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
## Selection Guide
|
|
100
|
-
|
|
101
|
-
| Framework | Async Runtime | Performance | Ecosystem | Best For |
|
|
102
|
-
|-----------|--------------|-------------|-----------|----------|
|
|
103
|
-
| Axum | Tokio | High | Growing fast | New projects, middleware-heavy |
|
|
104
|
-
| Actix-Web | Tokio | Highest | Mature | Maximum throughput |
|
|
105
|
-
| Rocket | Tokio | High | Good | Rapid prototyping, ergonomic API |
|
|
106
|
-
| Warp | Tokio | High | Smaller | Filter-based routing |
|
|
107
|
-
| Poem | Tokio | High | Growing | OpenAPI integration |
|
|
108
|
-
|
|
109
|
-
## Common Pitfalls
|
|
110
|
-
|
|
111
|
-
| Issue | Fix |
|
|
112
|
-
|-------|-----|
|
|
113
|
-
| Binary too large | Use `strip = true` in Cargo.toml `[profile.release]`; use `upx --best` |
|
|
114
|
-
| Slow compile | Use `sccache`; enable incremental compilation; reduce dependencies |
|
|
115
|
-
| Cross-compile fails | Use `cross` tool; or Docker-based cross-compilation |
|
|
116
|
-
| `openssl` build fails | Use `rustls` (pure Rust TLS) instead of native OpenSSL |
|
|
117
|
-
| Missing system libs in Docker | Use `debian:bookworm-slim` (not `alpine`) for glibc compatibility |
|
|
118
|
-
| Static linking issues | Use `x86_64-unknown-linux-musl` target for fully static binary |
|
|
1
|
+
# Rust Backend Build Sub-Skill
|
|
2
|
+
|
|
3
|
+
Build and package Rust backend services (Axum/Actix-Web/Rocket/Warp).
|
|
4
|
+
|
|
5
|
+
**Current version**: Rust 1.82+ / Axum 0.7 / Actix-Web 4.x (2025-2026)
|
|
6
|
+
|
|
7
|
+
## When to Use
|
|
8
|
+
|
|
9
|
+
- High-performance API services
|
|
10
|
+
- Microservices requiring low latency and minimal memory
|
|
11
|
+
- WebSocket servers
|
|
12
|
+
- System-level services (CLI backends, daemons)
|
|
13
|
+
- Security-sensitive backends (memory safety guaranteed by compiler)
|
|
14
|
+
|
|
15
|
+
## Build
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
# Standard build
|
|
19
|
+
cargo build --release
|
|
20
|
+
# Output: target/release/myapp
|
|
21
|
+
|
|
22
|
+
# With version embedding
|
|
23
|
+
cargo build --release
|
|
24
|
+
# In build.rs:
|
|
25
|
+
# println!("cargo:rustc-env=APP_VERSION={}", env!("CARGO_PKG_VERSION"));
|
|
26
|
+
|
|
27
|
+
# Static binary (no system dependencies)
|
|
28
|
+
RUSTFLAGS='-C target-feature=+crt-static' cargo build --release --target x86_64-unknown-linux-gnu
|
|
29
|
+
|
|
30
|
+
# Cross-compile
|
|
31
|
+
cargo install cross
|
|
32
|
+
cross build --release --target x86_64-unknown-linux-gnu
|
|
33
|
+
cross build --release --target aarch64-unknown-linux-gnu
|
|
34
|
+
cross build --release --target x86_64-pc-windows-gnu
|
|
35
|
+
cross build --release --target x86_64-apple-darwin
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Framework Quick Start
|
|
39
|
+
|
|
40
|
+
### Axum (Recommended — Tokio team)
|
|
41
|
+
|
|
42
|
+
```rust
|
|
43
|
+
use axum::{routing::get, Router};
|
|
44
|
+
use std::net::SocketAddr;
|
|
45
|
+
|
|
46
|
+
#[tokio::main]
|
|
47
|
+
async fn main() {
|
|
48
|
+
let app = Router::new()
|
|
49
|
+
.route("/", get(|| async { "Hello, World!" }))
|
|
50
|
+
.route("/health", get(|| async { "OK" }));
|
|
51
|
+
|
|
52
|
+
let addr = SocketAddr::from(([0, 0, 0, 0], 8080));
|
|
53
|
+
axum::serve(tokio::net::TcpListener::bind(addr).await.unwrap(), app)
|
|
54
|
+
.await
|
|
55
|
+
.unwrap();
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Actix-Web (Highest raw performance)
|
|
60
|
+
|
|
61
|
+
```rust
|
|
62
|
+
use actix_web::{web, App, HttpServer, HttpResponse};
|
|
63
|
+
|
|
64
|
+
#[actix_web::main]
|
|
65
|
+
async fn main() -> std::io::Result<()> {
|
|
66
|
+
HttpServer::new(|| {
|
|
67
|
+
App::new()
|
|
68
|
+
.route("/", web::get().to(|| async { HttpResponse::Ok().body("Hello!") }))
|
|
69
|
+
.route("/health", web::get().to(|| async { HttpResponse::Ok().body("OK") }))
|
|
70
|
+
})
|
|
71
|
+
.bind("0.0.0.0:8080")?
|
|
72
|
+
.run()
|
|
73
|
+
.await
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Docker
|
|
78
|
+
|
|
79
|
+
```dockerfile
|
|
80
|
+
FROM rust:1.82-slim AS builder
|
|
81
|
+
WORKDIR /app
|
|
82
|
+
COPY Cargo.toml Cargo.lock ./
|
|
83
|
+
# Cache dependencies (create dummy src)
|
|
84
|
+
RUN mkdir src && echo 'fn main(){}' > src/main.rs && cargo build --release && rm -rf src
|
|
85
|
+
COPY src/ src/
|
|
86
|
+
RUN touch src/main.rs && cargo build --release
|
|
87
|
+
|
|
88
|
+
FROM debian:bookworm-slim
|
|
89
|
+
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates && \
|
|
90
|
+
rm -rf /var/lib/apt/lists/* && \
|
|
91
|
+
groupadd -r appuser && useradd -r -g appuser appuser
|
|
92
|
+
COPY --from=builder /app/target/release/myapp /myapp
|
|
93
|
+
USER appuser
|
|
94
|
+
EXPOSE 8080
|
|
95
|
+
HEALTHCHECK --interval=30s --timeout=3s CMD curl -f http://localhost:8080/health || exit 1
|
|
96
|
+
CMD ["/myapp"]
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Selection Guide
|
|
100
|
+
|
|
101
|
+
| Framework | Async Runtime | Performance | Ecosystem | Best For |
|
|
102
|
+
|-----------|--------------|-------------|-----------|----------|
|
|
103
|
+
| Axum | Tokio | High | Growing fast | New projects, middleware-heavy |
|
|
104
|
+
| Actix-Web | Tokio | Highest | Mature | Maximum throughput |
|
|
105
|
+
| Rocket | Tokio | High | Good | Rapid prototyping, ergonomic API |
|
|
106
|
+
| Warp | Tokio | High | Smaller | Filter-based routing |
|
|
107
|
+
| Poem | Tokio | High | Growing | OpenAPI integration |
|
|
108
|
+
|
|
109
|
+
## Common Pitfalls
|
|
110
|
+
|
|
111
|
+
| Issue | Fix |
|
|
112
|
+
|-------|-----|
|
|
113
|
+
| Binary too large | Use `strip = true` in Cargo.toml `[profile.release]`; use `upx --best` |
|
|
114
|
+
| Slow compile | Use `sccache`; enable incremental compilation; reduce dependencies |
|
|
115
|
+
| Cross-compile fails | Use `cross` tool; or Docker-based cross-compilation |
|
|
116
|
+
| `openssl` build fails | Use `rustls` (pure Rust TLS) instead of native OpenSSL |
|
|
117
|
+
| Missing system libs in Docker | Use `debian:bookworm-slim` (not `alpine`) for glibc compatibility |
|
|
118
|
+
| Static linking issues | Use `x86_64-unknown-linux-musl` target for fully static binary |
|