- Fastify server with TypeScript
- MongoDB database integration
- User roles:
Student
,Tutor
,Parent
,Admin
- JWT authentication
- API versioning (
/v1
) - Swagger UI documentation at
/docs
- Dockerized for development and production
backend/
│
├─ src/
│ ├─ config/ # Database & environment configuration
│ │ ├─ db.ts
│ │ └─ env.ts
│ │
│ ├─ controllers/ # Handle requests → call services
│ │ ├─ auth.controller.ts
│ │ └─ user.controller.ts
│ │
│ ├─ services/ # Business logic
│ │ └─ auth.service.ts
│ │
│ ├─ models/ # MongoDB schemas
│ │ └─ User.ts
│ │
│ ├─ routes/ # API endpoints
│ │ ├─ auth.routes.ts
│ │ └─ user.routes.ts
│ │
│ ├─ middlewares/ # Auth, validation, error handling
│ │ └─ auth.ts
│ │
│ ├─ utils/ # Helpers: JWT, hash functions
│ │ ├─ jwt.ts
│ │ └─ hash.ts
│ │
│ ├─ app.ts # Fastify app setup
│ └─ server.ts # Entry point (start server)
│
├─ .env # Environment variables
├─ .env.example # Example environment config
├─ .gitignore
├─ package.json
├─ tsconfig.json
├─ .eslintrc.js
├─ .prettierrc
└─ docker-compose.yml
- Node.js >= 18
- npm
- Docker & Docker Compose (optional)
- MongoDB (if running locally, otherwise use Docker)
- Install dependencies:
npm install
- Create
.env
file (based on.env.example
)
PORT=3000
MONGO_URI=mongodb://localhost:27017/fastifydb
JWT_SECRET=supersecret123
- Start server in development mode:
npm run dev
- Access endpoints:
- Health check:
GET http://localhost:3000/v1/health
- Swagger UI:
http://localhost:3000/docs
- Signup/Login/Forgot Password APIs:
/v1/auth/...
- User profile:
/v1/user/profile
(requires JWT token)
- Build and start services:
docker-compose up --build
- Services included:
- backend: Fastify app on
PORT
from.env
(default 3000) - mongo: MongoDB container, port
27017
- Example connection inside container:
MONGO_URI=mongodb://mongo:27017/fastifydb
- Stop containers:
docker-compose down
Type | Description |
---|---|
feat: |
A new feature (e.g., feat(auth): add login API ) |
fix: |
A bug fix |
docs: |
Documentation only changes |
style: |
Code style changes (formatting, no logic change) |
refactor: |
Code refactoring, no feature or bug fix |
test: |
Adding or fixing tests |
chore: |
Maintenance tasks (build, package updates) |
perf: |
Performance improvements |
ci: |
Changes to CI/CD pipelines |
build: |
Changes to build system or dependencies |
revert: |
Revert previous commit |
Example commits:
feat(auth): add signup and login endpoints
fix(auth): correct password hashing issue
docs: add README and Swagger documentation
refactor(user): simplify profile controller
- Always rebuild Docker image if new dependencies are added:
docker-compose up --build
- JWT token is required for protected routes (
Authorization: Bearer <token>
). - Swagger UI helps test APIs directly:
http://localhost:3000/docs