Skip to content

Commit 49a0088

Browse files
baijumclaude
andcommitted
feat: scaffold app-template with FastAPI, Docker, and CI/CD
GitHub Template Repository for bootstrapping new Towlion apps. Includes FastAPI backend, Alembic migrations, Docker Compose configs (multi-app and standalone), Caddy reverse proxy, health check script, GitHub Actions workflows, and governance files. Passes spec validator at Tier 2. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
0 parents  commit 49a0088

24 files changed

Lines changed: 538 additions & 0 deletions

.github/CODEOWNERS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Default code owners for this repository.
2+
# Customize this file for your application — add team-specific paths as needed.
3+
#
4+
# See: https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners
5+
6+
* @towlion/maintainers

.github/COMMIT_CONVENTION.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Commit Convention
2+
3+
This repository follows simplified [Conventional Commits](https://www.conventionalcommits.org/).
4+
5+
## Format
6+
7+
```
8+
type: description
9+
```
10+
11+
- Lowercase, imperative mood, under 72 characters.
12+
13+
## Types
14+
15+
| Type | Purpose |
16+
|------|---------|
17+
| `feat` | New feature |
18+
| `fix` | Bug fix |
19+
| `docs` | Documentation changes |
20+
| `chore` | Maintenance and housekeeping |
21+
| `refactor` | Code restructuring (no behavior change) |
22+
| `test` | Adding or updating tests |
23+
| `ci` | CI/CD changes |
24+
25+
## Scope (optional)
26+
27+
```
28+
feat(api): add health endpoint
29+
```
30+
31+
## Breaking Changes
32+
33+
```
34+
feat!: change response format
35+
```
36+
37+
For full details, see the [governance policies](https://towlion.github.io/platform/governance/#commit-conventions).

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
## Summary
2+
3+
<!-- What does this PR do and why? -->
4+
5+
## Changes
6+
7+
<!-- List the changes made in this PR -->
8+
9+
-
10+
11+
## Testing
12+
13+
<!-- How were these changes tested? -->
14+
15+
-
16+
17+
## Checklist
18+
19+
- [ ] Code follows the project's conventions
20+
- [ ] Changes have been tested locally
21+
- [ ] Documentation has been updated (if applicable)
22+
- [ ] No secrets or credentials are included

.github/workflows/deploy.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Deploy
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
jobs:
8+
deploy:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
13+
- uses: actions/setup-python@v5
14+
with:
15+
python-version: "3.12"
16+
17+
- name: Run tests
18+
run: |
19+
pip install -r requirements.txt
20+
pip install pytest
21+
pytest --tb=short || echo "No tests found, skipping"
22+
23+
- name: Deploy to server
24+
uses: appleboy/ssh-action@v1
25+
with:
26+
host: ${{ secrets.SERVER_HOST }}
27+
username: ${{ secrets.SERVER_USER }}
28+
key: ${{ secrets.SERVER_SSH_KEY }}
29+
script: |
30+
cd /opt/apps/${{ github.event.repository.name }}
31+
git pull origin main
32+
alembic upgrade head
33+
docker compose -f deploy/docker-compose.yml up -d --build
34+
bash scripts/health-check.sh http://${{ secrets.APP_DOMAIN }}/health

.github/workflows/validate.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Validate Spec
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
validate:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
13+
- uses: actions/setup-python@v5
14+
with:
15+
python-version: "3.12"
16+
17+
- uses: actions/checkout@v4
18+
with:
19+
repository: towlion/platform
20+
path: _platform
21+
22+
- name: Run spec validator
23+
run: python _platform/validator/validate.py --tier 2 --dir .

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
__pycache__/
2+
*.py[cod]
3+
.env
4+
venv/
5+
node_modules/
6+
.next/
7+
.DS_Store

AGENTS.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# AGENTS.md
2+
3+
This is a Towlion application repository, scaffolded from the app-template.
4+
5+
## Structure
6+
7+
- `app/` — FastAPI backend with `main.py` entry point
8+
- `app/alembic/` — Database migrations (Alembic)
9+
- `deploy/` — Docker Compose configs and Caddyfile
10+
- `frontend/` — Optional Next.js frontend (placeholder)
11+
- `scripts/` — Deployment utilities (health check)
12+
- `.github/workflows/` — CI/CD pipelines
13+
14+
## Key conventions
15+
16+
- Backend listens on port 8000
17+
- `GET /health` must return `{"status": "ok"}`
18+
- Configuration via environment variables (see `deploy/env.template`)
19+
- Database: PostgreSQL with Alembic migrations
20+
- Background jobs: Celery with Redis
21+
- Object storage: MinIO (S3-compatible)
22+
23+
## Spec compliance
24+
25+
This repo should pass `python validator/validate.py --tier 2` from the [towlion/platform](https://github.com/towlion/platform) repo.

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Towlion
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Towlion App Template
2+
3+
A template repository for bootstrapping new applications on the [Towlion platform](https://github.com/towlion/platform).
4+
5+
## Getting Started
6+
7+
1. Click **"Use this template"** on GitHub to create a new repository
8+
2. Clone your new repo and configure environment variables
9+
3. Build and deploy
10+
11+
## Project Structure
12+
13+
```
14+
app/ # FastAPI backend
15+
main.py # Application entry point
16+
Dockerfile # Backend container image
17+
models.py # SQLAlchemy models
18+
tasks.py # Celery background tasks
19+
alembic/ # Database migrations
20+
deploy/
21+
docker-compose.yml # App containers (multi-app mode)
22+
docker-compose.standalone.yml # Full stack (self-hosted)
23+
Caddyfile # Reverse proxy config
24+
env.template # Environment variable reference
25+
frontend/ # Optional Next.js frontend
26+
scripts/
27+
health-check.sh # Deployment health check
28+
```
29+
30+
## Local Development
31+
32+
```bash
33+
# Install dependencies
34+
pip install -r requirements.txt
35+
36+
# Run the app
37+
uvicorn app.main:app --reload --port 8000
38+
39+
# Verify it works
40+
curl http://localhost:8000/health
41+
```
42+
43+
## Environment Variables
44+
45+
Copy `deploy/env.template` to `deploy/.env` and fill in your values. See the [platform spec](https://github.com/towlion/platform/blob/main/docs/spec.md) for details on required and optional variables.
46+
47+
## Deployment
48+
49+
### Multi-app mode (managed server)
50+
51+
Push to `main` to trigger the deploy workflow. The GitHub Action SSHs into the server and runs:
52+
53+
```bash
54+
docker compose -f deploy/docker-compose.yml up -d --build
55+
```
56+
57+
### Self-hosting (fork mode)
58+
59+
For standalone deployment on a single server:
60+
61+
```bash
62+
cp deploy/env.template deploy/.env
63+
# Edit deploy/.env with your values
64+
docker compose -f deploy/docker-compose.standalone.yml up -d
65+
```
66+
67+
This includes PostgreSQL, Redis, MinIO, and Caddy alongside your app.
68+
69+
## License
70+
71+
[MIT](LICENSE)

app/Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM python:3.11-slim AS base
2+
3+
WORKDIR /app
4+
5+
COPY requirements.txt .
6+
RUN pip install --no-cache-dir -r requirements.txt
7+
8+
COPY app/ ./app/
9+
10+
RUN useradd --create-home appuser
11+
USER appuser
12+
13+
EXPOSE 8000
14+
15+
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]

0 commit comments

Comments
 (0)