Scenario 2: Scaffolding + Internal Apps¶
This guide covers building a project with internal apps (like Django apps).
When to Use This Approach¶
Use internal apps when:
- You're building a single project
- You want modular organization within the project
- You need shared migrations across features
- You want to organize code into logical components
- You don't need reusable components across projects
Step-by-Step Guide¶
1. Create Project¶
2. Update Dependency Versions¶
IMPORTANT: Update dependency versions in pyproject.toml from * to specific ranges:
[tool.poetry.dependencies]
python = ">=3.11,<4.0"
fastapi = ">=0.120.0,<0.130"
sqlalchemy = ">=2.0,<3.0"
alembic = ">=1.17.2,<1.18"
3. Configure Environment¶
Edit .env file:
4. Create Internal App¶
This creates:
- apps/blog/__init__.py (with register() function)
- apps/blog/models.py (imports Base from core.models)
- apps/blog/router.py (FastAPI router)
- Automatically adds "apps.blog" to fastappkit.toml
5. Add Models¶
Edit apps/blog/models.py:
from core.models import Base
from sqlalchemy import Column, Integer, String
class Post(Base):
__tablename__ = "posts"
id = Column(Integer, primary_key=True)
title = Column(String)
content = Column(String)
IMPORTANT: Internal apps must import Base from core.models, not create their own.
6. Create Migration¶
This creates a migration in core/db/migrations/versions/ (shared with core).
7. Apply Migrations¶
This applies all migrations (core + internal apps) in the correct order.
8. Start Development Server¶
Your API is now running at http://127.0.0.1:8000 with routes mounted at /blog/.
Development Workflow¶
Adding More Internal Apps¶
Each app is automatically added to fastappkit.toml.
Creating Migrations¶
# For a specific app
fastappkit migrate app blog makemigrations -m "Add post model"
# For core (if you have core models)
fastappkit migrate core -m "Add session table"
Applying Migrations¶
# Apply all migrations (recommended)
fastappkit migrate all
# Or apply core + internal apps only
fastappkit migrate upgrade
Testing Internal Apps¶
-
Manual testing:
-
Test specific endpoints:
Migration Workflow for Internal Apps¶
Internal apps share the migration directory with core (core/db/migrations/):
-
Create migration:
-
Review migration:
-
Apply migration:
-
If needed, downgrade:
Important Notes¶
- All commands must be run from project root (where
fastappkit.tomlis located) - Internal apps share migration directory with core (
core/db/migrations/) - Internal apps can import from
core.modelsand other internal apps - Internal apps are automatically added to
fastappkit.tomlby CLI - Ensure
apps/<name>/__init__.pyexists (created by CLI, but verify if manual)
Quick Commands Reference¶
# Create project
fastappkit core new myproject && cd myproject
# Create internal app
fastappkit app new blog
# Create migration
fastappkit migrate app blog makemigrations -m "Add post model"
# Apply all migrations
fastappkit migrate all
# Start development server
fastappkit core dev
Common Patterns¶
App Dependencies¶
Internal apps can depend on other internal apps:
# apps/blog/models.py
from apps.auth.models import User
from core.models import Base
from sqlalchemy import Column, Integer, ForeignKey
class Post(Base):
__tablename__ = "posts"
author_id = Column(Integer, ForeignKey("users.id"))
Cross-App Relationships¶
Since all internal apps share the same Base and migration directory, you can create relationships between apps:
# apps/blog/models.py
from apps.auth.models import User
class Post(Base):
author = relationship("User", back_populates="posts")
Next Steps¶
- Full Ecosystem - Add external apps for reusable components
- Creating Apps - Detailed app creation guide
- Migrations - Complete migration workflow