// src/architecture.ts
import { z } from "zod";
var architectureNodeTypes = [
  "project",
  "domain",
  "module",
  "component",
  "controller",
  "route",
  "api_endpoint",
  "function",
  "class",
  "database",
  "table",
  "column",
  "queue",
  "job",
  "external_system",
  "config",
  "document",
  "risk"
];
var architectureEdgeTypes = [
  "contains",
  "depends_on",
  "calls",
  "reads_from",
  "writes_to",
  "exposes",
  "foreign_key_to",
  "impacts",
  "documents"
];
var ArchitectureNodeTypeSchema = z.enum(architectureNodeTypes);
var ArchitectureEdgeTypeSchema = z.enum(architectureEdgeTypes);
var ProjectMetadataSchema = z.object({
  name: z.string(),
  rootPath: z.string(),
  packageManager: z.string().optional(),
  version: z.string().optional(),
  languages: z.array(z.string()).default([]),
  frameworks: z.array(z.string()).default([]),
  dependencies: z.record(z.string()).default({}),
  services: z.array(
    z.object({
      name: z.string(),
      path: z.string(),
      packageManager: z.string().optional(),
      version: z.string().optional(),
      languages: z.array(z.string()).default([]),
      frameworks: z.array(z.string()).default([]),
      dependencies: z.record(z.string()).default({})
    })
  ).default([])
});
var SourceLocationSchema = z.object({
  file: z.string(),
  line: z.number().int().positive().optional(),
  column: z.number().int().positive().optional()
});
var ArchitectureNodeSchema = z.object({
  id: z.string().min(1),
  type: ArchitectureNodeTypeSchema,
  label: z.string().min(1),
  path: z.string().optional(),
  description: z.string().optional(),
  source: SourceLocationSchema.optional(),
  metadata: z.record(z.unknown()).default({})
});
var ArchitectureEdgeSchema = z.object({
  id: z.string().min(1),
  type: ArchitectureEdgeTypeSchema,
  source: z.string().min(1),
  target: z.string().min(1),
  label: z.string().optional(),
  metadata: z.record(z.unknown()).default({})
});
var ArchitectureGraphSchema = z.object({
  project: ProjectMetadataSchema,
  nodes: z.array(ArchitectureNodeSchema),
  edges: z.array(ArchitectureEdgeSchema),
  detectedFrameworks: z.array(z.string()).default([]),
  detectedDependencies: z.record(z.string()).default({}),
  generatedAt: z.string().datetime()
});

// src/database.ts
import { z as z2 } from "zod";
var DatabaseColumnSchema = z2.object({
  id: z2.string().min(1),
  tableId: z2.string().min(1),
  name: z2.string().min(1),
  type: z2.string().min(1),
  nullable: z2.boolean().default(false),
  isPrimaryKey: z2.boolean().default(false),
  isForeignKey: z2.boolean().default(false),
  references: z2.object({
    table: z2.string().min(1),
    column: z2.string().min(1).optional()
  }).optional(),
  defaultValue: z2.string().optional(),
  sensitive: z2.boolean().default(false),
  source: z2.object({
    file: z2.string(),
    line: z2.number().int().positive().optional()
  }).optional()
});
var DatabaseIndexSchema = z2.object({
  id: z2.string().min(1),
  tableId: z2.string().min(1),
  name: z2.string().min(1),
  columns: z2.array(z2.string()).default([]),
  unique: z2.boolean().default(false)
});
var DatabaseRelationshipSchema = z2.object({
  id: z2.string().min(1),
  fromTable: z2.string().min(1),
  fromColumn: z2.string().min(1).optional(),
  toTable: z2.string().min(1),
  toColumn: z2.string().min(1).optional(),
  type: z2.string().default("many-to-one"),
  label: z2.string().optional()
});
var DatabaseEnumSchema = z2.object({
  id: z2.string().min(1),
  name: z2.string().min(1),
  values: z2.array(z2.string()).default([]),
  source: z2.object({
    file: z2.string(),
    line: z2.number().int().positive().optional()
  }).optional()
});
var DatabaseTableSchema = z2.object({
  id: z2.string().min(1),
  name: z2.string().min(1),
  schema: z2.string().optional(),
  columns: z2.array(DatabaseColumnSchema).default([]),
  primaryKeys: z2.array(z2.string()).default([]),
  source: z2.object({
    file: z2.string(),
    line: z2.number().int().positive().optional()
  }).optional()
});
var DatabaseSchema = z2.object({
  id: z2.string().min(1),
  name: z2.string().min(1),
  tables: z2.array(DatabaseTableSchema).default([])
});
var DatabaseGraphSchema = z2.object({
  databases: z2.array(DatabaseSchema).default([]),
  tables: z2.array(DatabaseTableSchema).default([]),
  columns: z2.array(DatabaseColumnSchema).default([]),
  relationships: z2.array(DatabaseRelationshipSchema).default([]),
  indexes: z2.array(DatabaseIndexSchema).default([]),
  enums: z2.array(DatabaseEnumSchema).default([]),
  detectedSensitiveFields: z2.array(DatabaseColumnSchema).default([]),
  generatedAt: z2.string().datetime()
});

