A modern, serverless guestbook application built with Next.js and FaunaDB. This project demonstrates how to build a full-stack application with GraphQL, serverless functions, and static site generation.
- π Create Guestbook Entries - Visitors can sign the guestbook with their name and message
- π Real-time Updates - Uses SWR for optimistic UI updates and automatic revalidation
- π¨ Dark Mode Support - Beautiful UI with Tailwind CSS and dark mode
- β‘ Serverless Architecture - Powered by Next.js API routes and FaunaDB
- π Secure - Role-based access control with FaunaDB
- π± Responsive Design - Works seamlessly on all devices
- π Static Site Generation - Pre-renders pages at build time for optimal performance
- Framework: Next.js (latest)
- Database: FaunaDB with GraphQL
- Styling: Tailwind CSS v3
- State Management: SWR for data fetching
- Date Formatting: date-fns
- Language: JavaScript (React)
Before you begin, ensure you have the following installed:
- Node.js (v14 or higher)
- Yarn or npm
- A FaunaDB account
git clone <repository-url>
cd connexinsyarn install
# or
npm install- Create a new database in your FaunaDB dashboard
- Generate an admin key for your database:
- Go to Security β Keys
- Create a new key with the "Admin" role
- Save the secret key
Run the setup script to configure your database and create the necessary resources:
yarn setup
# or
npm run setupThe script will:
- Prompt you for your FaunaDB admin key (or use
FAUNA_ADMIN_KEYenvironment variable) - Import the GraphQL schema
- Create the necessary indexes and functions
- Set up role-based access control
- Generate a
.env.localfile with your client secret
Alternatively, you can manually create a .env.local file:
FAUNA_CLIENT_SECRET=your_fauna_client_secret_hereyarn dev
# or
npm run devOpen http://localhost:3000 in your browser to see the application.
connexins/
βββ components/ # React components
β βββ ErrorMessage.js # Error display component
β βββ LoadingSpinner.js # Loading indicator
β βββ SuccessMessage.js # Success notification
βββ lib/ # Utility libraries
β βββ constants.js # Configuration constants
β βββ fauna.js # FaunaDB GraphQL client and queries
βββ pages/ # Next.js pages
β βββ index.js # Main guestbook page
β βββ api/ # API routes
β βββ entries/ # Guestbook entries endpoints
β βββ index.js # GET and POST handlers
βββ public/ # Static assets
β βββ static/ # Static files (favicon, etc.)
βββ scripts/ # Setup and utility scripts
β βββ setup.js # Database setup script
βββ schema.gql # FaunaDB GraphQL schema
βββ tailwind.config.js # Tailwind CSS configuration
βββ postcss.config.js # PostCSS configuration
βββ package.json # Project dependencies
The application uses a simple GraphQL schema defined in schema.gql:
type GuestbookEntry {
name: String!
message: String!
createdAt: Time!
}
type Query {
entries: [GuestbookEntry!]
@resolver(name: "listLatestEntries", paginated: true)
}The setup script creates:
- Collection:
GuestbookEntry- Stores all guestbook entries - Index:
latestEntries- Indexes entries by creation date (descending) - Function:
listLatestEntries- Custom resolver for paginated queries - Role:
GuestbookRole- Defines read/write permissions - Key: Client secret with limited permissions
Retrieves all guestbook entries, sorted by creation date (newest first).
Response:
[
{
"_id": "123456789",
"_ts": 1234567890,
"name": "John Doe",
"message": "Great guestbook!",
"createdAt": "2025-10-29T12:00:00Z"
}
]Creates a new guestbook entry.
Request Body:
{
"name": "John Doe",
"message": "Hello, world!"
}Response:
{
"_id": "123456789",
"_ts": 1234567890,
"name": "John Doe",
"message": "Hello, world!",
"createdAt": "2025-10-29T12:00:00Z"
}yarn build
# or
npm run buildThis command will:
- Run the setup script (if not already configured)
- Build the Next.js application
- Generate static pages
yarn start
# or
npm startThis project is optimized for deployment on Vercel:
- Push your code to GitHub
- Import your repository on Vercel
- Add the
FAUNA_ADMIN_KEYenvironment variable in your Vercel project settings - Deploy!
The setup script will automatically run during the build process on Vercel.
- Optimistic Updates: The application uses SWR's
mutatefunction to immediately update the UI after submitting an entry - Error Handling: Comprehensive error states with user-friendly messages
- Loading States: Visual feedback during data fetching and form submission
- Static Generation: Uses
getStaticPropsto pre-render the page with initial data - Form Validation: Required fields with HTML5 validation
- Styling: Modify
tailwind.config.jsto customize the theme - Page Limit: Change the
sizeparameter inlib/fauna.jsto adjust the number of entries displayed - Date Format: Update the format string in
pages/index.jsto change date display
- Ensure your FaunaDB admin key is correct
- Check that you're using the right key for the correct database
- Make sure you have the necessary permissions in FaunaDB
- Verify that the schema file (
schema.gql) exists and is valid - Try creating a fresh database and running the setup again
- Check that your
.env.localfile exists and contains the correctFAUNA_CLIENT_SECRET - Verify that the database resources were created successfully
- Review the FaunaDB dashboard for any error logs
Contributions are welcome! Please feel free to submit a Pull Request.