A Node.js API for managing AI character chats, built with Express, Prisma, and Supabase. This application provides user authentication, character management, and chat functionality with support for multiple conversations.
-
🔐 User Authentication
- Email/password signup and login
- JWT-based authentication
- Password reset and email verification
- Role-based access control
-
🤖 Character Management
- Create and manage AI characters with custom prompts
- Public/private character visibility
- Character ownership and permissions
-
💬 Chat Functionality
- Create and manage multiple conversations
- Message history and persistence
- Conversation context management
-
🛡️ Security
- Secure password hashing
- CSRF protection
- Rate limiting
- Input validation
- Backend: Node.js, Express
- Database: PostgreSQL with Prisma ORM
- Authentication: JWT, Supabase Auth
- API Documentation: OpenAPI/Swagger (TBD)
- Containerization: Docker (TBD)
- Node.js 16+
- npm or yarn
- PostgreSQL database
- Supabase account (for authentication)
-
Clone the repository:
git clone <repository-url> cd ch
-
Install dependencies:
npm install # or yarn -
Set up environment variables: Create a
.envfile in the root directory with the following variables:PORT=3000 NODE_ENV=development # Database DATABASE_URL="postgresql://user:password@localhost:5432/character_chat?schema=public" DIRECT_URL="postgresql://user:password@localhost:5432/character_chat?schema=public" # JWT JWT_SECRET=your_jwt_secret JWT_EXPIRES_IN=1d # Supabase SUPABASE_URL=your_supabase_url SUPABASE_ANON_KEY=your_supabase_anon_key # Client URL for CORS CLIENT_URL=http://localhost:3001
-
Run database migrations:
npx prisma migrate dev
-
Start the development server:
npm run dev # or yarn dev
POST /auth/signup- Register a new userPOST /auth/login- User loginPOST /auth/logout- User logoutPOST /auth/refresh-token- Refresh access tokenPOST /auth/reset-password- Request password resetPOST /auth/verify-email- Verify email address
POST /create_bot- Create a new characterGET /characters- List all public characters (or user's private characters)GET /characters/:id- Get character detailsPUT /characters/:id- Update characterDELETE /characters/:id- Delete character
POST /new_chat- Start a new conversation with a characterGET /conversations- List user's conversationsGET /conversations/:id- Get conversation detailsPOST /conversations/:id/messages- Send a message in a conversationGET /conversations/:id/messages- Get conversation messages
-
User
- Authentication and profile information
- Relationships to characters and conversations
-
Character
- Name and prompt for the AI character
- Privacy settings (public/private)
- Owner relationship
-
Conversation
- Links a user to a character
- Contains message history
-
Message
- Content and metadata for each message in a conversation
- Role-based (user/assistant)
src/
├── api/ # API routes and controllers
│ ├── chat.js # Chat logic
│ └── chatRoutes.js # Chat-related routes
├── auth/ # Authentication logic
│ ├── authController.js
│ ├── authMiddleware.js
│ ├── config.js
│ ├── errorHandler.js
│ ├── routes.js
│ └── validation.js
└── server.js # Application entry point
See .env.example for all required environment variables.
# Run ESLint
npm run lint
# Fix linting issues
npm run lint:fix
# Format code
npm run format# Run tests
npm test
# Run tests with coverage
npm run test:coverageA Dockerfile and docker-compose.yml will be provided in a future update for containerized deployment.
- Set
NODE_ENV=productionin your environment variables - Ensure all required environment variables are set
- Use a process manager like PM2:
npm install -g pm2 pm2 start src/server.js --name "character-chat-api"
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Built with ❤️ using Node.js and Express
- Authentication powered by Supabase
- Database management with Prisma ORM