Skip to content

Commit 943a105

Browse files
committed
FastSaas structure
0 parents  commit 943a105

70 files changed

Lines changed: 842 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/test.yml

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches: [ main, develop ]
6+
pull_request:
7+
branches: [ main, develop ]
8+
9+
jobs:
10+
backend-tests:
11+
runs-on: ubuntu-latest
12+
13+
services:
14+
postgres:
15+
image: postgres:13
16+
env:
17+
POSTGRES_PASSWORD: changethis
18+
POSTGRES_USER: postgres
19+
POSTGRES_DB: app
20+
ports:
21+
- 5432:5432
22+
options: >-
23+
--health-cmd pg_isready
24+
--health-interval 10s
25+
--health-timeout 5s
26+
--health-retries 5
27+
28+
steps:
29+
- uses: actions/checkout@v4
30+
31+
- name: Install uv
32+
uses: astral-sh/setup-uv@v3
33+
with:
34+
version: "latest"
35+
36+
- name: Set up Python
37+
uses: actions/setup-python@v5
38+
with:
39+
python-version: "3.11"
40+
41+
- name: Install dependencies
42+
run: uv sync
43+
44+
- name: Run database migrations
45+
run: uv run alembic upgrade head
46+
env:
47+
POSTGRES_USER: postgres
48+
POSTGRES_PASSWORD: changethis
49+
POSTGRES_SERVER: localhost
50+
POSTGRES_PORT: 5432
51+
POSTGRES_DB: app
52+
53+
- name: Run backend tests
54+
run: uv run pytest app/tests/ -v
55+
env:
56+
SECRET_KEY: test-secret-key-minimum-32-characters-long
57+
FIRST_SUPERUSER_EMAIL: admin@example.com
58+
FIRST_SUPERUSER_PASSWORD: changethis
59+
POSTGRES_USER: postgres
60+
POSTGRES_PASSWORD: changethis
61+
POSTGRES_SERVER: localhost
62+
POSTGRES_PORT: 5432
63+
POSTGRES_DB: app
64+
65+
lint:
66+
runs-on: ubuntu-latest
67+
68+
steps:
69+
- uses: actions/checkout@v4
70+
71+
- name: Install uv
72+
uses: astral-sh/setup-uv@v3
73+
with:
74+
version: "latest"
75+
76+
- name: Set up Python
77+
uses: actions/setup-python@v5
78+
with:
79+
python-version: "3.11"
80+
81+
- name: Install dependencies
82+
run: uv sync
83+
84+
- name: Run mypy
85+
run: uv run mypy app
86+
87+
- name: Run ruff check
88+
run: uv run ruff check app
89+
90+
- name: Run ruff format check
91+
run: uv run ruff format --check app

Makefile