// src/config.ts
import { z as z4 } from "zod";

// src/review.ts
import { z as z3 } from "zod";
var codeReviewSeverityLevels = ["blocker", "critical", "major", "minor", "info"];
var codeReviewCategories = [
  "security",
  "bug",
  "reliability",
  "performance",
  "maintainability",
  "code_smell",
  "architecture_smell",
  "frontend",
  "backend",
  "database",
  "cache",
  "api",
  "testing",
  "documentation"
];
var codeReviewIssueTypes = [
  "frontend",
  "backend",
  "api",
  "database",
  "cache",
  "security",
  "performance",
  "maintainability",
  "reliability",
  "architecture",
  "testing",
  "documentation"
];
var CodeReviewSeveritySchema = z3.enum(codeReviewSeverityLevels);
var CodeReviewCategorySchema = z3.enum(codeReviewCategories);
var CodeReviewIssueTypeSchema = z3.enum(codeReviewIssueTypes);
var CodeReviewRuleSchema = z3.object({
  id: z3.string().min(1),
  name: z3.string().min(1),
  description: z3.string().min(1),
  severity: CodeReviewSeveritySchema,
  category: CodeReviewCategorySchema,
  appliesTo: z3.array(z3.string()).default([]),
  language: z3.array(z3.string()).default([]),
  framework: z3.array(z3.string()).default([]),
  enabled: z3.boolean().default(true),
  remediation: z3.string().default("Review the finding and update the implementation to follow the rule guidance."),
  examples: z3.array(z3.string()).default([])
});
var CodeReviewIssueSchema = z3.object({
  id: z3.string().min(1),
  ruleId: z3.string().min(1),
  title: z3.string().min(1),
  description: z3.string().min(1),
  severity: CodeReviewSeveritySchema,
  category: CodeReviewCategorySchema,
  type: CodeReviewIssueTypeSchema,
  filePath: z3.string().min(1),
  line: z3.number().int().positive().optional(),
  column: z3.number().int().positive().optional(),
  endLine: z3.number().int().positive().optional(),
  module: z3.string().optional(),
  framework: z3.string().optional(),
  evidence: z3.array(z3.string()).default([]),
  recommendation: z3.string().default("Review this code path and apply the rule-specific remediation."),
  remediation: z3.string().default("Refactor the implementation to remove the risk or document an intentional exception."),
  confidence: z3.number().min(0).max(1).default(0.75),
  tags: z3.array(z3.string()).default([])
});
var countRecord = z3.record(z3.number().int().nonnegative()).default({});
var CodeReviewSummarySchema = z3.object({
  totalIssues: z3.number().int().nonnegative(),
  bySeverity: countRecord,
  byCategory: countRecord,
  byType: countRecord,
  byFile: countRecord,
  byModule: countRecord,
  blocker: z3.number().int().nonnegative().default(0),
  critical: z3.number().int().nonnegative().default(0),
  major: z3.number().int().nonnegative().default(0),
  minor: z3.number().int().nonnegative().default(0),
  info: z3.number().int().nonnegative().default(0)
});
var CodeReviewFileSummarySchema = z3.object({
  filePath: z3.string().min(1),
  issues: z3.number().int().nonnegative(),
  highestSeverity: CodeReviewSeveritySchema.optional(),
  categories: z3.array(CodeReviewCategorySchema).default([]),
  module: z3.string().optional()
});
var CodeReviewModuleSummarySchema = z3.object({
  module: z3.string().min(1),
  issues: z3.number().int().nonnegative(),
  highestSeverity: CodeReviewSeveritySchema.optional(),
  categories: z3.array(CodeReviewCategorySchema).default([])
});
var CodeReviewReportSchema = z3.object({
  projectName: z3.string().min(1),
  rootPath: z3.string().min(1),
  generatedAt: z3.string().datetime(),
  summary: CodeReviewSummarySchema,
  issues: z3.array(CodeReviewIssueSchema),
  rules: z3.array(CodeReviewRuleSchema),
  files: z3.array(CodeReviewFileSummarySchema).default([]),
  modules: z3.array(CodeReviewModuleSummarySchema).default([])
});

