sg_project_template

SG Project Template

A clean, modular Python application template using Clean Architecture (Onion Architecture), Streamlit UI, FastAPI REST API, Typer CLI, PostgreSQL / SQLModel, and Marimo Notebooks.


๐Ÿš€ Quick Start

1. Prerequisites & Virtual Environment

Ensure you have uv installed:

curl -LsSf https://astral.sh/uv/install.sh | sh

Create and activate the Python 3.12 virtual environment:

uv venv --python 3.12
source .venv/bin/activate

Install project dependencies:

uv sync

โšก Running the Application

You can execute commands directly using the root executable ./run or python -m src.main:

# Display CLI help menu & options
./run
# (or python -m src.main)

# Launch Streamlit UI
./run ui

# Launch FastAPI REST API server (port 8001)
./run api

# Check environment & DB status
./run status

# Display project version
./run version

๐Ÿ“Š Interactive Marimo Notebooks

Exploratory notebooks are placed in the root notebooks/ directory to keep src/ clean:

# Edit interactive Marimo notebook in browser
marimo edit notebooks/explore_marimo.py

# Serve notebook as a standalone web app
marimo run notebooks/explore_marimo.py

๐Ÿงช Testing & Static Verification

Run static type checks and unit test suite:

# Run unit tests and Pyright type verification
pytest -m "not integration"

# Run full test suite including live service checks
pytest

๐Ÿ“š HTML Documentation Generation

Generate HTML documentation from docstrings using pdoc3:

pdoc3 --html -o data/_docs/ src --force

๐Ÿ—๏ธ Project Architecture & Layout

.
โ”œโ”€โ”€ run                                 # Root executable wrapper script for CLI commands
โ”œโ”€โ”€ pyproject.toml                      # Project metadata & dependencies
โ”œโ”€โ”€ README.md                           # Project instructions & overview
โ”œโ”€โ”€ data/                               # Application assets, configs, and sample inputs
โ”œโ”€โ”€ notebooks/                          # Root-level Marimo & Jupyter exploratory notebooks
โ”‚   โ”œโ”€โ”€ README.md                       # Marimo usage guide
โ”‚   โ”œโ”€โ”€ explore_marimo.py              # Interactive Plotly analytics notebook
โ”‚   โ””โ”€โ”€ trial.ipynb                     # Jupyter notebook
โ”œโ”€โ”€ src/                                # Application source code (Clean Architecture)
โ”‚   โ”œโ”€โ”€ main.py                         # Application CLI entrypoint
โ”‚   โ”œโ”€โ”€ version.py                      # Application version string (__version__)
โ”‚   โ”œโ”€โ”€ config.py                       # Configuration & pydantic-settings
โ”‚   โ”œโ”€โ”€ application/                    # Application use cases & helper utilities
โ”‚   โ”‚   โ””โ”€โ”€ utils.py                    # Helper utilities
โ”‚   โ”œโ”€โ”€ domain/                         # Core domain logic, models, & repository interfaces
โ”‚   โ”‚   โ”œโ”€โ”€ models/                     # SQLModel & data classes
โ”‚   โ”‚   โ”œโ”€โ”€ schemas/                    # Pydantic schemas (ResponseMessage, etc.)
โ”‚   โ”‚   โ””โ”€โ”€ repo_interfaces/            # Abstractions for persistence repositories
โ”‚   โ”œโ”€โ”€ infra/                          # Infrastructure & external adapters
โ”‚   โ”‚   โ”œโ”€โ”€ logging.py                  # Loguru logging setup
โ”‚   โ”‚   โ”œโ”€โ”€ postgres/                   # Postgres DB operations & async/sync engines
โ”‚   โ”‚   โ””โ”€โ”€ persistence/                # Repository implementations (pgvector, qdrant)
โ”‚   โ””โ”€โ”€ presentation/                   # Presentation layer (UI, REST API, CLI)
โ”‚       โ”œโ”€โ”€ cli.py                      # Typer CLI application commands
โ”‚       โ”œโ”€โ”€ bootstrap.py                # Service dependency container
โ”‚       โ”œโ”€โ”€ dependencies.py             # FastAPI dependency checks & response examples
โ”‚       โ”œโ”€โ”€ rest/                       # FastAPI REST API routers & server runner
โ”‚       โ””โ”€โ”€ ui/                         # Streamlit UI app, sidebar, and assets
โ””โ”€โ”€ tests/                              # Pytest test suite & static type verification
    โ”œโ”€โ”€ conftest.py                     # Test fixtures
    โ”œโ”€โ”€ test_static.py                  # Pyright static type checker suite
    โ”œโ”€โ”€ test_ui.py                      # Streamlit UI helper tests
    โ”œโ”€โ”€ test_api.py                     # REST API test suite
    โ””โ”€โ”€ test_db.py                      # Database integration tests