densha 0.1.5

Next.js-like web application framework built with Kotoba
Documentation
// Densha Configuration - Kotoba統合設定
// このファイルはkotoba-kotobasによって解析される
// dag.jsonnetと連携してプロセスネットワークを構成

{
  // ==========================================
  // Densha基本設定
  // ==========================================
  densha: {
    name: "densha-app",
    version: "0.1.2",
    framework: "kotoba-integrated",
    build_system: "dag-jsonnet",
    process_network_enabled: true,
  },

  // ==========================================
  // Kotoba統合設定
  // ==========================================
  kotoba: {
    version: "0.1.1",
    features: [
      "jsonnet",
      "graph-processing",
      "tsx-generation",
      "server-integration",
      "rewrite-engine",
      "storage-merkle"
    ],
    dag_config: "dag.jsonnet",
    strong_integration: true,
  },

  // ==========================================
  // サーバー設定 (kotoba-server統合)
  // ==========================================
  server: {
    host: "127.0.0.1",
    port: 8100,
    max_connections: 1000,
    timeout_ms: 30000,
    routes: [
      {
        pattern: "/api/*",
        handler: "api_handler",
        middleware: ["cors", "auth", "rate_limit"],
        methods: ["GET", "POST", "PUT", "DELETE"],
      },
      {
        pattern: "/_next/*",
        handler: "static_handler",
        middleware: ["cache"],
        methods: ["GET"],
      },
      {
        pattern: "/app/*",
        handler: "page_handler",
        middleware: ["ssr"],
        methods: ["GET"],
      },
    ],
    middleware: {
      cors: {
        type: "cors",
        allowed_origins: ["*"],
        allowed_methods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
        allowed_headers: ["Authorization", "Content-Type", "Accept"],
        credentials: true,
      },
      auth: {
        type: "jwt",
        algorithm: "RS256",
        secret: std.extVar("JWT_SECRET", "default-secret-change-in-production"),
        expiration: "1h",
      },
      rate_limit: {
        type: "token_bucket",
        capacity: 100,
        refill_rate: 10,
        window_ms: 60000,
      },
      cache: {
        type: "memory",
        max_age: 3600,
        private: false,
      },
      ssr: {
        type: "ssr",
        enabled: true,
        cache_enabled: false,
      },
    },
    ssl: {
      enabled: false,
      cert_path: null,
      key_path: null,
    },
  },

  // ==========================================
  // UI設定 (kotoba2tsx統合)
  // ==========================================
  ui: {
    framework: "react",
    language: "typescript",
    styling: "tailwind",
    ssr_enabled: true,
    components: {
      layout: "app/layout.kotoba",
      pages: std.map(function(f) "app/" + f + ".kotoba", [
        "page", "about", "contact", "blog", "api-docs"
      ]),
      dynamic_pages: [
        "app/blog/[id]/page.kotoba",
        "app/users/[id]/page.kotoba"
      ],
    },
    build: {
      output_dir: ".densha/build",
      target_platforms: ["web", "desktop"],
      minify: true,
      source_maps: true,
      css_code_split: true,
    },
    performance: {
      code_splitting: true,
      lazy_loading: true,
      image_optimization: true,
      preload: true,
    },
  },

  // ==========================================
  // ストレージ設定 (kotoba-storage統合)
  // ==========================================
  storage: {
    type: "rocksdb",
    path: "./.densha/storage",
    merkle_enabled: true,
    mvcc_enabled: true,
    cache_size: "1GB",
    compression: "snappy",
    backup: {
      enabled: true,
      interval_hours: 24,
      retention_days: 30,
    },
  },

  // ==========================================
  // グラフ設定 (kotoba-graph統合)
  // ==========================================
  graph: {
    type: "property_graph",
    schema_validation: true,
    indexing: {
      enabled: true,
      auto_index: ["id", "type", "created_at"],
    },
    queries: {
      gql_enabled: true,
      cypher_enabled: false,
      gremlin_enabled: false,
    },
  },

  // ==========================================
  // 書き換えエンジン設定 (kotoba-rewrite統合)
  // ==========================================
  rewrite: {
    dpo_enabled: true,
    strategies: [
      "exhaust",
      "once",
      "while"
    ],
    rules: {
      validation: true,
      optimization: true,
      custom_rules_path: "./rules/",
    },
  },

  // ==========================================
  // 実行エンジン設定 (kotoba-execution統合)
  // ==========================================
  execution: {
    parallel_processing: true,
    query_cache: {
      enabled: true,
      size: "100MB",
      ttl: "1h",
    },
    planner: {
      optimization: true,
      statistics: true,
    },
  },

  // ==========================================
  // プロセスネットワーク設定
  // ==========================================
  process_network: {
    enabled: true,
    dag_validation: true,
    build_order_check: true,
    dependency_tracking: true,
    error_recovery: true,
    hot_reload: true,
    monitoring: {
      enabled: true,
      metrics_endpoint: "/metrics",
      health_endpoint: "/health",
    },
  },

  // ==========================================
  // 環境別設定
  // ==========================================
  environment: std.mergePatch({
    name: "development",
    debug: true,
    hot_reload: true,
    source_maps: true,
    log_level: "debug",
    cache_enabled: false,
    optimization: false,
  }, if std.extVar("NODE_ENV", "development") == "production" then {
    name: "production",
    debug: false,
    hot_reload: false,
    source_maps: false,
    log_level: "info",
    cache_enabled: true,
    optimization: true,
    monitoring: true,
  } else if std.extVar("NODE_ENV", "development") == "staging" then {
    name: "staging",
    debug: false,
    hot_reload: false,
    source_maps: true,
    log_level: "info",
    cache_enabled: true,
    optimization: true,
    monitoring: true,
  } else {}),

  // ==========================================
  // 外部サービス統合
  // ==========================================
  external_services: {
    database: {
      type: "postgresql",
      host: std.extVar("DB_HOST", "localhost"),
      port: std.extVar("DB_PORT", 5432),
      database: std.extVar("DB_NAME", "densha"),
      username: std.extVar("DB_USER", "densha"),
      password: std.extVar("DB_PASSWORD", "password"),
      ssl: std.extVar("DB_SSL", "require"),
      pool_size: 20,
    },
    redis: {
      host: std.extVar("REDIS_HOST", "localhost"),
      port: std.extVar("REDIS_PORT", 6379),
      password: std.extVar("REDIS_PASSWORD", ""),
      db: std.extVar("REDIS_DB", 0),
      pool_size: 10,
    },
    email: {
      provider: "smtp",
      host: std.extVar("SMTP_HOST", "smtp.gmail.com"),
      port: std.extVar("SMTP_PORT", 587),
      username: std.extVar("SMTP_USER", ""),
      password: std.extVar("SMTP_PASSWORD", ""),
      from: std.extVar("EMAIL_FROM", "noreply@densha.dev"),
    },
  },

  // ==========================================
  // セキュリティ設定
  // ==========================================
  security: {
    csrf_protection: true,
    xss_protection: true,
    hsts: {
      enabled: true,
      max_age: 31536000,
      include_subdomains: true,
    },
    csp: {
      enabled: true,
      default_src: "'self'",
      script_src: "'self' 'unsafe-inline'",
      style_src: "'self' 'unsafe-inline' https://fonts.googleapis.com",
    },
    rate_limiting: {
      enabled: true,
      global_limit: "1000/minute",
      endpoint_limits: {
        "/api/auth/login": "5/minute",
        "/api/auth/register": "3/minute",
        "/api/users": "100/minute",
      },
    },
  },

  // ==========================================
  // モニタリング・ロギング
  // ==========================================
  monitoring: {
    enabled: $.environment.monitoring,
    metrics: {
      enabled: true,
      exporter: "prometheus",
      endpoint: "/metrics",
      buckets: [0.1, 0.5, 1.0, 2.5, 5.0, 10.0],
    },
    tracing: {
      enabled: true,
      jaeger_endpoint: std.extVar("JAEGER_ENDPOINT", ""),
      sampling_rate: if $.environment.name == "production" then 0.1 else 1.0,
    },
    logging: {
      level: $.environment.log_level,
      format: "json",
      outputs: ["stdout"],
      file_output: if $.environment.name == "production" then "/var/log/densha/app.log" else null,
    },
  },

  // ==========================================
  // デプロイメント設定
  // ==========================================
  deployment: {
    docker: {
      enabled: true,
      image_name: "densha-app",
      image_tag: $.densha.version,
      base_image: "rust:1.70-slim",
      port: $.server.port,
      environment: [
        "NODE_ENV=" + $.environment.name,
        "RUST_LOG=" + $.environment.log_level,
      ],
      volumes: [
        "./.densha/storage:/app/storage",
        "./logs:/app/logs",
      ],
    },
    kubernetes: {
      enabled: false,
      namespace: "densha",
      replicas: 3,
      resources: {
        requests: {
          cpu: "500m",
          memory: "1Gi",
        },
        limits: {
          cpu: "2000m",
          memory: "4Gi",
        },
      },
    },
  },

  // ==========================================
  // 開発者設定
  // ==========================================
  development: {
    watch_paths: [
      "app/",
      "api/",
      "public/",
      "densha.jsonnet",
      "dag.jsonnet",
    ],
    ignore_patterns: [
      "**/node_modules/**",
      "**/.git/**",
      "**/target/**",
      "**/*.log",
    ],
    auto_restart: true,
    browser_sync: {
      enabled: true,
      port: 3001,
      open_browser: true,
    },
  },
}