# Membership associations: asset library using Next.js

## Summary
A asset library blueprint for membership associations built with Next.js on Ample. Domain schema: 
- **course_groups** (chapter_or_program, start_at, end_at): Chapters and programs as groups;
- **memberships** (course_group_id, member_email, tier, role, renewed_at): Members and roles;
- **sessions** (course_group_id, starts_at, title, venue): Meetings and events;
- **materials** (course_group_id, title, object_key, visibility): Member resources;
- **uploads** (id, owner_reference, object_key, content_type, size, uploaded_at): Validated uploads linked to their owner.

Public information includes: about, chapters and benefits, public events, join information. Member directories are personal data;

## Technical Requirements
### Infrastructure Requirements
- **Compute**: Apps run in isolated x86_64 Firecracker microVMs that auto-pause when idle and wake on request.
- **Postgres**: Managed PostgreSQL 16 runs in its own microVM and is auto-provisioned when an app needs a database.
- **S3-compatible object storage**: Buckets are S3-compatible with issued credentials; operational checks are verified by canary.

### Framework and Workload
- **Framework**: Next.js
- **Workload**: Asset library
- **Industry**: Membership associations

## Prerequisites
- A Next.js project (next build then next start -H 0.0.0.0 -p $PORT on the node-22 template).
- A PostgreSQL driver reading DATABASE_URL.
- Bucket credentials from `ample bucket create` passed as encrypted S3_* environment variables.
- Review of which membership associations data classes may be handled.

## Workflow Steps  
1. **Model the membership associations domain**: Create the tables course_groups, memberships, sessions, materials, uploads. Keep sensitive classes out of this schema.  
2. **Model assets linked to their owning group or workspace**.  
3. **Validate uploads** and store them in the private bucket; link each object to its row.  
4. **Authorize downloads by membership**.  
5. **Deploy**: Run the synchronous deploy once and read the result.  
6. **Verify**: Run pattern self-tests and acceptance checks.

## Limitations  
- The technical basis was verified with the pattern fixture; the membership associations schema is an original design.
- Member directories are personal data; only public events are modeled.

## Cost Estimate
- **Monthly Amount**: 10.0 USD  
  - App server: s-1vcpu-1gb, $5.0  
  - Managed PostgreSQL database: s-1vcpu-1gb, $5.0  
- Note: Always-on monthly price; buckets are allocation-priced per quota.

## Examples
### Next.js pattern fixture
- **Description**: Verified browser file uploads basis for this blueprint.
- **Source Ref**: tests/deploy-canaries/next-js-patterns

## Success Checks
1. App responds on its public URL.  
2. Browser-file-uploads self-test from the example.

## Next Actions  
- Browse the catalog index  
- Search published recipes by intent, stack and constraints  
- Prepare a side-effect-free deployment plan  
- Read the existing agent authentication setup  
- Browse Membership Associations  
- Browse Asset library  
- Browse Next.js  
- Browse Deploy web app
