mirror of
https://github.com/johndoe6345789/postgres.git
synced 2026-04-24 13:55:00 +00:00
Document configuration-driven architecture in README and ROADMAP
Co-authored-by: johndoe6345789 <224850594+johndoe6345789@users.noreply.github.com>
This commit is contained in:
159
README.md
159
README.md
@@ -2,14 +2,41 @@
|
||||
|
||||
A production-ready Next.js 16 application with database management capabilities, built with TypeScript, Tailwind CSS, and DrizzleORM for connecting to multiple database backends.
|
||||
|
||||
## 🏗️ Configuration-Driven Architecture
|
||||
|
||||
This project features a **unique JSON-driven architecture** that makes adding features incredibly simple:
|
||||
|
||||
- **Define features in JSON** (`src/config/features.json`) - no need to write boilerplate code
|
||||
- **Automatic UI generation** - navigation and forms are generated by looping over configuration
|
||||
- **Reusable components** - shared `DataGrid`, `FormDialog`, and `ConfirmDialog` components
|
||||
- **Feature flags** - enable/disable features with a single boolean in the config
|
||||
- **Type-safe** - TypeScript ensures configuration integrity
|
||||
|
||||
**Example**: To add a new feature, simply add an entry to `features.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"id": "my-feature",
|
||||
"name": "My Feature",
|
||||
"enabled": true,
|
||||
"endpoints": [...],
|
||||
"ui": { "showInNav": true, "icon": "Star", "actions": ["create", "read"] }
|
||||
}
|
||||
```
|
||||
|
||||
The system automatically generates the navigation item, API routes, and UI components!
|
||||
|
||||
## Overview
|
||||
|
||||
This project is a full-stack web application featuring:
|
||||
- **Next.js 16** with App Router for server-side rendering and static site generation
|
||||
- **Configuration-driven architecture** - Features defined in JSON, UI generated automatically
|
||||
- **Database CRUD operations** - Create, read, update, and delete records through a clean UI
|
||||
- **DrizzleORM** for type-safe database operations with support for PostgreSQL, MySQL, and SQLite
|
||||
- **PostgreSQL 15** included as default database in Docker container
|
||||
- **Multi-database support** - Connect to external PostgreSQL, MySQL, or SQLite servers
|
||||
- **Authentication** using Clerk with support for multiple auth providers
|
||||
- **Admin panel** with authentication, table management, and SQL query interface
|
||||
- **Authentication** using JWT with secure session management
|
||||
- **TypeScript** for type safety across the entire stack
|
||||
- **Tailwind CSS 4** for modern, responsive styling
|
||||
- **Docker** support for easy deployment
|
||||
@@ -18,12 +45,17 @@ This project is a full-stack web application featuring:
|
||||
## Features
|
||||
|
||||
- ⚡ **Next.js 16** with App Router support
|
||||
- 🏗️ **Configuration-Driven Architecture** - Define features in JSON, auto-generate UI
|
||||
- 🔥 **TypeScript** for type safety
|
||||
- 💎 **Tailwind CSS 4** for styling
|
||||
- 🔒 **Clerk Authentication** with social login support
|
||||
- 🗄️ **Database CRUD Operations** - Full Create, Read, Update, Delete functionality
|
||||
- 🛠️ **Admin Panel** - Manage tables, columns, and data through a beautiful UI
|
||||
- 📊 **SQL Query Interface** - Execute custom queries with safety validation
|
||||
- 🔒 **JWT Authentication** with secure session management
|
||||
- 📦 **DrizzleORM** - Support for PostgreSQL, MySQL, and SQLite
|
||||
- 🔌 **Multi-Database Support** - Connect to custom database servers
|
||||
- 🐳 **Docker** with included PostgreSQL 15 (default option)
|
||||
- ♻️ **Reusable Components** - DataGrid, FormDialog, ConfirmDialog for consistent UX
|
||||
- 🧪 **Testing Suite** - Vitest for unit tests, Playwright for E2E
|
||||
- 🎨 **Storybook** for UI component development
|
||||
- 📏 **ESLint & Prettier** for code quality
|
||||
@@ -57,14 +89,17 @@ Create a `.env.local` file:
|
||||
# Database
|
||||
DATABASE_URL=postgresql://docker:docker@localhost:5432/postgres
|
||||
|
||||
# Clerk Authentication
|
||||
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=your_key
|
||||
CLERK_SECRET_KEY=your_secret
|
||||
# JWT Secret (required for admin authentication)
|
||||
JWT_SECRET=your_secure_random_secret_here
|
||||
|
||||
# Optional: Admin user creation
|
||||
CREATE_ADMIN_USER=true
|
||||
ADMIN_USERNAME=admin
|
||||
ADMIN_PASSWORD=admin123
|
||||
|
||||
# Optional: Clerk Authentication
|
||||
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=your_key
|
||||
CLERK_SECRET_KEY=your_secret
|
||||
```
|
||||
|
||||
4. Run the development server:
|
||||
@@ -74,6 +109,21 @@ npm run dev
|
||||
|
||||
5. Open http://localhost:3000 in your browser.
|
||||
|
||||
### Admin Panel
|
||||
|
||||
Access the admin panel at http://localhost:3000/admin/login
|
||||
|
||||
**Default credentials** (if using db:seed-admin):
|
||||
- Username: `admin`
|
||||
- Password: `admin123` (change this in production!)
|
||||
|
||||
**Features available in the admin panel**:
|
||||
- 📊 **Table Browser**: View all database tables and their data
|
||||
- ✏️ **CRUD Operations**: Create, edit, and delete records
|
||||
- 🔍 **SQL Query Interface**: Execute custom SELECT queries
|
||||
- 🛠️ **Schema Inspector**: View table structures, columns, and relationships
|
||||
- 🔐 **Secure Access**: JWT-based authentication with session management
|
||||
|
||||
### Docker Deployment
|
||||
|
||||
The Docker container includes PostgreSQL 15 as the default database option. You can also connect to external database servers.
|
||||
@@ -103,9 +153,17 @@ The Docker container includes both PostgreSQL and the Next.js application, but P
|
||||
```
|
||||
├── src/
|
||||
│ ├── app/ # Next.js App Router pages
|
||||
│ │ ├── admin/ # Admin panel pages (dashboard, login)
|
||||
│ │ └── api/admin/ # Admin API routes (CRUD, tables, queries)
|
||||
│ ├── components/ # React components
|
||||
│ │ └── admin/ # Reusable admin components (DataGrid, FormDialog, etc.)
|
||||
│ ├── config/ # Configuration files
|
||||
│ │ └── features.json # Feature definitions (JSON-driven architecture)
|
||||
│ ├── models/ # Database models (DrizzleORM schemas)
|
||||
│ ├── utils/ # Utility functions
|
||||
│ │ ├── featureConfig.ts # Feature configuration loader
|
||||
│ │ ├── db.ts # Database connection
|
||||
│ │ └── session.ts # JWT session management
|
||||
│ ├── libs/ # Third-party library configurations
|
||||
│ └── locales/ # i18n translations
|
||||
├── tests/
|
||||
@@ -117,6 +175,69 @@ The Docker container includes both PostgreSQL and the Next.js application, but P
|
||||
└── docker-compose.yml # Docker Compose setup
|
||||
```
|
||||
|
||||
## Configuration-Driven Features
|
||||
|
||||
### Adding a New Feature
|
||||
|
||||
To add a new feature to the admin panel:
|
||||
|
||||
1. **Define the feature in `src/config/features.json`**:
|
||||
```json
|
||||
{
|
||||
"id": "my-new-feature",
|
||||
"name": "My New Feature",
|
||||
"description": "Description of what it does",
|
||||
"enabled": true,
|
||||
"priority": "high",
|
||||
"endpoints": [
|
||||
{
|
||||
"path": "/api/admin/my-feature",
|
||||
"methods": ["GET", "POST"],
|
||||
"description": "API endpoint description"
|
||||
}
|
||||
],
|
||||
"ui": {
|
||||
"showInNav": true,
|
||||
"icon": "Settings",
|
||||
"actions": ["create", "read", "update", "delete"]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
2. **Add navigation item to `navItems` array** (if needed):
|
||||
```json
|
||||
{
|
||||
"id": "my-feature",
|
||||
"label": "My Feature",
|
||||
"icon": "Settings",
|
||||
"featureId": "my-new-feature"
|
||||
}
|
||||
```
|
||||
|
||||
3. **Create API route** at `src/app/api/admin/my-feature/route.ts`
|
||||
|
||||
4. **The UI is automatically generated** from your configuration!
|
||||
|
||||
### Reusable Components
|
||||
|
||||
Use these components for consistent UX:
|
||||
|
||||
- **`<DataGrid>`** - Display table data with edit/delete actions
|
||||
- **`<FormDialog>`** - Create/edit forms with automatic field generation
|
||||
- **`<ConfirmDialog>`** - Confirmation dialogs for destructive actions
|
||||
|
||||
Example:
|
||||
```tsx
|
||||
import DataGrid from '@/components/admin/DataGrid';
|
||||
|
||||
<DataGrid
|
||||
columns={[{ name: 'id' }, { name: 'name' }]}
|
||||
rows={data}
|
||||
onEdit={(row) => handleEdit(row)}
|
||||
onDelete={(row) => handleDelete(row)}
|
||||
/>
|
||||
```
|
||||
|
||||
## Available Scripts
|
||||
|
||||
### Development
|
||||
@@ -181,7 +302,33 @@ DATABASE_URL=file:./local.db
|
||||
|
||||
## Authentication
|
||||
|
||||
This project uses [Clerk](https://clerk.com) for authentication. To set up:
|
||||
This project includes a **JWT-based admin authentication system** with secure session management:
|
||||
|
||||
- **Admin Login**: Username/password authentication at `/admin/login`
|
||||
- **Session Management**: JWT tokens stored in HTTP-only cookies
|
||||
- **Protected Routes**: Admin API endpoints require valid session
|
||||
- **Secure**: bcrypt password hashing, 24-hour session expiration
|
||||
|
||||
### Admin User Setup
|
||||
|
||||
Create an admin user by running:
|
||||
|
||||
```bash
|
||||
npm run db:seed-admin
|
||||
```
|
||||
|
||||
Or set environment variables for automatic creation on startup:
|
||||
|
||||
```env
|
||||
CREATE_ADMIN_USER=true
|
||||
ADMIN_USERNAME=admin
|
||||
ADMIN_PASSWORD=your_secure_password
|
||||
JWT_SECRET=your_jwt_secret_here
|
||||
```
|
||||
|
||||
### Clerk Integration (Optional)
|
||||
|
||||
The project also supports [Clerk](https://clerk.com) for additional authentication options:
|
||||
|
||||
1. Create a Clerk account and application
|
||||
2. Copy your API keys to `.env.local`:
|
||||
|
||||
Reference in New Issue
Block a user