Library API is a fullstack library management app built with Next.js, Tailwind CSS, and MongoDB. It includes a public landing page, a protected workspace, internal API routes, bilingual UI, persistent theme preferences, and Swagger-based API documentation.
- Public landing page plus authenticated workspace
- Internal API routes for auth, authors, books, loans, seed data, and OpenAPI
- English and Spanish interface with saved language preference
- Light and dark themes with persistent user preference
- Cookie-based authentication with protected workspace routes
- Swagger UI docs at
/api-docs - Health endpoint at
/api/healthfor Railway readiness checks - Sample data loader for demo sessions
- Next.js 15
- React 19
- Tailwind CSS
- MongoDB
- Mongoose
- Zod
- JOSE
- Swagger UI
- Docker
src/
├── app/
│ ├── (marketing)/ # Public landing page
│ ├── (workspace)/ # Authenticated workspace
│ ├── api/ # Internal API route handlers
│ └── api-docs/ # Swagger UI page
├── components/ # Layout, auth, docs, UI, and feature sections
└── lib/
├── auth/ # Session and request auth helpers
├── client/ # Client-side API utilities
├── constants/ # Shared app constants
├── db/ # Database models, serializers, and connection
├── i18n/ # Dictionaries and preference helpers
├── services/ # Business logic
└── validation/ # Zod schemas
Create a local environment file:
cp .env.example .env.localMONGODB_URI=mongodb://admin:123456@localhost:27017/library-db?authSource=admin
JWT_SECRET=change-this-super-secret-key
NEXT_PUBLIC_APP_NAME=Library APIFor Railway, keep the same variable names in your app service:
MONGODB_URIJWT_SECRETNEXT_PUBLIC_APP_NAME
npm install
npm run devThe app will be available at http://localhost:3000.
docker-compose up --buildServices:
library-appathttp://localhost:3000library-mongodbatmongodb://localhost:27017
This repository is configured for Railway with:
next.config.tsusingoutput: "standalone"- A production
Dockerfilefor Railway builds railway.jsonfor config-as-code/api/healthas the deployment healthcheck
- Push this repository to GitHub.
- In Railway, create a new project and choose
Deploy from GitHub repo. - Add a MongoDB service to the same Railway project.
- In the app service, add these variables:
MONGODB_URIas a reference variable pointing to your MongoDB connection stringJWT_SECRETas a strong secret valueNEXT_PUBLIC_APP_NAME=Library API
- Open the app service
Settings -> Networkingand generate a public domain. - Redeploy the app service after adding variables if Railway does not redeploy automatically.
- Railway automatically injects
PORT, and the container is configured to listen on it. - The deployment will only become active when
/api/healthreturns HTTP200. - If the app is missing
MONGODB_URIorJWT_SECRET, the healthcheck returns503and Railway will keep the deployment from going live. - Railway supports defining settings in code via
railway.json, and those values override dashboard deploy settings for the current deployment.
/public landing page/loginauthentication screen/dashboardworkspace overview/authorsauthor management/bookscatalog management/loanslending management/api/healthdeployment health endpoint/api-docsSwagger UI documentation
npm run dev
npm run lint
npm run build
npm run start- Use
npm, notpnpm, for dependency management in this repository. - Keep OpenAPI docs in sync with backend route changes.
- Keep both locales updated when changing user-facing copy.
- Keep Railway deployment settings in sync with
railway.jsonand/api/health.
Before shipping changes, run:
npm run lint
npm run build