A robust Node.js API built with TypeScript, following a Modular Monolith architecture and Clean Code principles. This API fetches weather data from external services (StormGlass), processes it, and provides surf forecasts for registered beaches.
- Modular Monolith Architecture: Organized by domain modules (
users,beaches,forecast) for better maintainability and scalability. - User Management: Registration, authentication (JWT), and profile management.
- Beach Management: Create and manage favorite beaches.
- Surf Forecast: Fetch and process wave/wind data to rate surf conditions.
- Security:
- JWT Authentication
- Rate Limiting
- Security Headers (Helmet)
- Password Hashing (Bcrypt)
- Robustness:
- Centralized Error Handling
- Structured Logging (Pino)
- Validation (Mongoose & OpenApiValidator)
- Production Ready:
- Docker & Docker Compose support
- GitHuB Actions CI pipeline
- Runtime: Node.js (v20+)
- Language: TypeScript
- Framework: Express.js
- Database: MongoDB (Mongoose v8)
- Testing: Jest (Unit & Functional), Supertest, MongoDB Memory Server
- Documentation: OpenAPI (Swagger)
- Tooling: pnpm, ESLint, Prettier
src/
modules/ # Domain modules
users/ # Users domain (Auth, Profile)
beaches/ # Beaches domain (CRUD)
forecast/ # Forecast domain (Logic, Rating)
shared/
core/ # Shared base classes/types
infra/ # Infrastructure (Database, HTTP)
util/ # Utilities (Logger, Errors)
clients/ # External API clients
- Node.js v20+
- pnpm
- MongoDB (locally or via Docker)
-
Clone the repository:
git clone <repo-url> cd forecast-api
-
Install dependencies:
pnpm install
-
Configure environment variables: Copy
.env.exampleto.env(if applicable) or rely onconfig/default.json.
Development mode with hot reload:
pnpm start:localThe API will be available at http://localhost:3000.
Documentation (Swagger) available at http://localhost:3000/docs.
- Build and run the containers:
docker-compose up --build
This will start the API and a MongoDB instance.
The project includes a comprehensive test suite.
Run Unit Tests:
pnpm test:unitRun Functional (E2E) Tests: These tests run against an in-memory MongoDB instance for isolation.
pnpm test:functionalTo compile the TypeScript code for production:
pnpm build- Fork the project
- 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