← Back to list

“How to Generate Clean Python Apps Using Phind”

1. Start With a Strict Project Skeleton

REIT monero · 2026-06-11 10:46 · 0 claps · 2.6 min read
#python-app-development #phind
Open on Medium ↗

“How to Generate Clean Python Apps Using Phind

1. Start With a Strict Project Skeleton

A modern structure:

myapp/
│
├── pyproject.toml
├── README.md
├── .env
├── .gitignore
├── uv.lock
│
├── src/
│   └── myapp/
│       ├── main.py
│       ├── config.py
│       ├── models/
│       ├── services/
│       ├── repositories/
│       ├── api/
│       ├── utils/
│       └── core/
│
├── tests/
│
├── scripts/
│
└── docs/

2. Use Modern Python Tooling First

Install tooling BEFORE writing code.

Example:

uv init
uv add fastapi pydantic sqlalchemy
uv add --dev pytest ruff black mypy

Pipenv and similar tools help create deterministic Python environments and dependency isolation.

3. Use Phind for Architecture Prompts — Not Giant App Prompts

Bad prompt:

Build me a complete SaaS app.

Good prompt:

Design a clean FastAPI architecture for:
- JWT auth
- PostgreSQL
- repository pattern
- service layer
- async SQLAlchemy
- pytest
- Docker
Show folder structure only.

Then iterate module-by-module.

This produces dramatically cleaner code.

4. Generate One Layer at a Time

The biggest mistake with AI-generated Python apps:

generating entire systems in one prompt

Instead:

Step A — Generate Models

Create SQLAlchemy models for:
- User
- Organization
- Subscription
Use:
- typed ORM
- UUIDs
- relationships
- timestamps

Step B — Generate Repository Layer

Create repository classes for User CRUD.
Requirements:
- async
- SQLAlchemy 2.0
- no business logic
- return typed objects

Step C — Generate Services

Create a service layer for authentication.
Requirements:
- JWT
- password hashing
- repository injection
- typed responses

Step D — Generate API Routes

Create FastAPI routes for auth.
Requirements:
- dependency injection
- Pydantic request/response models
- proper HTTP status codes

5. Force Phind to Follow Contracts

Example:

Rules:
- no business logic in routes
- repositories access DB only
- services contain business logic
- use dependency injection
- full type hints
- no global state
- Python 3.12

AI quality improves massively when constraints are explicit.

6. Use “Refactor Prompts” Constantly

Example:

Refactor this module to:
- reduce coupling
- improve readability
- split responsibilities
- add type safety
- improve testability

This iterative cleanup workflow is where Phind becomes extremely valuable.

7. Enforce Clean Code Automatically

Use:

ruff check .
black .
mypy .
pytest

Add pre-commit hooks:

repos:
  - repo: https://github.com/astral-sh/ruff-pre-commit
    rev: v0.5.0
    hooks:
      - id: ruff

This prevents AI-generated drift.

8. Use AI for Boilerplate — Humans for Design

A strong rule:

If the module affects business logic or security, review manually.

9. Keep Functions Small

Good target:

def calculate_total(items: list[CartItem]) -> Decimal:
    ...

Bad target:

class MegaManagerEverythingService:
    ...

10. Use Prompt Templates

This is where professional workflows become fast.

Example reusable prompt:

Generate production-grade Python code.
Requirements:
- Python 3.12
- full typing
- SOLID principles
- clean architecture
- dependency injection
- no code duplication
- small functions
- pytest compatible
- structured logging
- docstrings
- PEP8
- async where appropriate
Return:
1. file tree
2. code
3. explanation
4. tests

Example Real Workflow

Workflow

1. Architecture prompt

Design clean architecture for a task management API.

2. Generate folders

Create src-based folder structure.

3. Generate models

Create typed SQLAlchemy models.

4. Generate repositories

Create repository layer.

5. Generate services

Create service layer.

6. Generate routes

Create FastAPI routes.

7. Generate tests

Create pytest coverage for services.

8. Ask Phind to audit code

Review architecture weaknesses.

Advanced Workflow (Very Effective)

Use this sequence:

Architect → Generate → Refactor → Type-check → Test → Optimize

NOT:

Generate entire app instantly

That single change separates messy AI projects from production-grade codebases.

Common AI-Generated Python Problems

1. Fat Routes

Bad:

@app.post("/users")
async def create_user():
    # 200 lines

Fix:

  • route → service → repository separation

2. Circular Imports

Avoid:

from services import *

4. Hidden State

Avoid globals.

Prefer:

Depends(get_db)

메타데이터
post_id
c68ddfdd2601
slug
how-to-generate-clean-python-apps-using-phind-c68ddfdd2601
url
https://medium.com/@juricavoda/how-to-generate-clean-python-apps-using-phind-c68ddfdd2601
canonical_url
https://medium.com/@juricavoda/how-to-generate-clean-python-apps-using-phind-c68ddfdd2601
author_url
https://medium.com/@juricavoda
status
ok
fetched_at
2026-06-27 23:56:40