Skip to content

Commit 12ac426

Browse files
authored
Merge pull request #49 from zecrypt-io/main
Sync Preview
2 parents 030f898 + d0df3a6 commit 12ac426

File tree

13 files changed

+1071
-530
lines changed

13 files changed

+1071
-530
lines changed

LICENSE.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
Custom License for Zecrypt
2+
==========================
3+
4+
Copyright (c) Zecrypt Labs, 2025
5+
6+
This software is licensed under the terms below. By using this software, you agree to abide by the following conditions.
7+
8+
---
9+
10+
Section 1: Personal and Non-Commercial Use
11+
------------------------------------------
12+
Permission is granted, free of charge, to individuals to use, modify, and self-host this software for **personal and non-commercial purposes**, subject to the following conditions:
13+
14+
- You may **use**, **modify**, and **deploy** the software for yourself or within your organization as long as no revenue is generated directly or indirectly from the use.
15+
- Any modified version must retain this license and attribution to the original author.
16+
- You may share your personal modifications **only if** the source code is made publicly available and licensed under the same terms as this license.
17+
18+
---
19+
20+
Section 2: Commercial Use
21+
--------------------------
22+
Commercial use of this software is **strictly prohibited without purchasing a commercial license** from Zecrypt Labs.
23+
24+
Commercial use includes, but is not limited to:
25+
26+
- Hosting the software as a service (SaaS) or product offering.
27+
- Using the software internally in a business to generate revenue or reduce cost.
28+
- Selling, sublicensing, or distributing the software or any derivative product.
29+
- Embedding the software in a commercial product or offering.
30+
31+
To obtain a commercial license, contact:
32+
33+
Zecrypt Labs
34+
Email: zecryptapp@gmail.com
35+
Website: https://zecrypt.io
36+
37+
---
38+
39+
Section 3: Open Source Requirement for Derivative Works
40+
-------------------------------------------------------
41+
Any derivative work or modified version that is deployed or distributed publicly, whether for personal or commercial use, **must be open-sourced** under the same license.
42+
43+
You are required to:
44+
45+
- Publish the source code of your modified version.
46+
- Credit the original project and maintain this license.
47+
48+
---
49+
50+
Section 4: Warranty Disclaimer
51+
-------------------------------
52+
This software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose, and noninfringement.
53+
54+
In no event shall the authors be liable for any claim, damages, or other liability in connection with the software.
55+
56+
---
57+
58+
For any questions or licensing inquiries, please contact the maintainer at zecryptapp@gmail.com.