// src/config.ts
var DEFAULT_OUTPUT_DIR = ".archlens";
var defaultExcludePatterns = [
  "node_modules/**",
  "**/node_modules/**",
  ".pnpm-store/**",
  "**/.pnpm/**",
  "dist/**",
  "**/dist/**",
  "build/**",
  "**/build/**",
  ".next/**",
  "**/.next/**",
  ".turbo/**",
  "**/.turbo/**",
  ".git/**",
  "coverage/**",
  "**/coverage/**",
  ".archlens/**",
  "**/.archlens/**",
  "**/dashboard-dist/**",
  "**/*.min.js",
  "**/*.bundle.js",
  "**/.cache/**",
  "**/vendor/**"
];
var architectureViewNodeTypes = [
  "project",
  "module",
  "component",
  "route",
  "controller",
  "api_endpoint",
  "class",
  "table",
  "database",
  "external_system"
];
var ArchLensConfigSchema = z4.object({
  projectName: z4.string().optional(),
  rootDir: z4.string().default("."),
  outputDir: z4.string().default(DEFAULT_OUTPUT_DIR),
  include: z4.array(z4.string()).default(["**/*"]),
  exclude: z4.array(z4.string()).default([...defaultExcludePatterns]),
  dashboard: z4.object({
    port: z4.number().int().positive().default(5173),
    host: z4.string().default("127.0.0.1")
  }).default({ port: 5173, host: "127.0.0.1" }),
  review: z4.object({
    enabled: z4.boolean().default(true),
    severityThreshold: CodeReviewSeveritySchema.default("info"),
    rules: z4.record(z4.boolean()).default({}),
    ignore: z4.array(z4.string()).default(["tests/**", "**/*.spec.ts", "**/*.test.ts"])
  }).default({
    enabled: true,
    severityThreshold: "info",
    rules: {},
    ignore: ["tests/**", "**/*.spec.ts", "**/*.test.ts"]
  }),
  llm: z4.object({
    enabled: z4.boolean().default(false),
    /**
     * Optional provider identifier (provider-specific string).
     * When unset, `chat` falls back to printing grounded context only.
     */
    provider: z4.string().optional(),
    /** Provider-specific model name (optional). */
    model: z4.string().optional(),
    /**
     * Name of an environment variable containing the provider API key.
     * If set, the provider may read from `process.env[apiKeyEnv]`.
     */
    apiKeyEnv: z4.string().optional()
  }).default({ enabled: false })
});

