- Aura
Aura is a social media website where you can post about your daily life incidents and our AI will do awesome calculations to give that particular some aura points. You can track your total aura and see your friends too. Each incident is assigned an aura value based on its sentiment, creating a unique way for users to visualize and understand their daily experiences.
- User authentication (login, register, OTP verification)
- Create and share life incidents
- AI-powered sentiment analysis for Aura Points
- Upvote and downvote system for incidents
- Responsive design for mobile and desktop
- Real-time updates using optimistic UI
- Infinite scroll for incident feed
- Dark mode UI
- Frontend:
- Next.js (App Router)
- React
- Tailwind CSS
- Framer Motion
- ShadCN UI Components
- Backend:
- Next.js API Routes
- Supabase (PostgreSQL)
- Redis (for caching)
- Authentication:
- Custom JWT-based auth system
- State Management:
- React Hooks
- Context API
- Deployment:
- Vercel
- Node.js (v14 or later)
- npm or yarn
- Supabase account
- Redis account
- Clone the repository
git clone https://github.com/yourusername/aura-io.git
cd aura-io- Install dependencies
npm installor
yarn install-
Set up environment variables: Create a
.env.localfile in the root directory and add the following variables:NEXT_PUBLIC_SUPABASE_URL=your_supabase_urlNEXT_PUBLIC_SUPABASE_ANON_KEY=your_supabase_anon_keyJWT_SECRET=your_jwt_secretEMAIL_ADDRESS = your_email_address_from_which_otp_will_be_sentEMAIL_PASSWORD = your_email_app_password[Help]REDIS_PW = your_redis_database_passwordREDIS_HOST = your_redis_host_addressREDIS_PORT = your_redis_portHUGGING_FACE_API_TOKEN = your_hugging_face_api_token -
Run the development server
npm run devor
yarn dev- Open http://localhost:3000 in your browser to see the application.
src/ ├── app/ │ ├── api/ │ │ └── ... │ ├── home/ │ │ └── page.js │ ├── incidents/ │ │ └── page.js │ ├── (auth)/ │ │ ├── login/ │ │ │ └── page.js │ │ ├── register/ │ │ │ └── page.js │ │ └── verifyOtp/ │ │ └── page.js │ ├── profile/ │ │ └── page.js │ ├── layout.js │ └── page.js ├── components/ │ ├── common/ │ │ ├── AuraLoader.js │ │ ├── Header.js │ │ └── SideMenu.js │ ├── homePage/ │ │ ├── AuraPointsAnimation.js │ │ └── PostLoader.js │ ├── profile/ │ │ └── ProfileLoadingScreen.js │ └── ui/ │ └── ... ├── lib/ │ ├── db.js │ ├── fetchUserData.js │ ├── supabaseClient.js │ └── utils.js ├── public/ │ └── ... ├── styles/ │ └── globals.css ├── tests/ │ └── db/ │ └── test-db.js ├── utils/ │ ├── auth.js │ ├── capitalizeWords.js │ ├── changeDateToReadable.js │ └── voteHandler.js ├── .env.local ├── .eslintrc.json ├── .gitignore ├── aura-application-er-diagram.mermaid ├── components.json ├── docker-compose.yml ├── jsconfig.json ├── next.config.mjs ├── postcss.config.mjs ├── package.json ├── README.md └── tailwind.config.cjs
- Register a new account or log in to an existing one.
- On the home page, you can view incidents shared by other users.
- Click the
Add New Incidentbutton to share your own life incident. - The AI will analyze your incident and assign Aura Points.
- You can upvote or downvote incidents.
- Visit your profile page to see your top aura moments and track your emotional journey.
- Visit your incidents page to see all your incidents.
/api/auth/register: Register a new user/api/auth/login: Log in a user/api/auth/verification/verifyOtp: Verify OTP for email confirmation/api/user/homePage: Get incidents for the home page feed/api/user/incidents/sentiment: Analyze sentiment of a new incident/api/user/incidents/write-incident: Create a new incident/api/user/vote: Handle upvotes and downvotes/api/user/incidents/getIncidents: Get a user's incidents for their profile
The authentication system in Aura is designed to handle user registration, login, and OTP verification. It uses a custom JWT-based authentication system to manage user sessions securely.
- Registration: Users can register by providing their email and password. An OTP is sent to their email for verification.
- Login: Users can log in using their email and password. Upon successful login, a JWT token is generated and stored.
- OTP Verification: Users verify their email by entering the OTP sent to their email during registration.
-
User Registration
- Endpoint:
/api/auth/register - The user submits their email and password.
- The server creates a new user record in the database and sends an OTP to the user's email.
- The user is prompted to enter the OTP for verification.
- Endpoint:
-
OTP Verification
- Endpoint:
/api/auth/verification/verifyOtp - The user submits the OTP received via email.
- The server verifies the OTP and activates the user's account.
- Endpoint:
-
User Login
- Endpoint:
/api/auth/login - The user submits their email and password.
- The server verifies the credentials and generates a JWT token.
- The JWT token is sent to the client and stored (e.g., in local storage or cookies).
- Endpoint:
-
Protected Routes
- The client includes the JWT token in the Authorization header for requests to protected routes.
- The server verifies the JWT token before granting access to protected resources.
-
Register:
POST /api/auth/register- Request Body:
{ "email": "user@example.com", "password": "password123" } - Response:
{ "message": "OTP sent to your email" }
- Request Body:
-
Verify OTP:
POST /api/auth/verification/verifyOtp- Request Body:
{ "email": "user@example.com", "otp": "123456" } - Response:
{ "message": "Email verified successfully" }
- Request Body:
-
Login:
POST /api/auth/login- Request Body:
{ "email": "user@example.com", "password": "password123" } - Response:
{ "token": "jwt_token_here" }
- Request Body:
// filepath: /src/app/api/auth/register/route.js
import { supabase } from '@/lib/supabaseClient';
export async function POST(request) {
const { email, password } = await request.json();
const { data, error } = await supabase.auth.signUp({ email, password });
if (error) {
return new Response(JSON.stringify({ error: error.message }), { status: 400 });
}
// Send OTP to user's email (implementation not shown)
await sendOtpToEmail(email);
return new Response(JSON.stringify({ message: 'OTP sent to your email' }), { status: 200 });
}// filepath: /src/app/api/auth/verification/verifyOtp/route.js
import { supabase } from '@/lib/supabaseClient';
export async function POST(request) {
const { email, otp } = await request.json();
const { data, error } = await supabase.auth.verifyOtp({ email, otp });
if (error) {
return new Response(JSON.stringify({ error: error.message }), { status: 400 });
}
return new Response(JSON.stringify({ message: 'Email verified successfully' }), { status: 200 });
}// filepath: /src/app/api/auth/login/route.js
import { supabase } from '@/lib/supabaseClient';
import jwt from 'jsonwebtoken';
export async function POST(request) {
const { email, password } = await request.json();
const { data, error } = await supabase.auth.signIn({ email, password });
if (error) {
return new Response(JSON.stringify({ error: error.message }), { status: 400 });
}
const token = jwt.sign({ userId: data.user.id }, process.env.JWT_SECRET, { expiresIn: '1h' });
return new Response(JSON.stringify({ token }), { status: 200 });
}Aura uses a combination of Supabase, Redis, and local storage to manage and store data. Each of these technologies serves a specific purpose in the application:
- Supabase: Acts as the primary database and authentication provider.
- Redis: Used for caching to improve performance and reduce database load.
- Local Storage: Used to store user session data on the client side.
erDiagram
USER {
int id PK
string username
string email
string password_hash
datetime created_at
int total_aura_points
int total_incidents
}
INCIDENT {
int id PK
int user_id FK
string description
int aura_points
datetime created_at
int total_likes
int total_comments
}
COMMENT {
int id PK
int user_id FK
int incident_id FK
string content
datetime created_at
}
LIKE {
int id PK
int user_id FK
int incident_id FK
datetime created_at
}
USER ||--o{ INCIDENT : "creates"
USER ||--o{ COMMENT : "writes"
USER ||--o{ LIKE : "gives"
INCIDENT ||--o{ COMMENT : "has"
INCIDENT ||--o{ LIKE : "receives"
Supabase is an open-source Firebase alternative that provides a Postgres database, authentication, and real-time capabilities.
-
User Authentication:
- Supabase handles user registration, login, and OTP verification.
- User data is stored in the
userstable.
-
Incident Management:
- Incidents are stored in the
incidentstable. - Each incident has associated
aura_points,user_id, and other metadata.
- Incidents are stored in the
-
Votes and Comments:
- Votes are stored in the
incident_votestable. - Comments are stored in the
incident_commentstable.
- Votes are stored in the
Fetching Incidents:
// filepath: /src/app/api/user/homePage/route.js
import { supabase } from '@/lib/supabaseClient';
export async function getIncidents(page) {
const { data, error } = await supabase
.from('incidents')
.select('*')
.range((page - 1) * 10, page * 10 - 1);
if (error) {
throw new Error('Error fetching incidents');
}
return data;
}Redis is an in-memory data structure store used for caching to improve performance and reduce the load on the primary database.
- Caching Incident Data:
- Frequently accessed incident data is cached in Redis to reduce the number of database queries.
- Cached data is updated whenever an incident is created, updated, or deleted.
- Session management:
- User session data can be cached in Redis to improve authentication performance.
import Redis from 'ioredis';
const redis = new Redis(process.env.REDIS_URL);
export async function cacheIncidentData(incidentId, data) {
await redis.set(`incident:${incidentId}`, JSON.stringify(data), 'EX', 3600); // Cache for 1 hour
}
export async function getCachedIncidentData(incidentId) {
const data = await redis.get(`incident:${incidentId}`);
return data ? JSON.parse(data) : null;
}Local storage is used to store user session data on the client side. This allows the application to persist user sessions across page reloads.
- Storing JWT Tokens:
- JWT tokens are stored in local storage after user login.
- The token is used to authenticate requests to protected API routes.
export function storeToken(token) {
localStorage.setItem('authToken', token);
}
export function getToken() {
return localStorage.getItem('authToken');
}
export function removeToken() {
localStorage.removeItem('authToken');
}- Type: Line Chart
- Data: Number of incidents over the last 7 days
- Features:
- Smooth trend visualization
- Responsive design
- Interactive tooltips with daily incident counts
- Type: Combined Area and Line Chart
- Data: Positive, negative, and total aura points over the last 7 days
- Features:
- Area chart for positive/negative aura
- Line chart for total aura
- Gradient fills for visual appeal
- Reference line at y=0
- Comprehensive legend
We welcome contributions to Aura.io! Please follow these steps to contribute:
- Fork the repository
- Create a new branch:
git checkout -b feature/your-feature-name - Make your changes and commit them:
git commit -m 'Add some feature' - Push to the branch:
git push origin feature/your-feature-name - Submit a pull request
Please make sure to update tests as appropriate and adhere to the existing coding style.