Initialize Aidoit v0.1 monorepo
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
FROM python:3.13-slim AS runtime
|
||||
|
||||
ENV PYTHONDONTWRITEBYTECODE=1
|
||||
ENV PYTHONUNBUFFERED=1
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY pyproject.toml requirements.txt ./
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
COPY app ./app
|
||||
|
||||
EXPOSE 8000
|
||||
|
||||
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
|
||||
@@ -0,0 +1,20 @@
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
aidoit_env: str = "development"
|
||||
aidoit_admin_token: str = "replace-me"
|
||||
database_url: str = "sqlite:///./aidoit.db"
|
||||
redis_url: str = "redis://localhost:6379/0"
|
||||
web_origin: str = "http://localhost:3000"
|
||||
msp_origin: str = "http://localhost:3001"
|
||||
|
||||
model_config = SettingsConfigDict(
|
||||
env_file=".env",
|
||||
env_file_encoding="utf-8",
|
||||
case_sensitive=False,
|
||||
extra="ignore",
|
||||
)
|
||||
|
||||
|
||||
settings = Settings()
|
||||
@@ -0,0 +1,32 @@
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
|
||||
from app.core.config import settings
|
||||
from app.modules.health.router import router as health_router
|
||||
from app.modules.projects.router import router as projects_router
|
||||
|
||||
app = FastAPI(
|
||||
title="Aidoit API",
|
||||
version="0.1.0",
|
||||
description="Shared REST API for the Aidoit personal AI operating system.",
|
||||
)
|
||||
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=[settings.web_origin, settings.msp_origin],
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
app.include_router(health_router)
|
||||
app.include_router(projects_router, prefix="/api/v1")
|
||||
|
||||
|
||||
@app.get("/")
|
||||
async def root() -> dict[str, str]:
|
||||
return {
|
||||
"name": "Aidoit API",
|
||||
"version": "0.1.0",
|
||||
"docs": "/docs",
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
from fastapi import APIRouter
|
||||
|
||||
router = APIRouter(tags=["health"])
|
||||
|
||||
|
||||
@router.get("/health")
|
||||
async def health() -> dict[str, str]:
|
||||
return {
|
||||
"status": "ok",
|
||||
"service": "aidoit-api",
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
from fastapi import APIRouter, HTTPException, status
|
||||
|
||||
from app.modules.projects.schemas import ProjectCreate, ProjectRead
|
||||
from app.modules.projects.service import project_service
|
||||
|
||||
router = APIRouter(prefix="/projects", tags=["projects"])
|
||||
|
||||
|
||||
@router.get("", response_model=list[ProjectRead])
|
||||
async def list_projects() -> list[ProjectRead]:
|
||||
return project_service.list()
|
||||
|
||||
|
||||
@router.post(
|
||||
"",
|
||||
response_model=ProjectRead,
|
||||
status_code=status.HTTP_201_CREATED,
|
||||
)
|
||||
async def create_project(payload: ProjectCreate) -> ProjectRead:
|
||||
return project_service.create(payload)
|
||||
|
||||
|
||||
@router.get("/{project_id}", response_model=ProjectRead)
|
||||
async def get_project(project_id: int) -> ProjectRead:
|
||||
project = project_service.get(project_id)
|
||||
if project is None:
|
||||
raise HTTPException(status_code=404, detail="Project not found")
|
||||
return project
|
||||
@@ -0,0 +1,19 @@
|
||||
from datetime import datetime
|
||||
from typing import Literal
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
ProductType = Literal["web", "desktop", "msp"]
|
||||
|
||||
|
||||
class ProjectCreate(BaseModel):
|
||||
name: str = Field(min_length=1, max_length=120)
|
||||
description: str = Field(default="", max_length=2000)
|
||||
product: ProductType = "web"
|
||||
|
||||
|
||||
class ProjectRead(ProjectCreate):
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
id: int
|
||||
created_at: datetime
|
||||
@@ -0,0 +1,31 @@
|
||||
from datetime import UTC, datetime
|
||||
from itertools import count
|
||||
|
||||
from app.modules.projects.schemas import ProjectCreate, ProjectRead
|
||||
|
||||
|
||||
class ProjectService:
|
||||
def __init__(self) -> None:
|
||||
self._ids = count(1)
|
||||
self._projects: list[ProjectRead] = []
|
||||
|
||||
def list(self) -> list[ProjectRead]:
|
||||
return self._projects.copy()
|
||||
|
||||
def create(self, payload: ProjectCreate) -> ProjectRead:
|
||||
project = ProjectRead(
|
||||
id=next(self._ids),
|
||||
created_at=datetime.now(UTC),
|
||||
**payload.model_dump(),
|
||||
)
|
||||
self._projects.append(project)
|
||||
return project
|
||||
|
||||
def get(self, project_id: int) -> ProjectRead | None:
|
||||
return next(
|
||||
(project for project in self._projects if project.id == project_id),
|
||||
None,
|
||||
)
|
||||
|
||||
|
||||
project_service = ProjectService()
|
||||
@@ -0,0 +1,31 @@
|
||||
[project]
|
||||
name = "aidoit-api"
|
||||
version = "0.1.0"
|
||||
description = "Shared REST API for Aidoit"
|
||||
requires-python = ">=3.13"
|
||||
dependencies = [
|
||||
"fastapi>=0.115",
|
||||
"uvicorn[standard]>=0.34",
|
||||
"pydantic-settings>=2.7",
|
||||
"sqlalchemy>=2.0",
|
||||
"psycopg[binary]>=3.2",
|
||||
"alembic>=1.14",
|
||||
"redis>=5.2",
|
||||
"httpx>=0.28"
|
||||
]
|
||||
|
||||
[project.optional-dependencies]
|
||||
dev = [
|
||||
"pytest>=8.3",
|
||||
"pytest-asyncio>=0.25",
|
||||
"ruff>=0.9",
|
||||
"mypy>=1.14"
|
||||
]
|
||||
|
||||
[tool.ruff]
|
||||
line-length = 100
|
||||
target-version = "py313"
|
||||
|
||||
[tool.pytest.ini_options]
|
||||
pythonpath = ["."]
|
||||
testpaths = ["tests"]
|
||||
@@ -0,0 +1 @@
|
||||
-e .[dev]
|
||||
@@ -0,0 +1 @@
|
||||
-e .
|
||||
@@ -0,0 +1,11 @@
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from app.main import app
|
||||
|
||||
client = TestClient(app)
|
||||
|
||||
|
||||
def test_health() -> None:
|
||||
response = client.get("/health")
|
||||
assert response.status_code == 200
|
||||
assert response.json()["status"] == "ok"
|
||||
Reference in New Issue
Block a user