Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2024 fastappkit contributors
Copyright (c) 2025 fastappkit contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
77 changes: 48 additions & 29 deletions docs/guides/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ apps = [

### App Entry Formats

- `apps.<name>` → Internal app (located in `./apps/<name>/`)
- `<package_name>` → External app (pip-installed package, must be importable)
- `apps.<name>` → Internal app (located in `./apps/<name>/`)
- `<package_name>` → External app (pip-installed package, must be importable)

### Migration Order

Expand All @@ -36,6 +36,7 @@ order = ["core", "auth", "blog"]
Settings are defined in `core/config.py` using Pydantic's `BaseSettings`:

```python
from pydantic import Field
from pydantic_settings import BaseSettings, SettingsConfigDict

class Settings(BaseSettings):
Expand All @@ -45,12 +46,19 @@ class Settings(BaseSettings):
Loads from .env file automatically.
"""

DATABASE_URL: str = "sqlite:///./app.db"
DEBUG: bool = False
database_url: str = Field(
default="sqlite:///./app.db",
alias="DATABASE_URL"
)
debug: bool = Field(
default=False,
alias="DEBUG"
)

model_config = SettingsConfigDict(
env_file=".env",
env_file_encoding="utf-8"
env_file_encoding="utf-8",
populate_by_name=True
)
```

Expand All @@ -59,30 +67,41 @@ class Settings(BaseSettings):
The scaffolded code includes minimal settings. You can extend it by adding more fields:

```python
from pydantic import Field

class Settings(BaseSettings):
DATABASE_URL: str = "sqlite:///./app.db"
DEBUG: bool = False
database_url: str = Field(
default="sqlite:///./app.db",
alias="DATABASE_URL"
)
debug: bool = Field(
default=False,
alias="DEBUG"
)

# Add your custom settings here
SECRET_KEY: str = "change-me-in-production"
HOST: str = "127.0.0.1"
PORT: int = 8000
secret_key: str = Field(
default="change-me-in-production",
alias="SECRET_KEY"
)
host: str = Field(default="127.0.0.1", alias="HOST")
port: int = Field(default=8000, alias="PORT")

model_config = SettingsConfigDict(
env_file=".env",
env_file_encoding="utf-8",
case_sensitive=True,
populate_by_name=True,
extra="ignore", # Ignore extra fields from .env
)
```

### Customization Options

- **Add Custom Settings:** Add fields to `Settings` class
- **Validation:** Use Pydantic validators: `@field_validator('DATABASE_URL')`
- **Default Values:** Set defaults in class definition
- **Nested Settings:** Use Pydantic models for nested configuration
- **Environment-Specific:** Override in `.env` or via environment variables
- **Add Custom Settings:** Add fields to `Settings` class with `Field()` instances
- **Validation:** Use Pydantic validators: `@field_validator('database_url')`
- **Default Values:** Set defaults in `Field()` instances
- **Nested Settings:** Use Pydantic models for nested configuration
- **Environment-Specific:** Override in `.env` or via environment variables (uppercase names are supported via aliases)

### Accessing Settings

Expand All @@ -92,7 +111,7 @@ class Settings(BaseSettings):
from fastappkit.conf import get_settings

settings = get_settings()
db_url = settings.DATABASE_URL
db_url = settings.database_url
```

**FastAPI dependency injection:**
Expand All @@ -103,7 +122,7 @@ from fastapi import Depends
from core.config import Settings

def handler(settings: Settings = Depends(get_settings)):
return settings.DEBUG
return settings.debug
```

### Environment Variables
Expand Down Expand Up @@ -198,28 +217,28 @@ route_prefix = "/blog"
```

!!! important "Manifest Requirements"
The manifest file is `fastappkit.toml`, not `pyproject.toml`. It must be located in the package directory (where `__init__.py` is). This ensures it's included when the package is published to PyPI. No fallback - `fastappkit.toml` is required for external apps.
The manifest file is `fastappkit.toml`, not `pyproject.toml`. It must be located in the package directory (where `__init__.py` is). This ensures it's included when the package is published to PyPI. No fallback - `fastappkit.toml` is required for external apps.

See the [Manifest Reference](../reference/manifest-reference.md) for complete details.

## Dependency Versions

!!! warning "Default Dependency Versions"
When creating a new project or external app, dependency versions in `pyproject.toml` are set to `*` (any version) by default. This provides maximum flexibility but may lead to compatibility issues.
When creating a new project or external app, dependency versions in `pyproject.toml` are set to `*` (any version) by default. This provides maximum flexibility but may lead to compatibility issues.

### Recommendations

**For Production Projects:**

- Update dependency versions to specific ranges (e.g., `>=0.120.0,<0.130`)
- Pin exact versions for critical dependencies
- Test thoroughly after updating versions
- Update dependency versions to specific ranges (e.g., `>=0.120.0,<0.130`)
- Pin exact versions for critical dependencies
- Test thoroughly after updating versions

**For External Apps:**

- Match dependency versions with the core project for compatibility
- Use compatible version ranges that work with the core project's versions
- Document minimum required versions in your app's README
- Match dependency versions with the core project for compatibility
- Use compatible version ranges that work with the core project's versions
- Document minimum required versions in your app's README

**Example:**

Expand All @@ -232,9 +251,9 @@ alembic = ">=1.17.2,<1.18"
```

!!! note "CLI Warning"
The CLI will display a warning message when creating projects or external apps, reminding you to update dependency versions according to your needs.
The CLI will display a warning message when creating projects or external apps, reminding you to update dependency versions according to your needs.

## Learn More

- [Configuration Reference](../reference/configuration-reference.md) - Complete configuration options
- [Manifest Reference](../reference/manifest-reference.md) - External app manifest schema
- [Configuration Reference](../reference/configuration-reference.md) - Complete configuration options
- [Manifest Reference](../reference/manifest-reference.md) - External app manifest schema
3 changes: 2 additions & 1 deletion docs/guides/creating-projects.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,14 @@ myproject/
Start the development server:

```bash
fastappkit core dev [--host <host>] [--port <port>] [--reload] [--verbose] [--debug] [--quiet]
fastappkit core dev [--host <host>] [--port <port>] [--reload] [--verbose] [--debug] [--quiet] [<uvicorn-options>]
```

### Options

- `--host, -h`: Host to bind to (default: `127.0.0.1`)
- `--port, -p`: Port to bind to (default: `8000`)
- Additional uvicorn options: All other arguments are forwarded to uvicorn (e.g., `--workers`, `--log-level`, `--access-log`)
- `--reload`: Enable auto-reload on code changes
- `--verbose, -v`: Enable verbose output (overrides global setting)
- `--debug`: Enable debug output (overrides global setting, includes stack traces)
Expand Down
24 changes: 14 additions & 10 deletions docs/guides/deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ DEBUG=false
```

!!! warning "Security"
Never commit `.env` files with sensitive data. Use environment variables or secure secret management systems in production.
Never commit `.env` files with sensitive data. Use environment variables or secure secret management systems in production.

### Dependency Versions

Expand All @@ -38,7 +38,7 @@ fastappkit migrate all
```

!!! tip "Migration Strategy"
Run migrations in a separate step before deploying application code. This ensures the database schema is ready before the new code runs.
Run migrations in a separate step before deploying application code. This ensures the database schema is ready before the new code runs.

## Deployment Options

Expand Down Expand Up @@ -106,7 +106,7 @@ gunicorn main:app -w 4 -k uvicorn.workers.UvicornWorker --bind 0.0.0.0:8000
```

!!! note "Development Server"
The `fastappkit core dev` command is intended for development only. Use a production ASGI server for production deployments.
The `fastappkit core dev` command is intended for development only. Use a production ASGI server for production deployments.

## Monitoring and Logging

Expand All @@ -115,18 +115,22 @@ Configure proper logging for production:
```python
# core/config.py
import logging
from pydantic import Field
from pydantic_settings import BaseSettings, SettingsConfigDict

class Settings(BaseSettings):
DATABASE_URL: str
DEBUG: bool = False
LOG_LEVEL: str = "INFO"
database_url: str = Field(alias="DATABASE_URL")
debug: bool = Field(default=False, alias="DEBUG")
log_level: str = Field(default="INFO", alias="LOG_LEVEL")

model_config = SettingsConfigDict(env_file=".env")
model_config = SettingsConfigDict(
env_file=".env",
populate_by_name=True
)

# Configure logging
logging.basicConfig(
level=getattr(logging, settings.LOG_LEVEL),
level=getattr(logging, settings.log_level),
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
```
Expand All @@ -148,5 +152,5 @@ def health_check():

## Learn More

- [Configuration Guide](configuration.md) - Production configuration
- [Best Practices](../advanced/best-practices.md) - Production best practices
- [Configuration Guide](configuration.md) - Production configuration
- [Best Practices](../advanced/best-practices.md) - Production best practices
14 changes: 7 additions & 7 deletions docs/reference/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ app = kit.create_app()

Create and configure FastAPI application.

- Loads all apps from `fastappkit.toml`
- Validates app manifests
- Mounts routers with automatic prefixes
- Returns configured FastAPI application
- Loads all apps from `fastappkit.toml`
- Validates app manifests
- Mounts routers with automatic prefixes
- Returns configured FastAPI application

## Settings API

Expand All @@ -38,7 +38,7 @@ Get the current settings instance.
from fastappkit.conf import get_settings

settings = get_settings()
db_url = settings.DATABASE_URL
db_url = settings.database_url
```

### set_settings()
Expand Down Expand Up @@ -198,5 +198,5 @@ print(sql)

## Learn More

- [Architecture](../advanced/architecture.md) - System architecture
- [Extending fastappkit](../advanced/extending-fastappkit.md) - Extension guide
- [Architecture](../advanced/architecture.md) - System architecture
- [Extending fastappkit](../advanced/extending-fastappkit.md) - Extension guide
Loading