Lines changed: 234 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
# =============================================================================
2+
# FastSaaS Development Makefile
3+
# =============================================================================
4+
# Quick setup: make setup
5+
# Full setup: make setup-full
6+
7+
.PHONY: help setup setup-full check-prereqs setup-env setup-secrets install-deps dev-up dev-down
8+
.PHONY: test test-backend test-frontend lint format clean migrate logs db-shell db-reset
9+
.PHONY: build-backend build-frontend build-all deploy-staging deploy-prod
10+
11+
# Default target
12+
help: ## Show this help message
13+
@echo "FastSaaS Development Environment"
14+
@echo "================================"
15+
@echo ""
16+
@echo "Quick Start Commands:"
17+
@echo " make setup - Complete project setup for new developers"
18+
@echo " make setup-full - Full setup with dependency installation"
19+
@echo " make dev - Start development environment"
20+
@echo ""
21+
@echo "Development Commands:"
22+
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
23+
24+
# =============================================================================
25+
# Setup Commands
26+
# =============================================================================
27+
28+
setup: check-prereqs setup-env install-deps dev-up setup-complete ## Complete project setup (recommended for new developers)
29+
30+
setup-full: check-prereqs setup-env setup-secrets install-deps dev-up migrate setup-complete ## Full setup including secrets generation and migrations
31+
32+
check-prereqs: ## Check if required tools are installed
33+
@echo "🔍 Checking prerequisites..."
34+
@command -v docker >/dev/null 2>&1 || { echo "❌ Docker is required but not installed. Please install Docker and try again."; exit 1; }
35+
@command -v docker compose >/dev/null 2>&1 || { echo "❌ Docker Compose is required but not installed. Please install Docker Compose and try again."; exit 1; }
36+
@command -v uv >/dev/null 2>&1 || { echo "❌ uv is required but not installed. Please install uv (https://docs.astral.sh/uv/) and try again."; exit 1; }
37+
@command -v node >/dev/null 2>&1 || { echo "❌ Node.js is required but not installed. Please install Node.js and try again."; exit 1; }
38+
@echo "✅ All prerequisites are installed!"
39+
40+
setup-env: ## Set up environment files from templates
41+
@echo "⚙️ Setting up environment files..."
42+
@if [ ! -f .env ]; then \
43+
cp .env.example .env; \
44+
echo "📝 Created .env from .env.example"; \
45+
else \
46+
echo "⚠️ .env already exists, skipping..."; \
47+
fi
48+
@if [ ! -f frontend/.env ]; then \
49+
cp frontend/.env.example frontend/.env; \
50+
echo "📝 Created frontend/.env from frontend/.env.example"; \
51+
else \
52+
echo "⚠️ frontend/.env already exists, skipping..."; \
53+
fi
54+
@echo "⚠️ Remember to update the following in .env for production:"
55+
@echo " - SECRET_KEY (run: make generate-secret)"
56+
@echo " - POSTGRES_PASSWORD (run: make generate-secret)"
57+
@echo " - FIRST_SUPERUSER_PASSWORD"
58+
@echo " - Stripe keys (STRIPE_SECRET_KEY, STRIPE_PUBLISHABLE_KEY)"
59+
@echo " - Email service settings"
60+
61+
setup-secrets: ## Generate secure secrets for .env file
62+
@echo "🔐 Generating secure secrets..."
63+
@echo "SECRET_KEY=$$(python3 -c 'import secrets; print(secrets.token_urlsafe(32))')"
64+
@echo "POSTGRES_PASSWORD=$$(python3 -c 'import secrets; print(secrets.token_urlsafe(16))')"
65+
@echo "FIRST_SUPERUSER_PASSWORD=$$(python3 -c 'import secrets; print(secrets.token_urlsafe(12))')"
66+
@echo ""
67+
@echo "📝 Copy these values to your .env file!"
68+
69+
generate-secret: ## Generate a single secret key
70+
@python3 -c "import secrets; print(secrets.token_urlsafe(32))"
71+
72+
setup-complete: ## Show setup completion message
73+
@echo ""
74+
@echo "🎉 Setup Complete!"
75+
@echo "=================="
76+
@echo ""
77+
@echo "Your FastSaaS development environment is ready!"
78+
@echo ""
79+
@echo "URLs:"
80+
@echo " Frontend: http://localhost:5173"
81+
@echo " Backend API: http://localhost:8000"
82+
@echo " API Docs: http://localhost:8000/docs"
83+
@echo " Database UI: http://localhost:8080"
84+
@echo ""
85+
@echo "Next Steps:"
86+
@echo " 1. Update .env with your Stripe keys and email settings"
87+
@echo " 2. Run 'make migrate' to set up the database"
88+
@echo " 3. Run 'make logs' to monitor the application"
89+
@echo " 4. Visit http://localhost:5173 to see your app!"
90+
@echo ""
91+
92+
# =============================================================================
93+
# Development Environment
94+
# =============================================================================
95+
96+
install-deps: install-backend-deps install-frontend-deps ## Install all dependencies
97+
98+
install-backend-deps: ## Install Python backend dependencies
99+
@echo "📦 Installing backend dependencies..."
100+
@uv sync
101+
102+
install-frontend-deps: ## Install Node.js frontend dependencies
103+
@echo "📦 Installing frontend dependencies..."
104+
@cd frontend && npm install
105+
106+
dev: dev-up ## Start development environment (alias for dev-up)
107+
108+
dev-up: ## Start development environment with Docker Compose
109+
@echo "🚀 Starting development environment..."
110+
@docker compose watch
111+
112+
dev-down: ## Stop development environment
113+
@echo "🛑 Stopping development environment..."
114+
@docker compose down
115+
116+
dev-restart: dev-down dev-up ## Restart development environment
117+
118+
logs: ## Show logs from all services
119+
@docker compose logs -f
120+
121+
logs-backend: ## Show backend logs only
122+
@docker compose logs -f backend
123+
124+
logs-frontend: ## Show frontend logs only
125+
@docker compose logs -f frontend
126+
127+
logs-db: ## Show database logs only
128+
@docker compose logs -f db
129+
130+
# =============================================================================
131+
# Database Management
132+
# =============================================================================
133+
134+
migrate: ## Run database migrations
135+
@echo "🗄️ Running database migrations..."
136+
@uv run alembic upgrade head
137+
138+
migrate-create: ## Create a new migration (usage: make migrate-create msg="your message")
139+
@if [ -z "$(msg)" ]; then \
140+
echo "❌ Please provide a message: make migrate-create msg='your message'"; \
141+
exit 1; \
142+
fi
143+
@echo "📝 Creating new migration: $(msg)"
144+
@uv run alembic revision --autogenerate -m "$(msg)"
145+
146+
migrate-rollback: ## Rollback one migration
147+
@echo "↩️ Rolling back one migration..."
148+
@uv run alembic downgrade -1
149+
150+
db-shell: ## Connect to database shell
151+
@echo "🔗 Connecting to database..."
152+
@docker compose exec db psql -U postgres -d app
153+
154+
db-reset: ## Reset database (WARNING: destroys all data)
155+
@echo "⚠️ WARNING: This will destroy all database data!"
156+
@read -p "Are you sure? Type 'yes' to continue: " confirm; \
157+
if [ "$$confirm" = "yes" ]; then \
158+
docker compose down; \
159+
docker volume rm $$(docker volume ls -q | grep postgres) 2>/dev/null || true; \
160+
docker compose up -d db; \
161+
sleep 5; \
162+
make migrate; \
163+
echo "✅ Database reset complete!"; \
164+
else \
165+
echo "❌ Database reset cancelled."; \
166+
fi
167+
168+
# =============================================================================
169+
# Testing
170+
# =============================================================================
171+
172+
tests: test-backend-simple
173+
174+
test-backend-simple: ## Run backend tests without coverage
175+
@echo "🧪 Running backend tests (simple)..."
176+
@uv run pytest
177+
178+
test-frontend: ## Run frontend tests (if configured)
179+
@echo "🧪 Running frontend tests..."
180+
@cd frontend && npm test
181+
182+
# =============================================================================
183+
# Code Quality
184+
# =============================================================================
185+
186+
lint: lint-backend lint-frontend ## Run linting on all code
187+
188+
lint-backend: ## Run backend linting (mypy + ruff)
189+
@echo "🔍 Running backend linting..."
190+
@uv run mypy app
191+
@uv run ruff check app
192+
193+
lint-frontend: ## Run frontend linting
194+
@echo "🔍 Running frontend linting..."
195+
@cd frontend && npm run lint
196+
197+
format: format-backend ## Format all code
198+
199+
format-backend: ## Format backend code
200+
@echo "✨ Formatting backend code..."
201+
@uv run ruff format app
202+
@uv run ruff check --fix app
203+
204+
# =============================================================================
205+
# Build Commands
206+
# =============================================================================
207+
208+
build-backend: ## Build backend Docker image
209+
@echo "🏗️ Building backend image..."
210+
@docker compose build backend
211+
212+
build-frontend: ## Build frontend for production
213+
@echo "🏗️ Building frontend..."
214+
@cd frontend && npm run build
215+
216+
build-all: build-backend build-frontend ## Build all components
217+
218+
# =============================================================================
219+
# Cleanup
220+
# =============================================================================
221+
222+
clean: ## Clean up Docker containers, volumes, and caches
223+
@echo "🧹 Cleaning up..."
224+
@docker compose down -v
225+
@docker system prune -f
226+
@rm -rf .mypy_cache .pytest_cache .ruff_cache
227+
@rm -rf frontend/node_modules/.cache
228+
@echo "✅ Cleanup complete!"
229+
230+
clean-all: clean ## Complete cleanup including node_modules and .venv
231+
@echo "🧹 Deep cleaning..."
232+
@rm -rf frontend/node_modules
233+
@rm -rf .venv
234+
@echo "✅ Deep cleanup complete!"

0 commit comments

Comments
 (0)