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
Empty file added .github/workflows/ci.yml
Empty file.
2 changes: 2 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
pnpm exec commitlint --edit $1
2 changes: 2 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
pnpm format && pnpm --filter backend lint
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
dist
build
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"semi": true,
"singleQuote": true,
"trailingComma": "all"
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ This repository contains both the frontend and backend code in a single reposito
## Structure

mysocialcode/

- frontend/ – Frontend application (Expo / React Native)
- backend/ – Backend API (Node.js / Express)

Expand Down
16 changes: 16 additions & 0 deletions backend/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import js from '@eslint/js';
import tseslint from 'typescript-eslint';

export default [
{
ignores: ['dist/**', 'build/**', 'node_modules/**'],
rules: {
'@typescript-eslint/no-unused-vars': [
'error',
{ argsIgnorePattern: '^_' },
],
},
},
js.configs.recommended,
...tseslint.configs.recommended,
];
36 changes: 28 additions & 8 deletions backend/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,33 @@
{
"name": "backend",
"version": "1.0.0",
"description": "",
"main": "index.js",
"private": true,
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"dev": "ts-node-dev --respawn --transpile-only src/server.ts",
"build": "tsc",
"start": "node dist/server.js",
"lint": "eslint"
},
"keywords": [],
"author": "",
"license": "ISC",
"type": "commonjs"
"dependencies": {
"dotenv": "^17.2.3",
"express": "^5.2.1",
"pg": "^8.16.3",
"pino": "^10.1.0",
"pino-http": "^11.0.0",
"reflect-metadata": "^0.2.2",
"typeorm": "^0.3.28"
},
"devDependencies": {
"@commitlint/cli": "^20.2.0",
"@commitlint/config-conventional": "^20.2.0",
"@eslint/js": "^9.39.2",
"@types/express": "^5.0.6",
"@types/node": "^25.0.3",
"@types/pg": "^8.16.0",
"@typescript-eslint/eslint-plugin": "^8.51.0",
"@typescript-eslint/parser": "^8.51.0",
"eslint": "^9.39.2",
"ts-node-dev": "^2.0.0",
"typescript": "~5.9.3",
"typescript-eslint": "^8.51.0"
}
}
15 changes: 15 additions & 0 deletions backend/src/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import express from 'express';
import { pinoHttp } from 'pino-http';
import { logger } from './utils/logger';
import { notFound } from './middleware/notFound';
import { errorHandler } from './middleware/errorHandler';
import Healthrouter from './routes/health';
const app = express();
app.use(express.json());
app.use(
pinoHttp({ logger, autoLogging: { ignore: (req) => req.url === 'health' } }),
);
app.use('/health', Healthrouter);
app.use(notFound);
app.use(errorHandler);
export default app;
15 changes: 15 additions & 0 deletions backend/src/data-source.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'dotenv/config';
import { DataSource } from 'typeorm';
import { User } from './entities/User';
if (!process.env.DATABASE_URL) {
throw new Error('DATABASE_URL is not defined');
}
export const appDataSouce = new DataSource({
type: 'postgres',
url: process.env.DATABASE_URL,
ssl: {
rejectUnauthorized: false,
},
entities: [User],
synchronize: true,
});
8 changes: 8 additions & 0 deletions backend/src/entities/User.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Entity, PrimaryGeneratedColumn, Column } from 'typeorm';
@Entity()
export class User {
@PrimaryGeneratedColumn()
id!: number;
@Column()
phone!: string;
}
18 changes: 18 additions & 0 deletions backend/src/middleware/errorHandler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Request, Response, NextFunction } from 'express';

export const errorHandler = (
err: unknown,
req: Request,
res: Response,
_next: NextFunction,
) => {
console.error(err);

let message = 'Internal Server Error';

if (err instanceof Error) {
message = err.message;
}

res.status(500).json({ message });
};
7 changes: 7 additions & 0 deletions backend/src/middleware/notFound.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Request, Response, NextFunction } from 'express';

