# Treasure Seeds Strapi CMS

Self-hosted Strapi 5 service for the Treasure Seeds Next.js frontend.

## What is in scope

- MySQL-backed Strapi app
- Public read-only content APIs for published site content
- Collection types for:
  - `blog-posts`
  - `programs`
  - `team-members`
  - `gallery-photos`
  - `faqs`
  - `careers`
- One-time Sanity import script at `scripts/migrate-from-sanity.ts`

The old Sanity presentation fields are intentionally removed from the CMS model:

- `tagColor`
- `pillColor`
- `tagStyle`
- `color`

The frontend now owns those visual mappings.

## Local setup

1. Copy `.env.example` to `.env`.
2. Start the bundled local MySQL container:

```bash
npm run db:up
```

3. Install dependencies:

```bash
npm install
```

4. Start Strapi:

```bash
npm run develop
```

The included `docker-compose.yml` starts MySQL 8 locally and uses the same `DATABASE_*` values from `.env`, so Strapi can connect to `127.0.0.1:${DATABASE_PORT}` without pointing at cPanel or another external host. Database files are persisted in the `mysql_data` Docker volume.

Useful local DB commands:

```bash
npm run db:logs
npm run db:down
npm run db:reset
```

## Required admin setup

After first boot, create an admin user and then configure the Public role:

1. Open `Settings -> Users & Permissions Plugin -> Roles -> Public`.
2. Allow only `find` and `findOne` for:
   - Blog Post
   - Program
   - Team Member
   - Gallery Photo
   - FAQ
   - Career
3. Leave write operations disabled.
4. Create an API token with full access for migration and store it in `STRAPI_API_TOKEN`.

## Frontend integration

Set the frontend env in the Next.js app root:

```bash
NEXT_PUBLIC_STRAPI_URL=http://localhost:1337
```

If Strapi is deployed behind a public URL, also update:

- `PUBLIC_URL`
- `FRONTEND_URL`
- `FRONTEND_PREVIEW_URL`

## Sanity migration

The migration script reads from the existing Sanity project and upserts into Strapi by stable keys such as `slug`, `question`, `name`, and `order`.

Required env values:

- `STRAPI_URL`
- `STRAPI_API_TOKEN`
- `SANITY_PROJECT_ID`
- `SANITY_DATASET`
- `SANITY_API_TOKEN`

Run it with:

```bash
npm run migrate:sanity
```

## Notes

- Blog posts use Draft & Publish.
- Programs and careers use Strapi blocks for long-form body content.
- Program `pillars` are stored as JSON arrays of strings to keep the frontend contract simple.