// src/solution.ts
import { z as z5 } from "zod";
var EvidenceSchema = z5.object({
  kind: z5.string().min(1),
  file: z5.string().min(1),
  line: z5.number().int().positive().optional(),
  excerpt: z5.string().min(1).optional()
});
var ConfidenceSchema = z5.enum(["low", "medium", "high"]);
var ProviderSchema = z5.enum([
  "aws",
  "azure",
  "gcp",
  "firebase",
  "stripe",
  "razorpay",
  "paypal",
  "sendgrid",
  "mailgun",
  "smtp",
  "twilio",
  "whatsapp",
  "auth0",
  "keycloak",
  "oidc",
  "sentry",
  "datadog",
  "newrelic",
  "prometheus",
  "grafana",
  "elasticsearch",
  "opensearch",
  "kafka",
  "rabbitmq",
  "sqs",
  "s3",
  "cloudinary",
  "unknown"
]);
var ComponentTypeSchema = z5.enum([
  "service",
  "client",
  "api",
  "worker",
  "database",
  "cache",
  "queue",
  "object_storage",
  "external_api",
  "payment",
  "email",
  "messaging",
  "auth",
  "monitoring",
  "search",
  "cloud",
  "cicd",
  "infrastructure"
]);
var DetectedSignalSchema = z5.object({
  id: z5.string().min(1),
  type: ComponentTypeSchema,
  label: z5.string().min(1),
  provider: ProviderSchema.default("unknown"),
  confidence: ConfidenceSchema.default("medium"),
  source: SourceLocationSchema.optional(),
  evidence: z5.array(EvidenceSchema).default([]),
  metadata: z5.record(z5.unknown()).default({})
});
var EnvVarSchema = z5.object({
  key: z5.string().min(1),
  inferredType: ComponentTypeSchema,
  provider: ProviderSchema.default("unknown"),
  confidence: ConfidenceSchema.default("medium"),
  sourceFile: z5.string().min(1),
  evidence: z5.array(EvidenceSchema).default([])
});
var InfraResourceSchema = z5.object({
  id: z5.string().min(1),
  kind: z5.string().min(1),
  name: z5.string().min(1).optional(),
  provider: ProviderSchema.default("unknown"),
  confidence: ConfidenceSchema.default("medium"),
  sourceFile: z5.string().min(1),
  evidence: z5.array(EvidenceSchema).default([]),
  metadata: z5.record(z5.unknown()).default({})
});
var ServiceSchema = z5.object({
  id: z5.string().min(1),
  name: z5.string().min(1),
  path: z5.string().min(1),
  kind: z5.enum(["node", "unknown"]).default("unknown"),
  detected: z5.array(DetectedSignalSchema).default([]),
  env: z5.array(EnvVarSchema).default([]),
  infra: z5.array(InfraResourceSchema).default([]),
  dependencies: z5.record(z5.string()).default({}),
  frameworks: z5.array(z5.string()).default([]),
  languages: z5.array(z5.string()).default([]),
  exposedPorts: z5.array(z5.number().int().positive()).default([]),
  generatedAt: z5.string().datetime()
});
var WorkspaceEdgeSchema = z5.object({
  id: z5.string().min(1),
  type: z5.enum(["calls", "depends_on", "shares", "publishes", "consumes"]).default("calls"),
  source: z5.string().min(1),
  target: z5.string().min(1),
  label: z5.string().optional(),
  evidence: z5.array(EvidenceSchema).default([]),
  metadata: z5.record(z5.unknown()).default({})
});
var WorkspaceGraphSchema = z5.object({
  workspaceName: z5.string().min(1),
  rootPath: z5.string().min(1),
  generatedAt: z5.string().datetime(),
  services: z5.array(ServiceSchema).default([]),
  edges: z5.array(WorkspaceEdgeSchema).default([]),
  externalSystems: z5.array(DetectedSignalSchema).default([]),
  risks: z5.array(
    z5.object({
      id: z5.string().min(1),
      severity: z5.enum(["low", "medium", "high"]),
      title: z5.string().min(1),
      detail: z5.string().min(1),
      evidence: z5.array(EvidenceSchema).default([])
    })
  ).default([])
});