README.md

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
# Zecrypt Server
2+
3+
A modern, secure, and scalable application built with FastAPI and Next.js. This monorepo contains both the backend server and frontend web application.
4+
5+
## 🚀 Features
6+
7+
- **Backend (FastAPI)**
8+
- RESTful API with OpenAPI documentation
9+
- MongoDB database integration
10+
- JWT authentication
11+
- Rate limiting
12+
- CORS support
13+
- Internationalization (i18n)
14+
- Structured logging
15+
- Redis caching
16+
- TOTP (Time-based One-Time Password) support
17+
18+
- **Frontend (Next.js)**
19+
- Modern React with TypeScript
20+
- Responsive UI with Tailwind CSS
21+
- Internationalization support
22+
- Dark/Light theme
23+
- Redux state management
24+
- Form handling with React Hook Form
25+
- Beautiful UI components with Radix UI
26+
- Toast notifications
27+
- Data visualization with Recharts
28+
29+
## 📋 Prerequisites
30+
31+
- Python 3.11+
32+
- Node.js 18+
33+
- MongoDB
34+
- Redis
35+
- Docker (optional)
36+
37+
## 🛠️ Installation
38+
39+
### Backend Setup
40+
41+
1. Navigate to the backend directory:
42+
```bash
43+
cd packages/backend-server
44+
```
45+
46+
2. Create a virtual environment:
47+
```bash
48+
python -m venv venv
49+
source venv/bin/activate # On Windows: venv\Scripts\activate
50+
```
51+
52+
3. Install dependencies:
53+
```bash
54+
pip install -r requirements.txt
55+
```
56+
57+
4. Create a `.env` file with the following variables:
58+
```env
59+
MONGO_DB_URL=your_mongodb_url
60+
JWT_SECRET=your_jwt_secret
61+
JWT_ALGORITHM=HS512
62+
ENV=development
63+
DB_NAME=your_db_name
64+
STACK_AUTH_PROJECT_ID=your_project_id
65+
STACK_AUTH_CLIENT_ID=your_client_id
66+
STACK_AUTH_CLIENT_SECRET=your_client_secret
67+
TOTP_SECRET=your_totp_secret
68+
```
69+
70+
### Frontend Setup
71+
72+
1. Navigate to the frontend directory:
73+
```bash
74+
cd packages/frontend-web
75+
```
76+
77+
2. Install dependencies:
78+
```bash
79+
npm install
80+
```
81+
82+
3. Create a `.env.local` file with necessary environment variables (if required)
83+
84+
## 🚀 Running the Application
85+
86+
### Backend
87+
88+
1. Start the backend server:
89+
```bash
90+
cd packages/backend-server
91+
uvicorn app.main:app --reload
92+
```
93+
94+
The server will start at `http://localhost:8000`
95+
96+
- API Documentation: `http://localhost:8000/docs` (Swagger UI)
97+
- Alternative Documentation: `http://localhost:8000/redoc` (ReDoc)
98+
99+
### Frontend
100+
101+
1. Start the frontend development server:
102+
```bash
103+
cd packages/frontend-web
104+
npm run dev
105+
```
106+
107+
The application will be available at `http://localhost:3000`
108+
109+
## 🐳 Docker Deployment
110+
111+
### Backend
112+
113+
1. Build the Docker image:
114+
```bash
115+
cd packages/backend-server
116+
docker build -t zecrypt-backend .
117+
```
118+
119+
2. Run the container:
120+
```bash
121+
docker run -p 8080:8080 zecrypt-backend
122+
```
123+
124+
### Frontend
125+
126+
1. Build the Docker image:
127+
```bash
128+
cd packages/frontend-web
129+
docker build -t zecrypt-frontend .
130+
```
131+
132+
2. Run the container:
133+
```bash
134+
docker run -p 3000:3000 zecrypt-frontend
135+
```
136+
137+
## 📚 API Documentation
138+
139+
When running in development mode, the API documentation is available at:
140+
- Swagger UI: `http://localhost:8000/docs`
141+
- ReDoc: `http://localhost:8000/redoc`
142+
- OpenAPI Schema: `http://localhost:8000/openapi.json`
143+
144+
Note: API documentation is disabled in production environment for security reasons.
145+
146+
## 🔒 Security
147+
148+
- JWT-based authentication
149+
- Rate limiting to prevent abuse
150+
- CORS protection
151+
- Environment-based configuration
152+
- Secure password hashing
153+
- TOTP for two-factor authentication
154+
155+
## 🌐 Internationalization
156+
157+
The application supports multiple languages through:
158+
- Backend: Custom i18n implementation
159+
- Frontend: next-intl for translations
160+
161+
## 📝 License
162+
163+
This project is licensed under the terms of the license included in the repository.
164+
165+
## 🤝 Contributing
166+
167+
1. Fork the repository
168+
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
169+
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
170+
4. Push to the branch (`git push origin feature/amazing-feature`)
171+
5. Open a Pull Request
172+
173+
## 📞 Support
174+
175+
For support, please open an issue in the repository or contact the maintainer [@anandude](https://github.com/anandude) [itsmeakhil](https://github.com/itsmeakhil).
176+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
MONGO_DB_URL="string"
2+
JWT_SECRET="string"
3+
ENV="string"
4+
DB_NAME="string"
5+
STACK_AUTH_PROJECT_ID="string"
6+
STACK_AUTH_CLIENT_ID="string"
7+
STACK_AUTH_CLIENT_SECRET="string"
8+
TOTP_SECRET="string"

packages/frontend-web/components/auth-error-listener.tsx

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { useRouter } from 'next/navigation';
66
import { useUser } from '@stackframe/stack';
77
import { RootState } from '@/libs/Redux/store';
88
import { clearUserData, setAuthError } from '@/libs/Redux/userSlice';
9-
import { secureSetItem } from '@/libs/session-storage-utils';
9+
import { logout } from '@/libs/utils';
1010

1111
interface AuthErrorListenerProps {
1212
children: React.ReactNode;
@@ -16,35 +16,21 @@ interface AuthErrorListenerProps {
1616
export function AuthErrorListener({ children, locale }: AuthErrorListenerProps) {
1717
const dispatch = useDispatch();
1818
const router = useRouter();
19-
const user = useUser(); // Use the useUser hook here
19+
const user = useUser();
2020
const authError = useSelector((state: RootState) => state.user.authError);
2121

2222
useEffect(() => {
2323
const handleAuthError = async () => {
2424
if (authError) {
2525
console.log('Auth error detected, performing full logout.');
2626

27-
// Clear access token cookie
28-
document.cookie = 'access_token=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT; secure; samesite=strict';
29-
30-
// Clear user data from Redux
31-
dispatch(clearUserData());
32-
33-
// Clear session storage
34-
await secureSetItem("privateKey", "");
35-
await secureSetItem("publicKey", "");
36-
37-
// Clear localStorage items
38-
localStorage.removeItem("userPublicKey");
39-
localStorage.removeItem("zecrypt_device_id");
40-
41-
// Sign out from Stack
42-
if (user && user.signOut) {
43-
await user.signOut();
44-
}
45-
46-
// Redirect to login and replace history entry
47-
router.replace(`/${locale}/login`);
27+
await logout({
28+
user,
29+
dispatch,
30+
router,
31+
clearUserData,
32+
locale
33+
});
4834

4935
// Reset auth error state
5036
dispatch(setAuthError());

packages/frontend-web/components/dashboard-layout.tsx

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import { useUser } from "@stackframe/stack";
4949
import { useTranslator } from "@/hooks/use-translations";
5050
import { secureSetItem } from '@/libs/session-storage-utils';
5151
import { SearchModal } from "@/components/search-modal";
52+
import { logout } from "@/libs/utils";
5253

5354
interface DashboardLayoutProps {
5455
children: React.ReactNode;
@@ -363,27 +364,14 @@ export function DashboardLayout({ children, locale = "en" }: DashboardLayoutProp
363364
};
364365

365366
const handleLogout = async () => {
366-
try {
367-
document.cookie = 'access_token=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT; secure; samesite=strict';
368-
369-
dispatch(clearUserData());
370-
dispatch(resetWorkspaceState());
371-
372-
await secureSetItem("privateKey", "");
373-
await secureSetItem("publicKey", "");
374-
375-
localStorage.removeItem("userPublicKey");
376-
localStorage.removeItem("zecrypt_device_id");
377-
378-
if (user) {
379-
await user.signOut();
380-
}
381-
382-
router.replace(`/${locale}/login`);
383-
} catch (error) {
384-
console.error("Logout error:", error);
385-
router.replace(`/${locale}/login`);
386-
}
367+
await logout({
368+
user,
369+
dispatch,
370+
router,
371+
clearUserData,
372+
resetWorkspaceState,
373+
locale
374+
});
387375
};
388376

389377
const switchLanguage = (newLocale: string) => {

0 commit comments

Comments
 (0)