Skip to content

Commit 22f79f8

Browse files
authored
feat: Complete Application Infrastructure and Security Overhaul (#28)
Chores & Configuration • Enhanced development setup: optimized Dockerfile, refined scripts, and improved .gitignore. • Updated docker-compose for better dev/prod separation. • Improved documentation in README and source files. Features & Enhancements • Refactored project structure with modular architecture. • Improved testing infrastructure and integration tests. • Enhanced file upload logic, client-side handling, and API routes. • Implemented robust server shutdown, rate limiting, and cleanup mechanisms. • Improved upload progress tracking with UI enhancements. • Strengthened security in PIN authentication and cookie handling. Refactors & Fixes • Cleaned up test infrastructure, logging, and error handling. • Simplified API route paths and improved middleware. • Fixed incorrect total storage size reporting. • Optimized logging verbosity based on environment. Documentation • Expanded project documentation and comments for clarity.
1 parent 2ec69ba commit 22f79f8

33 files changed

+9776
-2263
lines changed

.cursorrules

+130
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
/**
2+
* Cursor rules for maintaining code quality and consistency
3+
*/
4+
5+
{
6+
"rules": {
7+
"file-header-docs": {
8+
"description": "All source files must have a header comment explaining their purpose",
9+
"pattern": "src/**/*.js",
10+
"check": {
11+
"type": "regex",
12+
"value": "^/\\*\\*\\n \\* [^\\n]+\\n \\* [^\\n]+\\n \\* [^\\n]+\\n \\*/\\n",
13+
"message": "File must start with a header comment block (3 lines) explaining its purpose"
14+
}
15+
}
16+
}
17+
}
18+
19+
# Project Principles
20+
21+
# Code Philosophy
22+
- Keep code simple, smart, and follow best practices
23+
- Don't over-engineer for the sake of engineering
24+
- Use standard conventions and patterns
25+
- Write human-readable code
26+
- Keep it simple so the app just works
27+
- Follow the principle: "Make it work, make it right, make it fast"
28+
- Comments should explain "why" behind the code in more complex functions
29+
- Overcommented code is better than undercommented code
30+
31+
# Commit Conventions
32+
- Use Conventional Commits format:
33+
- feat: new features
34+
- fix: bug fixes
35+
- docs: documentation changes
36+
- style: formatting, missing semi colons, etc.
37+
- refactor: code changes that neither fix bugs nor add features
38+
- test: adding or modifying tests
39+
- chore: updating build tasks, package manager configs, etc.
40+
- Each commit should be atomic and focused
41+
- Write clear, descriptive commit messages
42+
43+
# Project Structure
44+
45+
# Root Directory
46+
- Keep root directory clean with only essential files
47+
- Production configuration files in root:
48+
- docker-compose.yml
49+
- Dockerfile
50+
- .env.example
51+
- package.json
52+
- README.md
53+
54+
# Source Code (/src)
55+
- All application source code in /src directory
56+
- app.js: Application setup and configuration
57+
- server.js: Server entry point
58+
- routes/: Route handlers
59+
- middleware/: Custom middleware
60+
- utils/: Helper functions and utilities
61+
- models/: Data models (if applicable)
62+
- services/: Business logic
63+
64+
# Development
65+
- All development configurations in /dev directory
66+
- Development specific files:
67+
- /dev/docker-compose.dev.yml
68+
- /dev/.env.dev.example
69+
- /dev/README.md (development setup instructions)
70+
71+
# Static Assets and Uploads
72+
- Static assets in /public directory
73+
- Upload directories:
74+
- /uploads (production)
75+
- /local_uploads (local development)
76+
77+
# Testing
78+
- Tests are mandatory for all new features
79+
- Test files location:
80+
- Unit tests: __tests__/unit/
81+
- Integration tests: __tests__/integration/
82+
- E2E tests: __tests__/e2e/
83+
- Test naming convention:
84+
- Unit tests: [feature].test.js
85+
- Integration tests: [feature].integration.test.js
86+
- E2E tests: [feature].e2e.test.js
87+
- Test coverage requirements:
88+
- Minimum 80% coverage for new features
89+
- Must include happy path and error cases
90+
- API endpoints must have integration tests
91+
92+
# Documentation
93+
- Main README.md in root focuses on production deployment
94+
- Development documentation in /dev/README.md
95+
- Code must be self-documenting with clear naming
96+
- Complex logic must include comments explaining "why" not "what"
97+
- JSDoc comments for public functions and APIs
98+
99+
# Docker Configuration
100+
- Use environment-specific .dockerignore files:
101+
- .dockerignore: Production defaults (most restrictive)
102+
- dev/.dockerignore: Development-specific (allows test/dev files)
103+
- Production .dockerignore should exclude:
104+
- All test files and configurations
105+
- Development-only dependencies
106+
- Documentation and non-essential files
107+
- Local development configurations
108+
- Development .dockerignore should:
109+
- Allow test files and configurations
110+
- Allow development dependencies
111+
- Still exclude node_modules and sensitive files
112+
- Keep Docker-specific files excluded
113+
- Docker Compose configurations:
114+
- Production: docker-compose.yml in root
115+
- Development: docker-compose.dev.yml in /dev
116+
- Use BuildKit features when needed
117+
- Document any special build arguments
118+
- Multi-stage builds:
119+
- Use appropriate base images
120+
- Minimize final image size
121+
- Separate development and production stages
122+
- Use specific version tags for base images
123+
124+
# Code Style
125+
- Follow ESLint and Prettier configurations
126+
- Use meaningful variable and function names
127+
- Keep functions small and focused
128+
- Maximum line length: 100 characters
129+
- Use modern JavaScript features appropriately
130+
- Prefer clarity over cleverness

.dockerignore

+52-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,56 @@
1+
# Version control
2+
.git
3+
.gitignore
4+
5+
# Dependencies
16
node_modules
27
npm-debug.log
3-
uploads/*
8+
yarn-debug.log
9+
yarn-error.log
10+
11+
# Environment variables
412
.env
5-
.git
6-
.gitignore
13+
.env.*
14+
!.env.example
15+
16+
# Development
17+
.vscode
18+
.idea
19+
*.swp
20+
*.swo
21+
22+
# Build outputs
23+
dist
24+
build
25+
coverage
26+
27+
# Local uploads (development only)
28+
local_uploads
29+
30+
# Logs
31+
logs
32+
*.log
33+
34+
# System files
35+
.DS_Store
36+
Thumbs.db
37+
38+
# Docker
39+
.docker
40+
docker-compose*.yml
41+
Dockerfile*
42+
43+
# Documentation
744
README.md
45+
CHANGELOG.md
46+
docs
47+
48+
# Keep test files and configs for development builds
49+
# __tests__
50+
# jest.config.js
51+
# *.test.js
52+
# *.spec.js
53+
# .eslintrc*
54+
# .prettierrc*
55+
.editorconfig
56+
nodemon.json

.eslintignore

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Dependencies
2+
node_modules/
3+
4+
# Upload directories
5+
local_uploads/
6+
uploads/
7+
test_uploads/
8+
9+
# Build directories
10+
dist/
11+
build/
12+
13+
# Coverage directory
14+
coverage/

.eslintrc.json

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"env": {
3+
"node": true,
4+
"es2022": true
5+
},
6+
"extends": [
7+
"eslint:recommended",
8+
"plugin:node/recommended",
9+
"prettier"
10+
],
11+
"parserOptions": {
12+
"ecmaVersion": 2022
13+
},
14+
"rules": {
15+
"node/exports-style": ["error", "module.exports"],
16+
"node/file-extension-in-import": ["error", "always"],
17+
"node/prefer-global/buffer": ["error", "always"],
18+
"node/prefer-global/console": ["error", "always"],
19+
"node/prefer-global/process": ["error", "always"],
20+
"node/prefer-global/url-search-params": ["error", "always"],
21+
"node/prefer-global/url": ["error", "always"],
22+
"node/prefer-promises/dns": "error",
23+
"node/prefer-promises/fs": "error"
24+
}
25+
}

.gitignore

+51-1
Original file line numberDiff line numberDiff line change
@@ -149,5 +149,55 @@ Thumbs.db
149149
# Development
150150
dev/*
151151
!dev/docker-compose.dev.yml
152+
!dev/Dockerfile.dev
153+
!dev/.dockerignore
152154
!dev/dev.sh
153-
!dev/README.md
155+
!dev/README.md
156+
157+
# Dependencies
158+
node_modules/
159+
/.pnp
160+
.pnp.js
161+
162+
# Testing
163+
/coverage
164+
.nyc_output
165+
166+
# Production
167+
/build
168+
/dist
169+
170+
# Development
171+
.env
172+
.env.local
173+
.env.development.local
174+
.env.test.local
175+
.env.production.local
176+
dev/.env.dev
177+
178+
# Debug
179+
npm-debug.log*
180+
yarn-debug.log*
181+
yarn-error.log*
182+
183+
# IDE
184+
.idea/
185+
.vscode/
186+
*.swp
187+
*.swo
188+
189+
# OS
190+
.DS_Store
191+
Thumbs.db
192+
193+
# Application specific
194+
/uploads/*
195+
/local_uploads/*
196+
!uploads/.gitkeep
197+
!local_uploads/.gitkeep
198+
199+
# Misc
200+
*.log
201+
.env.*
202+
!.env.example
203+
!dev/.env.dev.example

.prettierrc

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"semi": true,
3+
"trailingComma": "es5",
4+
"singleQuote": true,
5+
"printWidth": 100,
6+
"tabWidth": 2,
7+
"useTabs": false,
8+
"endOfLine": "lf"
9+
}

Dockerfile

+46-8
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,64 @@
1-
FROM node:18-alpine
1+
# Base stage for shared configurations
2+
FROM node:20-alpine as base
23

3-
# Install python and create virtual environment
4+
# Install python and create virtual environment with minimal dependencies
45
RUN apk add --no-cache python3 py3-pip && \
5-
python3 -m venv /opt/venv
6+
python3 -m venv /opt/venv && \
7+
rm -rf /var/cache/apk/*
68

79
# Activate virtual environment and install apprise
810
RUN . /opt/venv/bin/activate && \
9-
pip install --no-cache-dir apprise
11+
pip install --no-cache-dir apprise && \
12+
find /opt/venv -type d -name "__pycache__" -exec rm -r {} +
1013

1114
# Add virtual environment to PATH
1215
ENV PATH="/opt/venv/bin:$PATH"
1316

14-
WORKDIR /app
17+
WORKDIR /usr/src/app
18+
19+
# Dependencies stage
20+
FROM base as deps
1521

1622
COPY package*.json ./
23+
RUN npm ci --only=production && \
24+
# Remove npm cache
25+
npm cache clean --force
26+
27+
# Development stage
28+
FROM deps as development
29+
ENV NODE_ENV=development
30+
31+
# Install dev dependencies
32+
RUN npm install && \
33+
npm cache clean --force
34+
35+
# Create upload directories
36+
RUN mkdir -p uploads local_uploads
1737

18-
RUN npm install
38+
# Copy source with specific paths to avoid unnecessary files
39+
COPY src/ ./src/
40+
COPY public/ ./public/
41+
COPY __tests__/ ./__tests__/
42+
COPY dev/ ./dev/
43+
COPY .eslintrc.json .eslintignore ./
1944

20-
COPY . .
45+
# Expose port
46+
EXPOSE 3000
47+
48+
CMD ["npm", "run", "dev"]
2149

50+
# Production stage
51+
FROM deps as production
52+
ENV NODE_ENV=production
53+
54+
# Create upload directory
2255
RUN mkdir -p uploads
2356

57+
# Copy only necessary source files
58+
COPY src/ ./src/
59+
COPY public/ ./public/
60+
61+
# Expose port
2462
EXPOSE 3000
2563

26-
CMD ["node", "server.js"]
64+
CMD ["npm", "start"]

0 commit comments

Comments
 (0)