You are an expert code reviewer. Your task is to analyze the provided code files and provide a comprehensive code review. For each file, consider:

1. Code Quality: Assess readability, maintainability, and adherence to best practices
2. Potential Issues: Identify bugs, security vulnerabilities, or performance concerns
3. Suggestions: Provide specific recommendations for improvements

Format your review as follows:
1. Start with a brief overview of all files
2. For each file, provide:
   - A summary of the file's purpose
   - Key findings (both positive and negative)
   - Specific recommendations
3. End with any overall suggestions for the codebase

Your review should be detailed but concise, focusing on the most important aspects of the code.

Files to review:

File: ./src/lib/env.ts
Content:
import { z } from "https://deno.land/x/zod@v3.21.4/mod.ts";

function parseEnv(
  value: string,
  envVars: Record<string, string>
): string | string[] | number {
  if (value.includes(" ")) {
    return value.split(" ");
  }

  if (value.startsWith("$")) {
    const refKey = value.slice(1);
    return envVars[refKey] || value;
  }

  if (!isNaN(Number(value))) {
    return Number(value);
  }

  return value;
}

/**
 * Loads environment variables from a file.
 *
 * @param filename - The name of the file to load.
 * @returns The environment variables.
 */
export async function loadEnv(
  filename: string
): Promise<Record<string, string | string[] | number>> {
  try {
    const envText = await Deno.readTextFile(filename);
    const envVars: Record<string, string | string[] | number> = {};

    envText.split("\n").forEach((line) => {
      const [key, ...valueParts] = line.split("=").map((part) => part.trim());
      if (key && valueParts.length > 0) {
        const value = valueParts.join("=");
        envVars[key] = parseEnv(value, envVars as Record<string, string>);
      }
    });

    return envVars;
  } catch (error) {
    console.warn(`Failed to load ${filename} file:`, error);
    return {};
  }
}

export const envSchema = z.object({
  NODE_ENV: z.enum(["development", "production", "test"]).optional(),
  // PORT: z.coerce.number(),
  // DATABASE_URL: z.string().url(),
  // ALLOWED_ORIGINS: z.array(z.string().url()),
});

export type Env = z.infer<typeof envSchema>;

export async function loadAndParseEnv(): Promise<Env> {
  const nodeEnv = Deno.env.get("NODE_ENV")?.toLowerCase();
  let loadedEnv: Record<string, string | string[] | number> = {};

  if (nodeEnv) {
    try {
      loadedEnv = await loadEnv(`.env.${nodeEnv}`);
    } catch {
      console.warn(`Failed to load .env.${nodeEnv}, falling back to .env`);
    }
  }

  if (Object.keys(loadedEnv).length === 0) {
    loadedEnv = await loadEnv(".env");
  }

  const combinedEnv = { ...loadedEnv, ...Deno.env.toObject() };

  return envSchema.parse(combinedEnv);
}

export const env = await loadAndParseEnv();



PROMPT: You are an expert code reviewer. Your task is to analyze the provided code files and provide a comprehensive code review. For each file, consider:

1. Code Quality: Assess readability, maintainability, and adherence to best practices
2. Potential Issues: Identify bugs, security vulnerabilities, or performance concerns
3. Suggestions: Provide specific recommendations for improvements

Format your review as follows:
1. Start with a brief overview of all files
2. For each file, provide:
   - A summary of the file's purpose
   - Key findings (both positive and negative)
   - Specific recommendations
3. End with any overall suggestions for the codebase

Your review should be detailed but concise, focusing on the most important aspects of the code.

Files to review:

File: ./src/lib/env.ts
Content:
import { z } from "https://deno.land/x/zod@v3.21.4/mod.ts";

function parseEnv(
  value: string,
  envVars: Record<string, string>
): string | string[] | number {
  if (value.includes(" ")) {
    return value.split(" ");
  }

  if (value.startsWith("$")) {
    const refKey = value.slice(1);
    return envVars[refKey] || value;
  }

  if (!isNaN(Number(value))) {
    return Number(value);
  }

  return value;
}

/**
 * Loads environment variables from a file.
 *
 * @param filename - The name of the file to load.
 * @returns The environment variables.
 */
export async function loadEnv(
  filename: string
): Promise<Record<string, string | string[] | number>> {
  try {
    const envText = await Deno.readTextFile(filename);
    const envVars: Record<string, string | string[] | number> = {};

    envText.split("\n").forEach((line) => {
      const [key, ...valueParts] = line.split("=").map((part) => part.trim());
      if (key && valueParts.length > 0) {
        const value = valueParts.join("=");
        envVars[key] = parseEnv(value, envVars as Record<string, string>);
      }
    });

    return envVars;
  } catch (error) {
    console.warn(`Failed to load ${filename} file:`, error);
    return {};
  }
}

export const envSchema = z.object({
  NODE_ENV: z.enum(["development", "production", "test"]).optional(),
  // PORT: z.coerce.number(),
  // DATABASE_URL: z.string().url(),
  // ALLOWED_ORIGINS: z.array(z.string().url()),
});

export type Env = z.infer<typeof envSchema>;

export async function loadAndParseEnv(): Promise<Env> {
  const nodeEnv = Deno.env.get("NODE_ENV")?.toLowerCase();
  let loadedEnv: Record<string, string | string[] | number> = {};

  if (nodeEnv) {
    try {
      loadedEnv = await loadEnv(`.env.${nodeEnv}`);
    } catch {
      console.warn(`Failed to load .env.${nodeEnv}, falling back to .env`);
    }
  }

  if (Object.keys(loadedEnv).length === 0) {
    loadedEnv = await loadEnv(".env");
  }

  const combinedEnv = { ...loadedEnv, ...Deno.env.toObject() };

  return envSchema.parse(combinedEnv);
}

export const env = await loadAndParseEnv();