Skip to content

Commit 1c1b494

Browse files
Copilotallisson
andauthored
docs: add Development Setup section to README (#26)
* Initial plan * Add comprehensive Development Setup section to README Co-authored-by: allisson <5202+allisson@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: allisson <5202+allisson@users.noreply.github.com>
1 parent 26ed2c3 commit 1c1b494

1 file changed

Lines changed: 259 additions & 0 deletions

File tree

README.md

Lines changed: 259 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,6 +1048,265 @@ If you're having trouble connecting to the database from Docker:
10481048
- Set it as an environment variable: `FASTPUBSUB_AUTH_SECRET_KEY=your-generated-key`
10491049
- The same secret key must be used across all server instances
10501050

1051+
## 🛠️ Development Setup
1052+
1053+
This section is for developers who want to contribute to fastpubsub or run it locally without Docker.
1054+
1055+
### 📋 Prerequisites
1056+
1057+
- **Python 3.14+**: The project requires Python 3.14 or later
1058+
- **uv**: Fast Python package installer and resolver ([installation guide](https://github.com/astral-sh/uv))
1059+
- **PostgreSQL 14+**: Local PostgreSQL instance for development
1060+
- **make**: For running Makefile commands (usually pre-installed on Unix-like systems)
1061+
1062+
### 🚀 Initial Setup
1063+
1064+
1. **Clone the repository:**
1065+
1066+
```bash
1067+
git clone https://github.com/allisson/fastpubsub.git
1068+
cd fastpubsub
1069+
```
1070+
1071+
2. **Start a local PostgreSQL instance (optional):**
1072+
1073+
If you don't have PostgreSQL running, you can use the provided Makefile command:
1074+
1075+
```bash
1076+
make start-postgresql
1077+
```
1078+
1079+
This starts a PostgreSQL container with default credentials:
1080+
- User: `fastpubsub`
1081+
- Password: `fastpubsub`
1082+
- Database: `fastpubsub`
1083+
- Port: `5432`
1084+
1085+
To stop and remove the PostgreSQL container later:
1086+
1087+
```bash
1088+
make remove-postgresql
1089+
```
1090+
1091+
3. **Set up environment variables:**
1092+
1093+
Copy the sample environment file and adjust as needed:
1094+
1095+
```bash
1096+
cp env.sample .env
1097+
```
1098+
1099+
Edit `.env` to configure your local database connection and other settings.
1100+
1101+
4. **Install dependencies:**
1102+
1103+
```bash
1104+
# Install uv if you haven't already
1105+
pip install uv
1106+
1107+
# Install project dependencies (including development dependencies)
1108+
uv sync
1109+
```
1110+
1111+
This creates a virtual environment at `.venv` and installs all required packages.
1112+
1113+
5. **Run database migrations:**
1114+
1115+
```bash
1116+
make run-db-migrate
1117+
```
1118+
1119+
Or manually:
1120+
1121+
```bash
1122+
PYTHONPATH=./ uv run python fastpubsub/main.py db-migrate
1123+
```
1124+
1125+
### 🧪 Running Tests
1126+
1127+
Run the full test suite:
1128+
1129+
```bash
1130+
make test
1131+
```
1132+
1133+
Or manually with pytest:
1134+
1135+
```bash
1136+
uv run pytest -v
1137+
```
1138+
1139+
For coverage reporting:
1140+
1141+
```bash
1142+
uv run pytest -v --cov=fastpubsub --cov-report=term-missing
1143+
```
1144+
1145+
### 🎨 Linting and Code Quality
1146+
1147+
The project uses [ruff](https://docs.astral.sh/ruff/) for linting and formatting, along with pre-commit hooks.
1148+
1149+
**Run linting:**
1150+
1151+
```bash
1152+
make lint
1153+
```
1154+
1155+
This runs all pre-commit hooks including:
1156+
- Ruff linting and formatting
1157+
- Various file checks (trailing whitespace, YAML/JSON validation, etc.)
1158+
- MyPy type checking
1159+
1160+
**Install pre-commit hooks (recommended):**
1161+
1162+
```bash
1163+
uv run pre-commit install
1164+
```
1165+
1166+
After installation, the hooks will run automatically on every commit.
1167+
1168+
**Manual formatting:**
1169+
1170+
```bash
1171+
# Format code with ruff
1172+
uv run ruff format .
1173+
1174+
# Run ruff checks with auto-fix
1175+
uv run ruff check --fix .
1176+
```
1177+
1178+
### 🏃 Running the Server Locally
1179+
1180+
Start the development server:
1181+
1182+
```bash
1183+
make run-server
1184+
```
1185+
1186+
Or manually:
1187+
1188+
```bash
1189+
PYTHONPATH=./ uv run python fastpubsub/main.py server
1190+
```
1191+
1192+
The API will be available at:
1193+
- Server: `http://localhost:8000`
1194+
- Swagger UI: `http://localhost:8000/docs`
1195+
- ReDoc: `http://localhost:8000/redoc`
1196+
1197+
### 🗄️ Database Migrations
1198+
1199+
**Create a new migration:**
1200+
1201+
```bash
1202+
make create-migration
1203+
```
1204+
1205+
This generates a new migration file in `migrations/versions/`. Edit the file to define your schema changes.
1206+
1207+
**Apply migrations:**
1208+
1209+
```bash
1210+
make run-db-migrate
1211+
```
1212+
1213+
### 🐳 Building Docker Image Locally
1214+
1215+
Build the Docker image:
1216+
1217+
```bash
1218+
make docker-build
1219+
```
1220+
1221+
Or manually:
1222+
1223+
```bash
1224+
docker build --rm -t fastpubsub .
1225+
```
1226+
1227+
### 🔧 Development Workflow
1228+
1229+
1. **Create a feature branch:**
1230+
1231+
```bash
1232+
git checkout -b feature/your-feature-name
1233+
```
1234+
1235+
2. **Make your changes and test locally:**
1236+
1237+
```bash
1238+
# Run linting
1239+
make lint
1240+
1241+
# Run tests
1242+
make test
1243+
1244+
# Start the server to manually test
1245+
make run-server
1246+
```
1247+
1248+
3. **Commit your changes:**
1249+
1250+
The pre-commit hooks will automatically run linting and checks. Ensure all checks pass.
1251+
1252+
```bash
1253+
git add .
1254+
git commit -m "Your commit message"
1255+
```
1256+
1257+
4. **Push and create a pull request:**
1258+
1259+
```bash
1260+
git push origin feature/your-feature-name
1261+
```
1262+
1263+
### 📦 Project Structure
1264+
1265+
```
1266+
fastpubsub/
1267+
├── fastpubsub/ # Main application package
1268+
│ ├── api/ # FastAPI routes and API logic
1269+
│ ├── services/ # Business logic and services
1270+
│ ├── config.py # Configuration management
1271+
│ ├── database.py # Database connection and migrations
1272+
│ ├── models.py # Pydantic models
1273+
│ ├── main.py # CLI entry point
1274+
│ └── ...
1275+
├── migrations/ # Alembic database migrations
1276+
│ └── versions/ # Migration files
1277+
├── tests/ # Test suite
1278+
│ ├── api/ # API tests
1279+
│ ├── services/ # Service tests
1280+
│ └── ...
1281+
├── Dockerfile # Production Docker image
1282+
├── Makefile # Development commands
1283+
├── pyproject.toml # Project metadata and dependencies
1284+
├── ruff.toml # Ruff linter configuration
1285+
├── .pre-commit-config.yaml # Pre-commit hooks configuration
1286+
└── README.md # This file
1287+
```
1288+
1289+
### 💻 Available Makefile Commands
1290+
1291+
| Command | Description |
1292+
|---------|-------------|
1293+
| `make test` | Run the test suite with pytest |
1294+
| `make lint` | Run pre-commit hooks (linting, formatting, checks) |
1295+
| `make start-postgresql` | Start a local PostgreSQL Docker container |
1296+
| `make remove-postgresql` | Stop and remove the PostgreSQL container |
1297+
| `make create-migration` | Create a new Alembic migration file |
1298+
| `make run-db-migrate` | Apply database migrations |
1299+
| `make run-server` | Start the development server |
1300+
| `make docker-build` | Build the Docker image locally |
1301+
1302+
### 🔍 Additional Tips
1303+
1304+
- **Virtual Environment**: The project uses `uv` which automatically manages a virtual environment in `.venv/`
1305+
- **Python Version**: Ensure you're using Python 3.14+ as specified in `pyproject.toml`
1306+
- **Environment Variables**: All configuration is done via environment variables prefixed with `FASTPUBSUB_`
1307+
- **IDE Setup**: Consider configuring your IDE to use the `.venv/bin/python` interpreter
1308+
- **Database**: The test suite uses the same database configured in your `.env` file
1309+
10511310
---
10521311
10531312
Made with ❤️ using FastAPI and PostgreSQL

0 commit comments

Comments
 (0)