export const notFound = (req: Request, res: Response, _next: NextFunction) => {
res.status(404).json({
message: 'Route not found',
});
};
25 changes: 25 additions & 0 deletions backend/src/routes/health.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import express from 'express';
import { appDataSouce } from '../data-source';
const Healthrouter = express.Router();
Healthrouter.get('/health', async (req, res) => {
try {
if (!appDataSouce.isInitialized) {
return res.status(503).json({
status: 'eroor',
service: 'mysocial-code-backend',
db: 'not initialized',
});
}
await appDataSouce.query('SELECT 1');
return res.status(200).json({
status: 'ok',
service: 'mysocial-code-backend',
db: 'up',
});
} catch (err) {
return res
.status(503)
.json({ status: err, service: 'mysocialcode-backend', db: 'down' });
}
});
export default Healthrouter;
23 changes: 23 additions & 0 deletions backend/src/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import dotenv from 'dotenv';
dotenv.config();
import app from './app';
import { logger } from './utils/logger';
import { appDataSouce } from './data-source';
if (!process.env.PORT) {
throw new Error('PORT is not defined in environment variables');
}

(async () => {
try {
await appDataSouce.initialize();
logger.info('database connected success fully');
} catch (error) {
logger.error({ err: error }, 'error connecting the database');

process.exit(1);
}
})();

