-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from timeowilliams/setup-backend
Setup backend
- Loading branch information
Showing
20 changed files
with
1,625 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: Integration Tests | ||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
test: | ||
name: Run Integration Tests | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 'lts/*' | ||
|
||
- name: Install dependencies | ||
run: npm install | ||
working-directory: ./backend | ||
|
||
- name: Run Integration Tests | ||
env: | ||
MONGODB_URI: ${{ secrets.MONGODB_URI }} | ||
JWT_SECRET: ${{ secrets.JWT_SECRET }} | ||
run: npm run test:integration | ||
working-directory: ./backend |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: Package Size Report | ||
|
||
on: pull_request | ||
|
||
permissions: | ||
pull-requests: write | ||
contents: read | ||
|
||
jobs: | ||
pkg-size-report: | ||
name: Package Size Report | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 20 | ||
|
||
- name: Package size report | ||
uses: pkg-size/action@v1.1.1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Node modules | ||
node_modules/ | ||
|
||
# Build outputs | ||
dist/ | ||
out/ | ||
|
||
# Environment variables | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
## Getting Started | ||
|
||
### Prerequisites | ||
|
||
- Node.js LTS >=v20.12.2 | ||
- npm v10.5.0 or pnpm | ||
- MongoDB instance | ||
|
||
### Installation | ||
|
||
#### Backend | ||
|
||
1. Navigate to the `backend` directory: | ||
|
||
```bash | ||
cd backend | ||
``` | ||
|
||
2. Install dependencies: | ||
|
||
```bash | ||
pnpm install | ||
``` | ||
|
||
3. Create a `.env` file with your MongoDB URI: | ||
|
||
```env | ||
MONGO_URI=your_mongodb_uri | ||
JWT_SECRET=your_jwt_secret | ||
``` | ||
|
||
4. Start the backend server: | ||
```bash | ||
pnpm start | ||
``` | ||
|
||
#### Frontend | ||
|
||
1. Navigate to the `frontend` directory: | ||
|
||
```bash | ||
cd frontend | ||
``` | ||
|
||
2. Install dependencies: | ||
|
||
```bash | ||
pnpm install | ||
``` | ||
|
||
3. Start the Electron app: | ||
```bash | ||
pnpm start | ||
``` | ||
|
||
## Goals | ||
|
||
- [x] Allow all users to download on any machine through an Electron JS app | ||
- [x] Migrate to TypeScript and implement SolidJS | ||
- [x] Set up CI/CD pipeline and automatic releases | ||
- [x] Implement changelog using conventional commits | ||
- [ ] Allow users to enter session goals and customize productive/unproductive sites | ||
- [ ] Migrate from electron-storage to SQLite for improved data handling | ||
- [ ] Add integration and automated tests | ||
- [ ] Implement user authentication and cloud-based data persistence using MongoDB and JWT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{ | ||
"name": "deepfocus-backend", | ||
"version": "1.0.0", | ||
"type": "module", | ||
"main": "src/server.ts", | ||
"scripts": { | ||
"start": "tsx src/server.ts", | ||
"dev": "tsx watch .", | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"format": "prettier --write \"**/*.+(js|ts|jsx|tsx|json|css|md|yml|yaml|html)\"", | ||
"format:check": "prettier --check \"**/*.+(js|ts|jsx|tsx|json|css|md|yml|yaml|html)\"", | ||
"build": "copyfiles -u 1 src/**/* dist", | ||
"test:integration": "tsx node_modules/mocha/bin/mocha src/tests/integration/**/*.test.ts --exit" | ||
}, | ||
"dependencies": { | ||
"bcrypt": "^5.1.1", | ||
"bcryptjs": "^2.4.3", | ||
"cors": "^2.8.5", | ||
"dotenv": "^16.4.5", | ||
"express": "^4.17.1", | ||
"format": "^0.2.2", | ||
"jsonwebtoken": "^8.5.1", | ||
"mongoose": "^8.5.4", | ||
"tsx": "^4.18.0" | ||
}, | ||
"devDependencies": { | ||
"@types/bcrypt": "^5.0.2", | ||
"@types/chai": "^4.3.17", | ||
"@types/cors": "^2.8.17", | ||
"@types/express": "^4.17.21", | ||
"@types/jsonwebtoken": "^9.0.6", | ||
"@types/mocha": "^10.0.7", | ||
"@types/supertest": "^6.0.2", | ||
"chai": "^5.1.1", | ||
"crypto": "^1.0.1", | ||
"mocha": "^10.7.3", | ||
"prettier": "^3.3.3", | ||
"supertest": "^7.0.0", | ||
"ts-node": "^9.1.1", | ||
"typescript": "^4.2.4" | ||
}, | ||
"engines": { | ||
"node": ">=20.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import mongoose from 'mongoose' | ||
import dotenv from 'dotenv' | ||
|
||
dotenv.config() | ||
const uri = process.env.MONGODB_URI || '' | ||
|
||
if (!uri) { | ||
throw new Error('MONGODB_URI is not defined in the environment variables') | ||
} | ||
|
||
async function connectToDB(): Promise<typeof mongoose> { | ||
try { | ||
// Connect to the MongoDB server using Mongoose | ||
await mongoose.connect(uri) | ||
console.log('Connected successfully to MongoDB server') | ||
return mongoose | ||
} catch (error) { | ||
console.error('Error connecting to the database:', error) | ||
throw error | ||
} | ||
} | ||
async function closeDBConnection(): Promise<void> { | ||
try { | ||
await mongoose.connection.close() | ||
console.log('Disconnected successfully from MongoDB server') | ||
} catch (error) { | ||
console.error('Error closing the database connection:', error) | ||
} | ||
} | ||
|
||
export { connectToDB, closeDBConnection } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import mongoose, { Document, Schema } from 'mongoose' | ||
|
||
// Define the User interface | ||
interface IUser extends Document { | ||
username: string | ||
password: string | ||
firstName: string | ||
lastName: string | ||
country: string | ||
language: string | ||
} | ||
|
||
// Create the User schema | ||
const UserSchema: Schema = new Schema({ | ||
username: { | ||
type: String, | ||
required: true, | ||
unique: true, | ||
match: [/.+@.+\..+/, 'Please fill a valid email address'] // Email validation | ||
}, | ||
password: { type: String, required: true }, | ||
firstName: { type: String, required: true }, | ||
lastName: { type: String, required: true }, | ||
country: { type: String, required: true }, | ||
language: { type: String, required: true } | ||
}) | ||
|
||
// Create the User model | ||
const User = mongoose.model<IUser>('User', UserSchema) | ||
|
||
export default User | ||
export { IUser } |
Oops, something went wrong.