Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .env.example

This file was deleted.

197 changes: 8 additions & 189 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,206 +41,28 @@ Welcome to **GitHub Tracker**, a web app designed to help you monitor and analyz
---

## 🚀 Setup Guide

### 📋 Prerequisites

Before setting up the project locally, ensure the following tools are installed on your system:

- Node.js (v18 or later recommended)
- npm
- Docker
- Docker Compose
- MongoDB (required for backend services and testing)

---

## 📥 Clone the Repository

```bash
git clone https://github.com/GitMetricsLab/github_tracker.git
cd github-tracker
```

---

# 💻 Local Development Setup

This project contains both frontend and backend services.

## ▶️ Frontend Setup

Install frontend dependencies:

```bash
npm install
```

Start the frontend development server:

```bash
npm run dev
```

The frontend will run on:

```txt
http://localhost:5173
```

---

## ⚙️ Backend Setup

Move into the backend directory:

1. Clone the repository to your local machine:
```bash
cd backend
$ git clone https://github.com/yourusername/github-tracker.git
```

Install backend dependencies:

2. Navigate to the project directory:
```bash
npm install
$ cd github-tracker
```

3. Configure environment variables

Copy the example files and fill in your values:
```bash
# Frontend (.env in the repo root)
cp .env.example .env

# Backend (.env inside backend/)
cp backend/.env.example backend/.env
```

Key variables to set:

| Variable | Where | Description |
|---|---|---|
| `VITE_BACKEND_URL` | root `.env` | URL of the backend (default: `http://localhost:5000`) |
| `MONGO_URI` | `backend/.env` | MongoDB connection string |
| `SESSION_SECRET` | `backend/.env` | Long random string used to sign session cookies |
| `FRONTEND_ORIGIN` | `backend/.env` | URL of the frontend — restricts CORS. **Required in production.** Defaults to `http://localhost:5173` in development. |

4. Run the frontend
3. Run the frontend
```bash
npm run dev
```

The backend server will run on:

```txt
http://localhost:5000
$ npm i
$ npm run dev
```

5. Run the backend
4. Run the backend
```bash
$ cd backend
$ npm i
$ npm start
```

This command:

- Builds frontend and backend containers
- Starts development services
- Enables live file changes using Docker volumes
- Runs frontend and backend simultaneously

### Development Services

| Service | Port |
|----------|------|
| Frontend | 5173 |
| Backend | 5000 |

---

## 🚀 Production Environment

Run the production Docker setup:

```bash
npm run docker:prod
```

This command:

- Creates optimized production builds
- Runs frontend using Nginx
- Starts backend production services

### Production Services

| Service | Port |
|----------|------|
| Frontend | 3000 |
| Backend | 5000 |

---

# 📂 Docker Configuration Overview

| File | Purpose |
|------|----------|
| `Dockerfile.dev` | Development container setup |
| `Dockerfile.prod` | Production container setup |
| `docker-compose.yml` | Multi-service container orchestration |

---

# 🔄 Local Development Workflow

Recommended contributor workflow:

1. Fork the repository
2. Clone your fork locally
3. Create a new branch
4. Install dependencies
5. Run frontend/backend locally or using Docker
6. Make changes
7. Test your implementation
8. Commit and push changes
9. Open a Pull Request

---

# 🌱 Environment Configuration

The project uses environment variables for configuration.

Frontend environment variables:

```env
VITE_BACKEND_URL=http://localhost:5000
```

Backend environment variables:

```env
PORT=5000
MONGO_URI=your_mongodb_connection
SESSION_SECRET=your_secret
```

Create corresponding `.env` files before running the application.

---

# 🛠️ Useful Commands

| Command | Description |
|----------|-------------|
| `npm run dev` | Start frontend locally |
| `npm run build` | Create production build |
| `npm run docker:dev` | Run Docker development environment |
| `npm run docker:prod` | Run Docker production environment |
| `npm run test` | Run frontend tests |
| `npm run test:backend` | Run backend tests |

