|
1 | | -# python-app-template |
2 | | -python-app-template |
| 1 | + |
| 2 | +# Python App Template |
| 3 | + |
| 4 | +A modern, modular Python application template with robust CI/CD, best practices, and synthwave terminal UI. This project demonstrates clean architecture, packaging, and workflow automation for professional Python development. |
| 5 | + |
| 6 | +## Features |
| 7 | +- **Modular Structure**: src layout, clear separation of core, UI, models, and tests |
| 8 | +- **Synthwave Terminal UI**: Rich + pyfiglet for beautiful astronomical data display |
| 9 | +- **Robust CI/CD**: GitHub Actions for linting, testing, Docker multi-arch builds, Trivy scanning, and releases |
| 10 | +- **Best Practices**: Type hints, logging, config management, reusable workflows, DRY code |
| 11 | +- **Packaging**: pyproject.toml, src layout, testable modules, versioned releases |
| 12 | + |
| 13 | +## Architecture |
| 14 | + |
| 15 | +``` |
| 16 | +python-app-template/ |
| 17 | +├── src/sample_python_app/ |
| 18 | +│ ├── core/ # Core logic: config, logging, display (thin wrappers) |
| 19 | +│ ├── models/ # Data models (Pydantic) |
| 20 | +│ ├── ui/ # Terminal UI (synthwave) |
| 21 | +│ ├── data_loader/ # Data loader module (API logic) |
| 22 | +│ ├── services/ # Service layer (business logic, imports data loader) |
| 23 | +│ └── main.py # Entry point |
| 24 | +├── tests/ # Unit tests |
| 25 | +├── data/ # Sample data |
| 26 | +├── Dockerfile # Containerization |
| 27 | +├── pyproject.toml # Packaging |
| 28 | +├── .github/workflows # CI/CD workflows |
| 29 | +``` |
| 30 | + |
| 31 | +## Frameworks & Libraries |
| 32 | +- **rich**: Terminal formatting and color |
| 33 | +- **pyfiglet**: ASCII art for synthwave look |
| 34 | +- **pydantic**: Data validation and settings |
| 35 | +- **httpx**: HTTP requests |
| 36 | +- **pytest**: Testing |
| 37 | +- **ruff, black, isort**: Linting and formatting |
| 38 | + |
| 39 | +## CI/CD & Workflows |
| 40 | + |
| 41 | +- **cache-uv-build.yaml**: Caches Python dependencies for fast builds |
| 42 | +- **ruff.yaml**: Lints code for style and quality |
| 43 | +- **pytest.yaml**: Runs unit tests |
| 44 | +- **docker-build-and-scan.yaml**: Multi-arch Docker builds, Trivy vulnerability scan |
| 45 | +- **ci-cd.yaml**: Orchestrates all jobs, triggers on push, PR, release, manual |
| 46 | +- **release.yaml**: Publishes releases on main/tags |
| 47 | + |
| 48 | +### Docker Build Safety Features |
| 49 | +- **Multi-arch builds**: Uses Docker Buildx and QEMU for isolated, reproducible builds across amd64 and arm64 |
| 50 | +- **Trivy vulnerability scan**: Automated scan for critical/high OS and library vulnerabilities before release |
| 51 | +- **Buildx isolation**: Ensures builds are run in a clean environment, reducing risk of contamination |
| 52 | +- **Secrets management**: DockerHub credentials and other secrets are handled securely via GitHub Actions |
| 53 | +- **Minimal base image**: Dockerfile uses slim Python base for reduced attack surface |
| 54 | +- **No root user**: (Recommended) Run containers as non-root for extra safety (customize Dockerfile as needed) |
| 55 | + |
| 56 | +## Python Best Practices |
| 57 | +- **src layout**: Prevents import shadowing, enables clean packaging |
| 58 | +- **pyproject.toml**: Modern build system, dependency management |
| 59 | +- **Type hints**: Static analysis, clarity |
| 60 | +- **Logging**: Traceability for inputs, API calls, UI rendering |
| 61 | +- **Modularization**: UI logic in dedicated module, core as thin wrappers, data loader and service layer separated for clarity and maintainability |
| 62 | +- **Testing**: pytest for unit and integration tests |
| 63 | +- **CI/CD**: Automated lint, test, build, scan, release |
| 64 | +- **Multi-arch Docker**: Builds for amd64 and arm64 |
| 65 | + |
| 66 | +## Getting Started |
| 67 | +1. Clone the repo |
| 68 | +2. Install dependencies: `uv sync` |
| 69 | +3. Run tests: `uv run pytest` |
| 70 | +4. Run app: `uv run src/sample_python_app/main.py` |
| 71 | + - Data loading and business logic are now handled via the service layer and data_loader module |
| 72 | +5. Build Docker: `docker build -t python-app-template .` |
| 73 | + |
| 74 | +## Contributing |
| 75 | +- Follow PEP8 and use ruff, black, isort |
| 76 | +- Write tests for new features |
| 77 | +- Use modular, reusable workflows |
| 78 | + |
| 79 | +## License |
| 80 | +MIT |
| 81 | + |
| 82 | +--- |
| 83 | +This template is ideal for modern Python apps with clean architecture, robust automation, and beautiful terminal UI. |
0 commit comments