// src/dbUsage.ts
import { z as z6 } from "zod";
var UsageTypeSchema = z6.enum([
  "read",
  "write",
  "filter",
  "join",
  "sort",
  "group",
  "select",
  "validation",
  "response",
  "unknown"
]);
var AccessPatternSchema = z6.enum([
  "prisma_select",
  "prisma_where",
  "prisma_create_data",
  "prisma_update_data",
  "prisma_delete_filter",
  "prisma_include",
  "prisma_order_by",
  "raw_sql_select",
  "raw_sql_insert",
  "raw_sql_update",
  "raw_sql_delete",
  "orm_entity_property",
  "sequelize_model_field",
  "mongoose_schema_field",
  "typeorm_column",
  "dto_property",
  "response_mapping",
  "validation_schema",
  "env_or_config",
  "unknown"
]);
var UsageRecordSchema = z6.object({
  id: z6.string().min(1),
  tableName: z6.string().min(1),
  fieldName: z6.string().min(1),
  usageType: UsageTypeSchema,
  accessPattern: AccessPatternSchema,
  filePath: z6.string().min(1),
  line: z6.number().int().positive(),
  column: z6.number().int().positive().optional(),
  module: z6.string().optional(),
  className: z6.string().optional(),
  functionName: z6.string().optional(),
  apiEndpoint: z6.string().optional(),
  framework: z6.string().optional(),
  codeSnippet: z6.string().optional(),
  confidence: z6.enum(["high", "medium", "low"]).default("medium"),
  evidence: z6.array(z6.string()).default([])
});
var TableUsageSchema = z6.object({
  tableName: z6.string().min(1),
  source: z6.string().optional(),
  usageCount: z6.number().int().nonnegative(),
  readCount: z6.number().int().nonnegative(),
  writeCount: z6.number().int().nonnegative(),
  unknownCount: z6.number().int().nonnegative(),
  modules: z6.array(z6.string()).default([]),
  files: z6.array(z6.string()).default([]),
  fields: z6.array(z6.string()).default([])
});
var FieldUsageSchema = z6.object({
  tableName: z6.string().min(1),
  fieldName: z6.string().min(1),
  fieldType: z6.string().optional(),
  source: z6.string().optional(),
  usageCount: z6.number().int().nonnegative(),
  readCount: z6.number().int().nonnegative(),
  writeCount: z6.number().int().nonnegative(),
  unknownCount: z6.number().int().nonnegative(),
  modules: z6.array(z6.string()).default([]),
  classes: z6.array(z6.string()).default([]),
  functions: z6.array(z6.string()).default([]),
  apiEndpoints: z6.array(z6.string()).default([]),
  files: z6.array(z6.string()).default([]),
  usages: z6.array(z6.string()).default([])
});
var DbUsageRiskSchema = z6.object({
  id: z6.string().min(1),
  severity: z6.enum(["low", "medium", "high"]),
  title: z6.string().min(1),
  detail: z6.string().min(1),
  tableName: z6.string().optional(),
  fieldName: z6.string().optional(),
  filePath: z6.string().optional(),
  line: z6.number().int().positive().optional()
});
var DbUsageSummarySchema = z6.object({
  totalTables: z6.number().int().nonnegative(),
  totalFields: z6.number().int().nonnegative(),
  totalUsages: z6.number().int().nonnegative(),
  tablesWithUsage: z6.number().int().nonnegative(),
  fieldsWithUsage: z6.number().int().nonnegative(),
  unusedFields: z6.number().int().nonnegative(),
  highImpactFields: z6.number().int().nonnegative(),
  byUsageType: z6.record(z6.string(), z6.number().int().nonnegative()).default({}),
  byModule: z6.record(z6.string(), z6.number().int().nonnegative()).default({})
});
var DatabaseFieldUsageReportSchema = z6.object({
  projectName: z6.string().min(1),
  rootPath: z6.string().min(1),
  generatedAt: z6.string().min(1),
  databaseSources: z6.array(z6.string()).default([]),
  tables: z6.array(TableUsageSchema).default([]),
  fields: z6.array(FieldUsageSchema).default([]),
  usages: z6.array(UsageRecordSchema).default([]),
  summary: DbUsageSummarySchema,
  risks: z6.array(DbUsageRiskSchema).default([])
});
var WorkspaceDbFieldUsageReportSchema = DatabaseFieldUsageReportSchema.extend({
  workspaceName: z6.string().min(1),
  services: z6.array(
    z6.object({
      name: z6.string().min(1),
      path: z6.string().min(1),
      reportPath: z6.string().optional()
    })
  ).default([]),
  sharedTables: z6.array(
    z6.object({
      tableName: z6.string(),
      services: z6.array(z6.string()),
      writeServices: z6.array(z6.string()).default([])
    })
  ).default([]),
  sharedFields: z6.array(
    z6.object({
      tableName: z6.string(),
      fieldName: z6.string(),
      services: z6.array(z6.string()),
      writeServices: z6.array(z6.string()).default([])
    })
  ).default([])
});
export {
  AccessPatternSchema,
  ArchLensConfigSchema,
  ArchitectureEdgeSchema,
  ArchitectureEdgeTypeSchema,
  ArchitectureGraphSchema,
  ArchitectureNodeSchema,
  ArchitectureNodeTypeSchema,
  CodeReviewCategorySchema,
  CodeReviewFileSummarySchema,
  CodeReviewIssueSchema,
  CodeReviewIssueTypeSchema,
  CodeReviewModuleSummarySchema,
  CodeReviewReportSchema,
  CodeReviewRuleSchema,
  CodeReviewSeveritySchema,
  CodeReviewSummarySchema,
  ComponentTypeSchema,
  ConfidenceSchema,
  DEFAULT_OUTPUT_DIR,
  DatabaseColumnSchema,
  DatabaseEnumSchema,
  DatabaseFieldUsageReportSchema,
  DatabaseGraphSchema,
  DatabaseIndexSchema,
  DatabaseRelationshipSchema,
  DatabaseSchema,
  DatabaseTableSchema,
  DbUsageRiskSchema,
  DbUsageSummarySchema,
  DetectedSignalSchema,
  EnvVarSchema,
  EvidenceSchema,
  FieldUsageSchema,
  InfraResourceSchema,
  ProjectMetadataSchema,
  ProviderSchema,
  ServiceSchema,
  SourceLocationSchema,
  TableUsageSchema,
  UsageRecordSchema,
  UsageTypeSchema,
  WorkspaceDbFieldUsageReportSchema,
  WorkspaceEdgeSchema,
  WorkspaceGraphSchema,
  architectureEdgeTypes,
  architectureNodeTypes,
  architectureViewNodeTypes,
  codeReviewCategories,
  codeReviewIssueTypes,
  codeReviewSeverityLevels,
  defaultExcludePatterns
};
