> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/igorek05m/daily-geogame/llms.txt
> Use this file to discover all available pages before exploring further.

# Configuration

> Configure environment variables and settings for Daily GeoGame

## Environment variables

Daily GeoGame uses environment variables to configure the application. Create a `.env.local` file in the root directory of your project:

```bash theme={null}
touch .env.local
```

### Required variables

#### MONGODB\_URI

The MongoDB connection string is the only required environment variable:

```bash theme={null}
MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/database?retryWrites=true&w=majority
```

<Warning>
  Never commit your `.env.local` file to version control. It should be listed in `.gitignore`.
</Warning>

## MongoDB Atlas setup

Daily GeoGame uses MongoDB Atlas for data storage. Follow these steps to set up your database:

<Steps>
  <Step title="Create a MongoDB Atlas account">
    Sign up for a free account at [MongoDB Atlas](https://www.mongodb.com/cloud/atlas).
  </Step>

  <Step title="Create a new cluster">
    Create a new cluster (the free M0 tier is sufficient for development and small deployments).
  </Step>

  <Step title="Configure network access">
    Add your IP address to the IP Access List, or allow access from anywhere (0.0.0.0/0) for development.

    <Warning>
      For production, restrict access to specific IP addresses or use VPC peering.
    </Warning>
  </Step>

  <Step title="Create database user">
    Create a database user with read and write permissions. Save the username and password.
  </Step>

  <Step title="Get connection string">
    Click "Connect" on your cluster, choose "Connect your application", and copy the connection string. Replace `<password>` with your database user password.
  </Step>

  <Step title="Add to .env.local">
    Paste the connection string into your `.env.local` file:

    ```bash theme={null}
    MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/geogame?retryWrites=true&w=majority
    ```
  </Step>
</Steps>

## MongoDB connection handling

The application handles MongoDB connections through `app/lib/mongodb.ts`:

```typescript theme={null}
import { MongoClient } from 'mongodb';

const uri = process.env.MONGODB_URI;

let client: MongoClient;
let clientPromise: Promise<MongoClient>;

if (!uri) {
  console.warn("WARN: Missing MONGODB_URI environment variable");
  clientPromise = Promise.reject(new Error("Missing MONGODB_URI"));
} else {
  try {
    client = new MongoClient(uri);
    clientPromise = client.connect();
  } catch (e) {
    console.error('Failed to initialize MongoDB client', e);
    clientPromise = Promise.reject(e);
  }
}

export default clientPromise;
```

<Note>
  If `MONGODB_URI` is missing, the application will log a warning but won't crash. However, database-dependent features won't work.
</Note>

## Next.js configuration

The Next.js configuration is minimal by default (`next.config.ts`):

```typescript theme={null}
import type { NextConfig } from "next";

const nextConfig: NextConfig = {
  /* config options here */
};

export default nextConfig;
```

You can customize this file to add:

* Image optimization domains
* Custom headers
* Redirects and rewrites
* Experimental features

## TypeScript configuration

The project uses strict TypeScript settings (`tsconfig.json`):

```json theme={null}
{
  "compilerOptions": {
    "target": "ES2017",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "bundler",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "incremental": true,
    "plugins": [
      {
        "name": "next"
      }
    ],
    "paths": {
      "@/*": ["./*"]
    }
  },
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
  "exclude": ["node_modules"]
}
```

Key features:

* **Strict mode** enabled for better type safety
* **Path alias** `@/*` for cleaner imports
* **ES2017** target for modern JavaScript features

## Development vs production settings

### Development

For local development:

```bash .env.local theme={null}
MONGODB_URI=mongodb+srv://dev-user:password@dev-cluster.mongodb.net/geogame-dev?retryWrites=true&w=majority
```

* Use a separate development database
* Allow broader network access (0.0.0.0/0)
* Enable detailed error messages

### Production

For production deployment:

```bash theme={null}
MONGODB_URI=mongodb+srv://prod-user:password@prod-cluster.mongodb.net/geogame?retryWrites=true&w=majority
```

* Use a dedicated production database
* Restrict network access to your deployment platform's IP ranges
* Use strong, unique passwords
* Enable MongoDB Atlas monitoring and alerts

<Tip>
  Consider using different MongoDB clusters for development and production to avoid accidental data corruption.
</Tip>

## Environment variable validation

To ensure your environment is configured correctly:

1. Start the development server
2. Check the console for warnings:
   * `WARN: Missing MONGODB_URI environment variable` - Add the variable to `.env.local`
   * `Failed to initialize MongoDB client` - Check your connection string format

## Next steps

After configuration, you can:

* Start developing locally with `pnpm dev`
* Proceed to [Deployment](/development/deployment) when ready to go live
