A minimal, resilient Pastebin-like application built with Next.js and PostgreSQL.
- Create Pastes: Share arbitrary text with syntax highlighting options.
- Constraints: Set Time-to-Live (TTL) and Maximum View Counts.
- Persistence: Data is stored reliably in PostgreSQL.
- Resilience: Handles high traffic and edge cases gracefully.
- Responsive Design: Modern UI that works on desktop and mobile.
- Framework: Next.js (App Router)
- Language: TypeScript
- Database: PostgreSQL (via Prisma ORM)
- Validation: Zod
- Styling: Tailwind CSS
.
├── app/ # Next.js App Router pages and layouts
│ ├── api/ # API routes
│ ├── p/[id]/ # Paste view page
│ └── page.tsx # Main create paste page
├── components/ # Reusable UI components
├── lib/ # Utilities, types, and database clients
├── prisma/ # Database schema and migrations
└── public/ # Static assets- Node.js (v18+)
- PostgreSQL installed and running
-
Clone the repository:
git clone https://github.com/yourusername/agnitha.git cd agnitha -
Install dependencies:
npm install
-
Configure Database:
- Copy
.env.exampleto.env(or create.env):cp .env.example .env
- Set the
DATABASE_URLin.env:DATABASE_URL="postgresql://user:password@localhost:5432/pastebin_lite?schema=public"
- Copy
-
Run Migrations:
npx prisma migrate dev --name init
-
Run the Development Server:
npm run dev
-
Verify:
- Visit
http://localhost:3000to create a paste. - Check
/api/healthzfor system status.
- Visit
For automated testing with deterministic time:
- Set
TEST_MODE=1in your environment. - Send requests with
x-test-now-msheader to simulate time travel.
This project uses PostgreSQL for persistence to ensure data durability and consistency across requests. Redis was considered for TTL but Postgres handles relational data and ACID compliance better for this use case, and TTL can be efficiently indexed.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Distributed under the MIT License. See LICENSE for more information.