---

## 🧪 Backend Unit & Integration Testing with Jasmine

This project uses the Jasmine framework for backend unit and integration tests. The tests cover:
Expand Down Expand Up @@ -318,6 +140,3 @@ spec_files: [
⬆️ Back to Top
</a>
</p>



37 changes: 0 additions & 37 deletions backend/.env.example

This file was deleted.

15 changes: 0 additions & 15 deletions backend/config/validateEnv.js

This file was deleted.

4 changes: 1 addition & 3 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
"zod": "^4.4.3"
},
"devDependencies": {
"jasmine": "^5.0.0",
"nodemon": "^3.1.9",
"supertest": "^7.0.0"
"nodemon": "^3.1.9"
}
}
72 changes: 22 additions & 50 deletions backend/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,62 +6,32 @@ const bodyParser = require('body-parser');
require('dotenv').config();
const cors = require('cors');

const { validateEnv } = require('./config/validateEnv');
const logger = require('./logger');

// Fail fast in production when required env vars are absent.
try {
validateEnv();
} catch (err) {
logger.error(`[FATAL] ${err.message}`);
process.exit(1);
}

// Passport configuration
require('./config/passportConfig');

const app = express();

// In development, fall back to localhost:5173 if FRONTEND_ORIGIN is not set so
// that contributors can run the stack without a full .env file.
const corsOrigin = process.env.FRONTEND_ORIGIN || 'http://localhost:5173';
const logger = require('./logger');

if (!process.env.FRONTEND_ORIGIN) {
logger.warn(
'FRONTEND_ORIGIN is not set; defaulting to http://localhost:5173. ' +
'Set this variable in production.'
);
}
const app = express();

// CORS — explicit allowlist with credentials support.
// A function-based origin is required so that the header is only set (and
// reflected) for allowed origins; a static string would send the header on
// every response regardless of the requesting origin.
// CORS configuration
const allowedOrigins = ['http://localhost:5173', 'https://github-spy.etlify.app'];
app.use(cors({
origin: (requestOrigin, callback) => {
// Allow same-origin requests (no Origin header) and the configured origin.
if (!requestOrigin || requestOrigin === corsOrigin) {
return callback(null, true);
}
callback(null, false);
},
credentials: true,
methods: ['GET', 'POST'],
allowedHeaders: ['Content-Type'],
origin: function (origin, callback) {
if (!origin || allowedOrigins.indexOf(origin) !== -1) {
callback(null, true);
} else{
callback(new Error('Blocked by CORS policy'));
}
},
credentials: true
}));

// Middleware
app.use(bodyParser.json());
app.use(session({
secret: process.env.SESSION_SECRET,
resave: false,
saveUninitialized: false,
cookie: {
httpOnly: true,
// Only transmit the cookie over HTTPS in production.
secure: process.env.NODE_ENV === 'production',
sameSite: 'strict',
},
secret: process.env.SESSION_SECRET,
resave: false,
saveUninitialized: false,
}));
app.use(passport.initialize());
app.use(passport.session());
Expand All @@ -72,10 +42,12 @@ app.use('/api/auth', authRoutes);

// Connect to MongoDB
mongoose.connect(process.env.MONGO_URI, {}).then(() => {
logger.info('Connected to MongoDB');
app.listen(process.env.PORT, () => {
logger.info(`Server running on port ${process.env.PORT}`);
});
logger.info('Connected to MongoDB');

const PORT = process.env.PORT || 5000;
app.listen(PORT, () => {
logger.info(`Server running on port ${PORT}`);
});
}).catch((err) => {
logger.error('MongoDB connection error', err);
logger.error('MongoDB connection error', err);
});
3 changes: 0 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/crl-icon.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=VT323&display=swap" rel="stylesheet" />
<title>Github Tracker</title>
</head>
<body>
Expand Down
Loading
Loading