Stateful CLI generator for Layered FastAPI projects
Project description
PyArch
PyArch is a stateful CLI that creates FastAPI projects and evolves them through project-aware generation commands.
It creates a backend project, stores its configuration in pyarch.toml, and
later uses that state to add modules and modify the existing application.
The CLI is the interface. The core idea is project-aware backend development tooling built around a manifest, generators, templates, and FastAPI conventions.
pyarch init
↓
Generated FastAPI project
↓
pyarch.toml
↓
pyarch generate module users
↓
Project is extended
↓
Manifest is updated
Highlights
- Creates Layered FastAPI projects
- Supports PostgreSQL, SQLite and MongoDB
- Stateful project manifest (
pyarch.toml) - Project-aware module generation
- JWT auth integration with generated RSA keys
- Automatic router and model registration
- Jinja2 template rendering with
StrictUndefined - Dependency installation via
uv
30-second demo
$ pyarch init demo --database postgres
✓ Creating project...
✓ Installing dependencies...
✓ Configuring Alembic...
✓ Writing manifest...
✓ Done.
$ cd demo
$ pyarch generate module users
✓ Creating module...
✓ Registering model...
✓ Registering router...
✓ Updating manifest...
✓ Done.
$ pyarch add integration auth
✓ Creating auth files...
✓ Generating RSA keys...
✓ Registering auth router...
✓ Updating manifest...
✓ Done.
$ pyarch generate module tasks --protected
✓ Creating protected module...
✓ Registering model...
✓ Registering router...
✓ Updating manifest...
✓ Done.
$ pyarch info
Project: demo
Architecture: Layered
Database: PostgreSQL
Modules:
- users
Why PyArch?
PyArch started as a tool to remove repetitive setup work in FastAPI projects: database configuration, layered structure, Alembic setup, tests and CRUD wiring.
PyArch was inspired by the developer experience of Nest CLI, but is focused on FastAPI projects and incremental project evolution.
Unlike one-shot template generators, PyArch keeps project state in a manifest and uses it for later commands. The goal is not only to create the first project structure, but also to extend the project after it already exists.
Project Manifest
PyArch stores selected architecture, database backend, generated modules and
enabled integrations in pyarch.toml.
This allows later commands to understand and extend the existing project instead of treating generation as a one-time template render.
The manifest currently records:
- schema version;
- PyArch version;
- project name;
- selected architecture;
- database engine;
- database access style;
- generated modules;
- enabled integrations;
- generated project paths.
Generated Module Flow
pyarch generate module users
The module generator:
pyarch generate module users
↓
read manifest
↓
detect backend
↓
render templates
↓
register model
↓
register router
↓
update manifest
Architecture
User
│
▼
Typer CLI
│
▼
Application Services
│
▼
Generators
│
├──────────────┐
▼ │
Jinja2 │
Templates │
│
▼ │
Filesystem │
│
▼ │
Generated Project
▲
│
pyarch.toml
Design Decisions
Why a manifest instead of scanning the filesystem?
Scanning the filesystem can show which files exist, but it cannot reliably explain why they exist or which generator state produced them. The manifest stores project-level decisions such as architecture, database backend, generated modules, integrations, paths, schema version, and PyArch version. Later commands can read that state directly instead of guessing from folders and imports.
Why marker-based registration instead of AST rewriting?
PyArch currently modifies files it generated itself, so explicit markers are simple, readable, and predictable. For router and model registration, the tool only needs stable insertion points, not a full Python code transformation pipeline. AST rewriting may become useful later if PyArch needs to safely modify arbitrary user-written code.
Why Jinja2?
Generated FastAPI files are mostly structured text, and Jinja2 keeps templates
close to the final code that users will read. StrictUndefined makes template
errors fail fast when required context is missing. This keeps generators simple
while still making missing data visible during development.
What Works Now
- creating a new Layered FastAPI project;
- choosing PostgreSQL, SQLite, or MongoDB during initialization;
- installing the matching runtime and development dependencies with
uv; - generating application layers, database configuration, test setup, and Alembic configuration for relational databases;
- generating a basic CRUD module after project creation;
- adding a JWT auth integration for PostgreSQL and SQLite projects;
- generating protected CRUD routes with
pyarch generate module <name> --protected; - registering generated SQLAlchemy models in
app/models/__init__.py; - registering generated routers in
app/api/v1/router.py; - keeping project state in
pyarch.toml; - displaying the current project configuration through the CLI.
Usage
Create a project:
pyarch init my_project
Select a database explicitly:
pyarch init my_project --database postgres
pyarch init my_project --database sqlite
pyarch init my_project --database mongodb
Move into the generated project and inspect its recorded state:
cd my_project
pyarch info
Generate a CRUD module:
pyarch generate module users
Add auth and generate protected routes:
pyarch add integration auth
pyarch generate module tasks --protected
Roadmap
v0.2
- safe generation
- validation improvements
- rollback on failed generation
- Redis integration foundation
v0.3
- Redis integration
- scheduler integration
- dry-run mode
Later
- new architectures
- plugin system
- async database access
Generated Structure
Show generated project tree
A generated project currently follows this general structure:
my_project/
├── app/
│ ├── api/
│ │ └── v1/
│ ├── core/
│ ├── db/
│ ├── dependencies/
│ ├── models/
│ ├── repositories/
│ ├── schemas/
│ ├── services/
│ └── main.py
├── docs/
├── tests/
├── alembic/ # PostgreSQL and SQLite only
├── certs/ # created by the auth integration
├── .env.example
├── pyarch.toml
└── pyproject.toml
Requirements
- Python 3.13 or newer;
- uv.
Local Setup
Install from PyPI:
pip install pyarch-cli
pyarch --help
Clone the repository and install its dependencies:
git clone <repository-url>
cd pathlib
uv sync
Run the CLI directly from the repository:
uv run pyarch --help
Install the current checkout as a local CLI tool:
uv tool install --editable .
Project Status
MVP+ — early development
The first working CLI flow is in place. Commands, generated code, templates, and the manifest format may still change while the project evolves.
Current Limitations
- only Layered Architecture is supported;
- generated applications use synchronous database access;
- only FastAPI projects are supported;
- auth integration currently supports PostgreSQL and SQLite projects;
- generated projects are starter scaffolds and still require application-specific configuration and code;
- the manifest format may change before a stable release.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyarch_cli-0.1.0.tar.gz.
File metadata
- Download URL: pyarch_cli-0.1.0.tar.gz
- Upload date:
- Size: 44.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.1 {"installer":{"name":"uv","version":"0.11.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d67d026b60ba35e6c22c66358ccb2a2d2ae085190b6a2cfddbb6315ee3f9cf79
|
|
| MD5 |
09f02a7ec1093e676232777965050e7b
|
|
| BLAKE2b-256 |
3b3bc66d1775d2fedb6823870ff81000c9f0886ecf783280e0d9cb7afe98c8b7
|
File details
Details for the file pyarch_cli-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pyarch_cli-0.1.0-py3-none-any.whl
- Upload date:
- Size: 42.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.1 {"installer":{"name":"uv","version":"0.11.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7593b72aaf8eb934fc0ae5d4f77afbdd1abca6d6e6f6ff65cb4f26ca70ddffe8
|
|
| MD5 |
f9a452b662a7cc8e473e73b92b172b8d
|
|
| BLAKE2b-256 |
db3862225eb9693fef52e364280be65019cffb97f76c6254b3f0c763bf0ea93d
|