app.listen(process.env.PORT, () => {
logger.info('server started dont need worry');
});
4 changes: 4 additions & 0 deletions backend/src/utils/logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import pino from 'pino';
export const logger = pino({
level: process.env.NODE_ENV === 'production' ? 'info' : 'debug',
});
13 changes: 13 additions & 0 deletions backend/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"target": "ES2020",
"module": "CommonJS",
"rootDir": "./src",
"outDir": "./dist",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true
}
}
3 changes: 3 additions & 0 deletions commitlint.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
extends: ['@commitlint/config-conventional'],
};
11 changes: 8 additions & 3 deletions frontend/app/(tabs)/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,24 @@ export default function TabLayout() {
tabBarActiveTintColor: Colors[colorScheme ?? 'light'].tint,
headerShown: false,
tabBarButton: HapticTab,
}}>
}}
>
<Tabs.Screen
name="index"
options={{
title: 'Home',
tabBarIcon: ({ color }) => <IconSymbol size={28} name="house.fill" color={color} />,
tabBarIcon: ({ color }) => (
<IconSymbol size={28} name="house.fill" color={color} />
),
}}
/>
<Tabs.Screen
name="explore"
options={{
title: 'Explore',
tabBarIcon: ({ color }) => <IconSymbol size={28} name="paperplane.fill" color={color} />,
tabBarIcon: ({ color }) => (
<IconSymbol size={28} name="paperplane.fill" color={color} />
),
}}
/>
</Tabs>
Expand Down
44 changes: 29 additions & 15 deletions frontend/app/(tabs)/explore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,31 @@ export default function TabTwoScreen() {
name="chevron.left.forwardslash.chevron.right"
style={styles.headerImage}
/>
}>
}
>
<ThemedView style={styles.titleContainer}>
<ThemedText
type="title"
style={{
fontFamily: Fonts.rounded,
}}>
}}
>
Explore
</ThemedText>
</ThemedView>
<ThemedText>This app includes example code to help you get started.</ThemedText>
<ThemedText>
This app includes example code to help you get started.
</ThemedText>
<Collapsible title="File-based routing">
<ThemedText>
This app has two screens:{' '}
<ThemedText type="defaultSemiBold">app/(tabs)/index.tsx</ThemedText> and{' '}
<ThemedText type="defaultSemiBold">app/(tabs)/index.tsx</ThemedText>{' '}
and{' '}
<ThemedText type="defaultSemiBold">app/(tabs)/explore.tsx</ThemedText>
</ThemedText>
<ThemedText>
The layout file in <ThemedText type="defaultSemiBold">app/(tabs)/_layout.tsx</ThemedText>{' '}
The layout file in{' '}
<ThemedText type="defaultSemiBold">app/(tabs)/_layout.tsx</ThemedText>{' '}
sets up the tab navigator.
</ThemedText>
<ExternalLink href="https://docs.expo.dev/router/introduction">
Expand All @@ -47,15 +53,17 @@ export default function TabTwoScreen() {
</Collapsible>
<Collapsible title="Android, iOS, and web support">
<ThemedText>
You can open this project on Android, iOS, and the web. To open the web version, press{' '}
<ThemedText type="defaultSemiBold">w</ThemedText> in the terminal running this project.
You can open this project on Android, iOS, and the web. To open the
web version, press <ThemedText type="defaultSemiBold">w</ThemedText>{' '}
in the terminal running this project.
</ThemedText>
</Collapsible>
<Collapsible title="Images">
<ThemedText>
For static images, you can use the <ThemedText type="defaultSemiBold">@2x</ThemedText> and{' '}
<ThemedText type="defaultSemiBold">@3x</ThemedText> suffixes to provide files for
different screen densities
For static images, you can use the{' '}
<ThemedText type="defaultSemiBold">@2x</ThemedText> and{' '}
<ThemedText type="defaultSemiBold">@3x</ThemedText> suffixes to
provide files for different screen densities
</ThemedText>
<Image
source={require('@/assets/images/react-logo.png')}
Expand All @@ -68,8 +76,9 @@ export default function TabTwoScreen() {
<Collapsible title="Light and dark mode components">
<ThemedText>
This template has light and dark mode support. The{' '}
<ThemedText type="defaultSemiBold">useColorScheme()</ThemedText> hook lets you inspect
what the user&apos;s current color scheme is, and so you can adjust UI colors accordingly.
<ThemedText type="defaultSemiBold">useColorScheme()</ThemedText> hook
lets you inspect what the user&apos;s current color scheme is, and so
you can adjust UI colors accordingly.
</ThemedText>
<ExternalLink href="https://docs.expo.dev/develop/user-interface/color-themes/">
<ThemedText type="link">Learn more</ThemedText>
Expand All @@ -78,8 +87,10 @@ export default function TabTwoScreen() {
<Collapsible title="Animations">
<ThemedText>
This template includes an example of an animated component. The{' '}
<ThemedText type="defaultSemiBold">components/HelloWave.tsx</ThemedText> component uses
the powerful{' '}
<ThemedText type="defaultSemiBold">
components/HelloWave.tsx
</ThemedText>{' '}
component uses the powerful{' '}
<ThemedText type="defaultSemiBold" style={{ fontFamily: Fonts.mono }}>
react-native-reanimated
</ThemedText>{' '}
Expand All @@ -88,7 +99,10 @@ export default function TabTwoScreen() {
{Platform.select({
ios: (
<ThemedText>
The <ThemedText type="defaultSemiBold">components/ParallaxScrollView.tsx</ThemedText>{' '}
The{' '}
<ThemedText type="defaultSemiBold">
components/ParallaxScrollView.tsx
</ThemedText>{' '}
component provides a parallax effect for the header image.
</ThemedText>
),
Expand Down
21 changes: 15 additions & 6 deletions frontend/app/(tabs)/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@ export default function HomeScreen() {
source={require('@/assets/images/partial-react-logo.png')}
style={styles.reactLogo}
/>
}>
}
>
<ThemedView style={styles.titleContainer}>
<ThemedText type="title">Welcome!</ThemedText>
<HelloWave />
</ThemedView>
<ThemedView style={styles.stepContainer}>
<ThemedText type="subtitle">Step 1: Try it</ThemedText>
<ThemedText>
Edit <ThemedText type="defaultSemiBold">app/(tabs)/index.tsx</ThemedText> to see changes.
Press{' '}
Edit{' '}
<ThemedText type="defaultSemiBold">app/(tabs)/index.tsx</ThemedText>{' '}
to see changes. Press{' '}
<ThemedText type="defaultSemiBold">
{Platform.select({
ios: 'cmd + d',
Expand All @@ -43,7 +45,11 @@ export default function HomeScreen() {
</Link.Trigger>
<Link.Preview />
<Link.Menu>
<Link.MenuAction title="Action" icon="cube" onPress={() => alert('Action pressed')} />
<Link.MenuAction
title="Action"
icon="cube"
onPress={() => alert('Action pressed')}
/>
<Link.MenuAction
title="Share"
icon="square.and.arrow.up"
Expand All @@ -68,8 +74,11 @@ export default function HomeScreen() {
<ThemedText type="subtitle">Step 3: Get a fresh start</ThemedText>
<ThemedText>
{`When you're ready, run `}
<ThemedText type="defaultSemiBold">npm run reset-project</ThemedText> to get a fresh{' '}
<ThemedText type="defaultSemiBold">app</ThemedText> directory. This will move the current{' '}
<ThemedText type="defaultSemiBold">
npm run reset-project
</ThemedText>{' '}
to get a fresh <ThemedText type="defaultSemiBold">app</ThemedText>{' '}
directory. This will move the current{' '}
<ThemedText type="defaultSemiBold">app</ThemedText> to{' '}
<ThemedText type="defaultSemiBold">app-example</ThemedText>.
</ThemedText>
Expand Down
Loading