Skip to main content

Architecture-preserving REST API synthesis library

Project description

ArchAPI

ArchAPI is a Python library for architecture-preserving REST API generation.

It scans an existing backend project, detects the framework, understands the project structure, plans a REST API, generates framework-specific files, validates the output, and writes files only when explicitly requested.

Current Status

Current checkpoint: 0.3.1

ArchAPI currently supports:

  • Express TypeScript
  • FastAPI
  • Generic fallback detection for unsupported projects

Core features:

  • Framework detection
  • Project scanning
  • API architecture modeling
  • Confidence scoring
  • Low-confidence blocking
  • Strict config mode
  • REST intent planning
  • Dry-run code generation
  • Safe apply behavior
  • Overwrite protection
  • Cache and changed-file detection
  • Secret scanning helpers
  • Context redaction
  • Policy gate
  • Architecture consistency scoring
  • Unified regression test suite

Installation from PyPI

python -m pip install archapi

Verify:

python -c "from archapi import ArchAPI; print('ArchAPI import works')"

Run from GitHub Source

git clone https://github.com/rohith5005/archapi.git
cd archapi

python3 -m venv .venv
source .venv/bin/activate

python -m pip install --upgrade pip setuptools wheel
python -m pip install -e .

Verify:

python -c "from archapi import ArchAPI; print('GitHub source install worked')"

Run Tests

python -m compileall archapi
python -m unittest tests.test_archapi_suite -v

Or:

./scripts/run_tests.sh

Expected result:

Ran 7 tests

OK

Basic Usage

from archapi import ArchAPI

engine = ArchAPI("./sample_projects/express_basic")

result = engine.generate_api(
    "Create GET API for user order history",
    dry_run=True,
)

print(result.plan)
print(result.validation_report)
print(result.diff)

Express TypeScript Example

from pathlib import Path
from archapi import ArchAPI

project = Path("express_basic")

(project / "src/routes").mkdir(parents=True, exist_ok=True)
(project / "src/controllers").mkdir(parents=True, exist_ok=True)
(project / "src/services").mkdir(parents=True, exist_ok=True)
(project / "src/schemas").mkdir(parents=True, exist_ok=True)
(project / "tests").mkdir(parents=True, exist_ok=True)

(project / "package.json").write_text(
    '{"dependencies": {"express": "^4.18.0", "zod": "^3.0.0"}}'
)

(project / "src/routes/user.routes.ts").write_text(
    'import { Router } from "express";\n'
    'const router = Router();\n'
    'export default router;\n'
)

(project / "src/controllers/user.controller.ts").write_text(
    'export const userController = {};\n'
)

(project / "src/services/user.service.ts").write_text(
    'export const userService = {};\n'
)

(project / "src/schemas/user.schema.ts").write_text(
    'import { z } from "zod";\n'
)

(project / "tests/user.test.ts").write_text(
    'describe("user", () => { it("works", () => expect(true).toBe(true)); });\n'
)

engine = ArchAPI(str(project))
result = engine.generate_api("Create GET API for user order history", dry_run=True)

print("Detected framework:", engine.detect_framework().framework)
print("Generated method:", result.plan.method)
print("Generated path:", result.plan.path)
print("Generated files:", [str(file.path) for file in result.files])

Expected output includes:

Detected framework: express-typescript
Generated method: GET
Generated path: /users/{user_id}/orders

FastAPI Example

from pathlib import Path
from archapi import ArchAPI

project = Path("fastapi_basic")

(project / "app/routers").mkdir(parents=True, exist_ok=True)
(project / "app/services").mkdir(parents=True, exist_ok=True)
(project / "app/schemas").mkdir(parents=True, exist_ok=True)
(project / "tests").mkdir(parents=True, exist_ok=True)

(project / "requirements.txt").write_text("fastapi\npydantic\npytest\n")

(project / "app/routers/user_router.py").write_text(
    "from fastapi import APIRouter\n"
    "router = APIRouter()\n"
)

(project / "app/services/user_service.py").write_text(
    "class UserService:\n"
    "    pass\n\n"
    "user_service = UserService()\n"
)

(project / "app/schemas/user_schema.py").write_text(
    "from pydantic import BaseModel\n\n"
    "class UserResponse(BaseModel):\n"
    "    id: str\n"
)

(project / "tests/test_user.py").write_text(
    "def test_user_placeholder():\n"
    "    assert True\n"
)

engine = ArchAPI(str(project))
result = engine.generate_api("Create POST API for product review", dry_run=True)

print("Detected framework:", engine.detect_framework().framework)
print("Generated method:", result.plan.method)
print("Generated path:", result.plan.path)
print("Generated files:", [str(file.path) for file in result.files])

Expected output includes:

Detected framework: fastapi
Generated method: POST
Generated path: /products/{product_id}/reviews

Documentation

Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

archapi-0.4.0.tar.gz (35.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

archapi-0.4.0-py3-none-any.whl (44.7 kB view details)

Uploaded Python 3

File details

Details for the file archapi-0.4.0.tar.gz.

File metadata

  • Download URL: archapi-0.4.0.tar.gz
  • Upload date:
  • Size: 35.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.9

File hashes

Hashes for archapi-0.4.0.tar.gz
Algorithm Hash digest
SHA256 5c953b5fbc0d5a361e7c1e967d3c9e839de02e3152f12544fe1c27b87eb10c05
MD5 2984f9707f5375279ffbf43d3add5f56
BLAKE2b-256 e92b18f245a3a852fa50f10b66542701dc3b9dc13dfb9dfae22c2a5ccb6c16a7

See more details on using hashes here.

File details

Details for the file archapi-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: archapi-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 44.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.9

File hashes

Hashes for archapi-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 45165c58f76c2fbf83f372b5b2307b67ca289d08775db519fd4a4e2eab45fb9c
MD5 a3a429ecb15368cc20463c1fe93921d3
BLAKE2b-256 f44dab5a9ced01ac24ec1e19229a0b052732adcab956c1296755474d665ef9f5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page