A scalable REST API built with Fastify, TypeScript, MongoDB, and clean architecture for React Native applications with Google authentication.
- Google Authentication - Secure authentication using Google ID tokens
- Group Management - Role-based group system (owner, admin, participant)
- Real-time Notifications - WebSocket support for live updates
- Auto-generated Documentation - OpenAPI/Swagger documentation from Zod schemas
- Clean Architecture - Domain-driven design with clear separation of concerns
- Type Safety - Full TypeScript coverage with Zod validation
- Scalable - MongoDB with Redis caching and horizontal scaling support
- Framework: Fastify with TypeScript
- Database: MongoDB with Mongoose ODM
- Caching: Redis
- Authentication: JWT with Clerk
- Validation: Zod schemas
- Documentation: OpenAPI/Swagger
- Real-time: WebSockets
- External Services: SendGrid (email), Twilio (SMS), Google Cloud Storage
- Node.js 18+
- MongoDB
- Redis
- Google Cloud Console project (for OAuth)
-
Clone and install dependencies
git clone <repository-url> cd plotter-api npm install
-
Set up environment variables
cp env.example .env # Edit .env with your configuration -
Required Environment Variables
JWT_SECRET=your-super-secret-jwt-key-change-this-in-production GOOGLE_CLIENT_ID=your-google-client-id.apps.googleusercontent.com MONGODB_URI=mongodb://localhost:27017/plotter-api REDIS_URL=redis://localhost:6379
-
Start development server
npm run dev
-
View API documentation Open http://localhost:3000/documentation
POST /auth/google- Authenticate with Google ID tokenGET /auth/me- Get current user information
GET /groups- List user's groupsPOST /groups- Create a new groupGET /groups/:id- Get group detailsPUT /groups/:id- Update group (admin+)DELETE /groups/:id- Delete group (owner only)GET /groups/:id/members- List group membersPOST /groups/:id/members- Add member (admin+)PUT /groups/:id/members/:userId- Update member role (admin+)DELETE /groups/:id/members/:userId- Remove member (admin+)
GET /users/me- Get current user profilePUT /users/me- Update current user profile
POST /files/upload- Upload file to Google Cloud StorageGET /files/:id- Get file information
GET /ws- WebSocket connection for real-time updates
src/
├── app.ts # Main Fastify app setup
├── server.ts # Server entry point
├── plugins/ # Auto-loaded plugins
│ ├── auth.ts # Authentication & authorization
│ ├── cors.ts # CORS configuration
│ ├── database.ts # MongoDB & Redis connections
│ ├── swagger.ts # OpenAPI documentation
│ └── websocket.ts # WebSocket setup
├── routes/ # Auto-loaded routes
│ ├── auth/ # Authentication endpoints
│ ├── groups/ # Group management
│ ├── users/ # User management
│ └── files/ # File operations
├── domain/ # Domain entities
├── application/ # Business logic
├── infrastructure/ # External services
├── presentation/ # Schemas & controllers
└── config/ # Configuration
- Subsequent Requests:
- Include JWT in Authorization header:
Bearer <token> - Backend validates JWT and extracts user/group/role info
- Include JWT in Authorization header:
# Development with hot reload
npm run dev
# Build for production
npm run build
# Start production server
npm start
# Run tests
npm test
# Lint code
npm run lintThe API is designed to be deployed on Railway or similar platforms:
- Connect your repository to Railway
- Set environment variables
- Deploy automatically
- Health check:
GET /health - Logs: Structured logging with Pino
- Error tracking: Built-in error handling
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request