implement backend skeleton with MongoDB and Claude AI integration
- Add controllers (Auth, Chat, Event) with placeholder implementations - Add services (Auth, Chat, Event) with business logic interfaces - Add repositories with MongoDB/Mongoose models (User, Event, Chat) - Add middleware for JWT authentication - Add Claude AI adapter implementing AIProvider interface - Add utility modules for JWT and password handling - Add shared types and DTOs for User, CalendarEvent, ChatMessage - Configure routes with proper endpoint structure - Update app.ts with dependency injection setup - Add required dependencies: mongoose, bcrypt, jsonwebtoken, @anthropic-ai/sdk
This commit is contained in:
@@ -1,12 +1,64 @@
|
||||
import express, { Request, Response } from 'express';
|
||||
import express from 'express';
|
||||
import mongoose from 'mongoose';
|
||||
|
||||
import { createRoutes } from './routes';
|
||||
import { AuthController, ChatController, EventController } from './controllers';
|
||||
import { AuthService, ChatService, EventService } from './services';
|
||||
import { MongoUserRepository, MongoEventRepository, MongoChatRepository } from './repositories';
|
||||
import { ClaudeAdapter } from './ai';
|
||||
|
||||
const app = express();
|
||||
const port = 3000;
|
||||
const port = process.env.PORT || 3000;
|
||||
const mongoUri = process.env.MONGODB_URI || 'mongodb://localhost:27017/caldav';
|
||||
|
||||
app.get('/', (req: Request, res: Response) => {
|
||||
res.send('Hello World!');
|
||||
// Middleware
|
||||
app.use(express.json());
|
||||
|
||||
// Initialize repositories
|
||||
const userRepo = new MongoUserRepository();
|
||||
const eventRepo = new MongoEventRepository();
|
||||
const chatRepo = new MongoChatRepository();
|
||||
|
||||
// Initialize AI provider
|
||||
const aiProvider = new ClaudeAdapter();
|
||||
|
||||
// Initialize services
|
||||
const authService = new AuthService(userRepo);
|
||||
const chatService = new ChatService(chatRepo, eventRepo, aiProvider);
|
||||
const eventService = new EventService(eventRepo);
|
||||
|
||||
// Initialize controllers
|
||||
const authController = new AuthController(authService);
|
||||
const chatController = new ChatController(chatService);
|
||||
const eventController = new EventController(eventService);
|
||||
|
||||
// Setup routes
|
||||
app.use('/api', createRoutes({
|
||||
authController,
|
||||
chatController,
|
||||
eventController,
|
||||
}));
|
||||
|
||||
// Health check
|
||||
app.get('/health', (_, res) => {
|
||||
res.json({ status: 'ok' });
|
||||
});
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`Example app listening on port ${port}`);
|
||||
});
|
||||
// Start server
|
||||
async function start() {
|
||||
try {
|
||||
await mongoose.connect(mongoUri);
|
||||
console.log('Connected to MongoDB');
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`Server running on port ${port}`);
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Failed to start server:', error);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
start();
|
||||
|
||||
export default app;
|
||||
|
||||
Reference in New Issue
Block a user