Architecture

Understanding the layered architecture of ForgeAPI.

ForgeAPI follows a 6-layer architecture pattern for maximum separation of concerns and testability.

Directory Structure

app
api
v1
endpoints
router.py
core
config.py
security.py
models
user.py
base.py
services
auth.py
user.py
repositories
user.py

The 6 Layers

LayerResponsibilityLocation
1. APIHTTP request/response handlingapp/api/
2. ServicesBusiness logic orchestrationapp/services/
3. RepositoriesData access abstractionapp/repositories/
4. ModelsDatabase entity definitionsapp/models/
5. SchemasRequest/response validationapp/schemas/
6. CoreConfiguration and utilitiesapp/core/

Configuration

All configuration is centralized in the settings module:

app/core/config.py
import os
from pydantic import BaseSettings

class Settings(BaseSettings):
    # Application
    APP_NAME: str = "ForgeAPI"
    DEBUG: bool = False
    
    # Database
    DATABASE_URL: str
    
    # Security
    SECRET_KEY: str
    ACCESS_TOKEN_EXPIRE_MINUTES: int = 30
    
    class Config:
        env_file = ".env"

settings = Settings()

Environment Variables

Never commit sensitive values like SECRET_KEY to version control. Always use environment variables.