A social networking backend API built with Node.js, TypeScript, Express, Sequelize, PostgreSQL, and Socket.io.
- User authentication with JWT
- User profiles with customizable settings
- Connection requests (friend system)
- Real-time messaging with Socket.io
- Notifications system
- Location tracking
- AWS S3 integration for file uploads
- Email notifications with Nodemailer
- Redis caching (optional)
- Swagger API Documentation
- Comprehensive test coverage with Jest
- ESLint and Prettier for code quality
- CI/CD pipeline with GitHub Actions
- Runtime: Node.js
- Language: TypeScript
- Framework: Express
- Database: PostgreSQL with PostGIS
- ORM: Sequelize
- Real-time: Socket.io
- Validation: Zod
- Authentication: JWT + bcrypt
- Cloud Storage: AWS S3
- Email: Nodemailer
- Cache: Redis (optional)
- Documentation: Swagger/OpenAPI
- Testing: Jest + Supertest
- Code Quality: ESLint + Prettier
- Logging: Morgan + Winston
``` src/ ├── config/ # Configuration files (database, email, S3, Redis, Swagger) ├── interfaces/ # TypeScript interfaces and types ├── models/ # Sequelize models ├── migrations/ # Database migrations ├── controllers/ # Route controllers ├── services/ # Business logic ├── routes/ # API routes ├── schemas/ # Zod validation schemas ├── middlewares/ # Custom middleware ├── utils/ # Utility functions ├── tests/ # Integration tests ├── app.ts # Express app setup └── server.ts # Server entry point ```
-
Clone the repository
-
Install dependencies: ```bash npm install ```
-
Copy
.env.exampleto.envand configure your environment variables -
Run migrations: ```bash npm run migrations:run ```
-
Start the development server: ```bash npm run dev ```
npm run dev- Start development server with hot reloadnpm run build- Build TypeScript for productionnpm start- Start production server
npm run migrations:run- Run all pending migrationsnpm run migrations:delete- Undo all migrationsnpm run migrations:revert- Undo last migrationnpm run seed- Run database seeders
npm run lint- Run ESLint and auto-fix issuesnpm run format- Format code with Prettier
npm test- Run all testsnpm run test:watch- Run tests in watch modenpm run test:coverage- Run tests with coverage report
Interactive API documentation is available at: ``` http://localhost:8000/api/docs ```
The Swagger UI provides:
- Complete API endpoint documentation
- Request/response schemas
- Interactive API testing
- Authentication examples
POST /api/auth/register- Register new userPOST /api/auth/login- Login userPOST /api/auth/resend-verification- Resend verification email
GET /api/users/:id- Get user by IDPATCH /api/users/:id- Update userPATCH /api/users/:id/location- Update user location
GET /api/profiles/:userId- Get user profilePOST /api/profiles- Create profilePATCH /api/profiles/:userId- Update profileDELETE /api/profiles/:userId- Delete profile
POST /api/connections- Send connection requestGET /api/connections- Get all connectionsPATCH /api/connections/:connectionId- Accept/reject connectionDELETE /api/connections/:connectionId- Delete connection
GET /api/messages- Get recent conversationsPOST /api/messages- Send messageGET /api/messages/:userId- Get messages with userPATCH /api/messages/read- Mark messages as readGET /api/messages/unread/count- Get unread message count
GET /api/notifications- Get all notificationsPATCH /api/notifications/read- Mark notifications as readGET /api/notifications/unread/count- Get unread notification countDELETE /api/notifications/:notificationId- Delete notification
update-location- Update user locationsend-message- Send real-time messageconnection-request- Send connection requestconnection-accepted- Accept connectiontyping- User is typingstop-typing- User stopped typing
location-updated- Location was updatednew-message- New message receivednew-connection-request- New connection requestconnection-request-accepted- Connection accepteduser-typing- User is typinguser-stopped-typing- User stopped typing
- users - User authentication and basic info
- profiles - User profiles and preferences
- connections - Friend connections (status stored as VARCHAR)
- messages - Direct messages
- notifications - User notifications (type stored as VARCHAR)
Note: ENUMs are implemented as TypeScript enums for type safety, while database columns use VARCHAR to avoid database-level enum constraints.
The project includes comprehensive integration tests covering:
- Authentication (register, login)
- Profile management
- Connection requests
- Message handling
Run tests with: ```bash npm test ```
Tests use a separate test database and clean up after each test run.
GitHub Actions workflow automatically:
- Runs ESLint for code quality
- Checks code formatting with Prettier
- Compiles TypeScript
- Runs database migrations
- Executes all tests
- Builds Docker image (on main branch)
- Uploads coverage reports
Build and run with Docker: ```bash docker build -t radar-backend . docker run -p 3000:3000 --env-file .env radar-backend ```
See .env.example for all required environment variables:
NODE_ENV- Environment (development/test/production)PORT- Server portDATABASE_URL- PostgreSQL connection stringJWT_SECRET- Secret key for JWT tokensENCRYPTION_KEY- Secret key for message encryption
DB_USER- Database usernameDB_PASSWORD- Database passwordDB_NAME- Database nameDB_HOST- Database hostDB_PORT- Database port
AWS_REGION- AWS regionAWS_ACCESS_KEY_ID- AWS access keyAWS_SECRET_ACCESS_KEY- AWS secret keyAWS_S3_BUCKET- S3 bucket name
EMAIL_HOST- SMTP hostEMAIL_PORT- SMTP portEMAIL_USER- Email usernameEMAIL_PASS- Email passwordEMAIL_FROM- From email address
REDIS_URL- Redis connection URL
The project follows strict code quality standards:
- TypeScript: Full type safety with interfaces and types
- ESLint: Enforces coding standards and best practices
- Prettier: Consistent code formatting
- Modular Architecture: Separation of concerns (controllers, services, routes)
- Error Handling: Centralized error handling with Boom
- Validation: Input validation with Zod schemas
All environment variables are accessed through src/config/config.ts for consistency and maintainability.
TypeScript interfaces are organized in src/interfaces/ for better code organization and reusability.
ENUMs are defined in TypeScript for type safety while using VARCHAR in the database to avoid migration complexity.
Integration tests focus on API endpoints with real database interactions to ensure end-to-end functionality.
ISC