Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
lonnik committed Jun 27, 2024
1 parent 9edd910 commit 03f7842
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 49 deletions.
58 changes: 37 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,57 +1,68 @@
# Spaces (under development)

TODO: use grammarly and hemmingway

## About

<img src="https://github.com/lonnik/spaces/assets/16211241/583e057e-f667-47bb-a789-649cc61bc7ae" alt="Screenshot of the application" width="200" style="margin-right: 15px; margin-bottom: 15px"/>
<img src="https://github.com/lonnik/spaces/assets/16211241/37f1e8a6-f02b-47f4-bd45-f3c86de0ad8c" alt="Screenshot of the application" width="200" style="margin-right: 15px; margin-bottom: 15px"/>
<img src="https://github.com/lonnik/spaces/assets/16211241/a4934596-fb74-4571-af52-12385c2f539b" alt="Screenshot of the application" width="200" style="margin-right: 15px; margin-bottom: 15px"/>
<img src="https://github.com/lonnik/spaces/assets/16211241/df4dfbc1-ab61-472a-aa80-a95842b45dfb" alt="Screenshot of the application" width="200" style="margin-right: 15px; margin-bottom: 15px"/>
<img src="https://github.com/lonnik/spaces/assets/16211241/7138e5f5-1694-4777-821b-1f0b0959802f" alt="Screenshot of the application" width="200" style="margin-right: 15px; margin-bottom: 15px"/>
<img src="https://github.com/lonnik/spaces/assets/16211241/3b9f0575-d235-4d81-bca6-a54ec7a9ba3a" alt="Screenshot of the application" width="200" style="margin-right: 15px; margin-bottom: 15px"/>
<img src="https://github.com/lonnik/spaces/assets/16211241/5b02e446-b8ab-43b6-9adf-185691372638" alt="Screenshot of the application" width="200" style="margin-right: 15px; margin-bottom: 15px"/>
<img src="https://github.com/lonnik/spaces/assets/16211241/917b32c9-279e-4e79-93f3-5bce8e259581" alt="Screenshot of the application" width="200" style="margin-right: 15px; margin-bottom: 15px"/>
<img src="https://github.com/lonnik/spaces/assets/16211241/6f8f2f7c-dc41-4e20-b052-d5fec0935cc7" alt="Screenshot of the application" width="200" style="margin-right: 15px; margin-bottom: 15px"/>

"Spaces" is supposed to bring people together that are in physical proximity to each other but have never really interacted. You can create a "space" bound to a physical location and set a specific radius to it. Then, other people who open the app and find themselves within the radius of the space's location can access the space and communicate with other members of the space. Once you have accessed a space "on site", you can access it from anywhere anytime.

One of the many use cases would be to create a space for your neighbors. Another one, to create a space for a Pingpong table in the local park so people who play there Pingpong regularly can meet up without having to know each others Whatsapp numbers. You only must have been there once and have accessed the Pingpong table space. People who regularly go play Pingpong in parks know what I am meaning :)
One of the many use cases would be to create a space for your neighborhood. Another one, to create a space for a Pingpong table in the local park so people who play there Pingpong regularly can meet up without having to know each others Whatsapp numbers. You only must have been there once and have accessed the space for the Pingpong table.

From a technical viewpoint, the application consists of a Golang backend with a Redis DB connected to it and a React Native frontend. The backend app will be deployed on a Kubernetes cluster (using Linode -> cheapest option) and will be split into microservices. I am aware that this is a **total overkill** but this project is supposed to be a personal learning project, as a functional app at the end. I will soon move most of the DB functionality from Redis to Postgres to take advantage of the benefits a relational database brings to me (foreign keys, schemas, complex queries etc.).
TODO: above Pingpong table doesn't sound nice

### Testing
From a technical viewpoint, the application consists of a Golang backend with a Redis instance connected to it and a React Native frontend. The backend app will be deployed on a Kubernetes cluster (using Linode -> cheapest option) and will be split into microservices. I am aware that this is a **total overkill** but this project is supposed to be a personal learning project, as a functional app at the end. I will soon move most of the DB functionality from Redis to Postgres to take advantage of the benefits a relational database brings to me (foreign keys, schemas, complex queries etc.).

My testing strategy for the backend service puts an emphasis on end-to-end tests to avoid having brittle tests. This way, I can have fast running tests that cover the whole API from authentication to the DB layer implementation. External APIs (eg Firebase) are mocked and tested using separate integration tests. Important (util) functions are additionally tested using classic unit tests.
## Testing

My testing strategy for the backend service puts an emphasis on end-to-end tests to avoid having brittle tests. This way, I can have fast running tests that cover the whole API from authentication to the DB layer implementation. External APIs (eg Firebase) are mocked and tested using separate integration tests. Critical (util) functions are additionally tested using classic unit tests.
The E2E tests fail in around 20% percent of the cases due to an incorrect implementation of the DB layer using Redis. This will be fixed soon when replacing most of the Redis implementation with PostgreSQL.

### How to run the backend service tests?

In the `services/server` directory, run:

* `make e2e` to run the E2E test
* `make integration` to run the integration tests (The value of the TEST_FIREBASE_API_KEY environment variable must be set in the `services/server/.env.test`)
* `make unit` to run all unit tests
* `make test` to run all tests

You are welcome to go through the code as you please. I'm happy about every bit of feedback!

### Main Tasks before launch
## Main Tasks before launch

* <s>Create backend with Redis as the main DB</s>
* <s>Create screen designs in Figma</s>
* <s>Implement screen designs</s>
* <s>Hook up screens to backend</s>
* <s>Create custom navigator for React Navigation to take advantage of gestures</s>
* <s>Create basic CI/CD pipeline</s>
* <s>Create CI/CD pipeline</s>
* Split backend into microservices with single API Gateway
* Move from Redis to Postgresql as main DB
* Add missing backend API functionality
* Integrate Sentry
* Submit app to Appstore and Playstore

## Useful Commands

`docker compose --profile dev up --build` to start the developer environment (Firebase service account key must be set)

`docker exec -it server-redis-1 redis-cli` to access the Redis CLI from the Redis server started with the above command

`ngrok http http://localhost:8080` to start a ngrok HTTP tunnel exposing the development server

`kubectl port-forward -n test <database service> 5432:5432 &`

## Useful Links

`http://localhost:8001/redis-stack/browser`

## Migrations

([golang-migrate](https://github.com/golang-migrate/migrate) must be installed locally)

Create a migration: `migrate create -ext sql -dir services/server/postgres/migrations -seq <migration name>`

In case of dirty database version:

1. Set version manually to previous version using `migrate force`

2. push again
2. Push again

## Deploy a new instance

Expand Down Expand Up @@ -83,9 +94,14 @@ linode_token = <Linode API token>

* `DOCKERHUB_USERNAME` (f.e. `nteeeeed`)
* `DOCKERHUB_REPO` (f.e. `spaces`)
* `HELM_VERSION` (f.e. `3.14.3`)

### Github Action Secrets

* `DOCKERHUB_TOKEN`
* `FIREBASE_SERVICE_ACCOUNT_KEY_BASE64`
* `LINODE_KUBECONFIG`
* `POSTGRES_HOST`
* `POSTGRES_PASSWORD`
* `TEST_FIREBASE_API_KEY`
* `TEST_FIREBASE_SERVICE_ACCOUNT_KEY_BASE64`
2 changes: 1 addition & 1 deletion apps/mobile_app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const queryClient = new QueryClient();

export default function App() {
return (
<GestureHandlerRootView style={{ flex: 1, backgroundColor: "#000" }}>
<GestureHandlerRootView style={{ flex: 1, backgroundColor: "#fff" }}>
<NotificationStateProvider>
<UserStateProvider>
<NewSpaceStateProvider>
Expand Down
20 changes: 10 additions & 10 deletions apps/mobile_app/src/modules/my_spaces/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,28 @@ export const lastVisitedSpaces: TSpaceListItem[] = [
{
icon: "🏠",
lastActivity: {
sender: "nicknick",
message: "I'm back home",
sender: "luka",
message: "Get ready for the party",
},
name: "Thule32",
name: "Thule45",
themeColorHexaCode: template.colors.purple,
},
{
icon: "🏓",
lastActivity: {
sender: "nicknick",
message: "I'm back home",
sender: "luka",
message: "Have you seen my ping..",
},
name: "Thule32",
name: "Pingpongparkparty",
themeColorHexaCode: "#212078",
},
{
icon: "🍺",
lastActivity: {
sender: "nicknick",
message: "I'm back home",
sender: "pia",
message: "Let's meet here",
},
name: "Thule32",
name: "beer garden",
themeColorHexaCode: "#69701e",
},
].map((data) => ({ type: "space", data, spaceType: "lastVisited" }));
Expand All @@ -35,7 +35,7 @@ export const subscribedSpaces: TSpaceListItem[] = [
{
icon: "🍺",
lastActivity: {
sender: "nicknick",
sender: "niko",
message: "I'm back home",
},
name: "Thule32",
Expand Down
18 changes: 10 additions & 8 deletions apps/mobile_app/src/screens/Here.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ export const HereScreen: FC<BottomTabScreenProps<TabsParamList, "Here">> = ({
// const { location } = useLocation();
const location = { latitude: 52.554357, longitude: 13.420848 };

console.log("hello world");
console.log("location :>> ", location);
const [
{ data: spaces, isLoading, refetch: refetchSpaces, status, error },
{ data: address, refetch: refetchAddress },
Expand All @@ -37,7 +35,6 @@ export const HereScreen: FC<BottomTabScreenProps<TabsParamList, "Here">> = ({
{
queryKey: ["spaces by location", location],
queryFn: () => {
console.log("hello world");
return getSpacesByLocation(location as Location, maxNumberItems);
},
enabled: !!location,
Expand All @@ -50,9 +47,6 @@ export const HereScreen: FC<BottomTabScreenProps<TabsParamList, "Here">> = ({
],
});

console.log("status :>> ", status);
console.log("error :>> ", error);

const onRefresh = useCallback(async () => {
setRefreshing(true);
await Promise.allSettled([refetchAddress(), refetchSpaces()]);
Expand Down Expand Up @@ -87,8 +81,14 @@ export const HereScreen: FC<BottomTabScreenProps<TabsParamList, "Here">> = ({
onRefresh={onRefresh}
refreshing={refreshing}
keyExtractor={(item) => item.id}
renderItem={({ item }) => {
return <SpaceItem data={item} navigation={navigation} />;
renderItem={({ item, index }) => {
return (
<SpaceItem
data={item}
navigation={navigation}
emojy={emojies[index]}
/>
);
}}
contentContainerStyle={{
paddingHorizontal: (template.paddings.md * 2) / 3,
Expand All @@ -101,6 +101,8 @@ export const HereScreen: FC<BottomTabScreenProps<TabsParamList, "Here">> = ({
);
};

const emojies = ["🏠", "🏢", "🏡", "🏣", "🏥", "🏦", "🏨", "🏪", "🏫", "🏬"];

const HeaderCenterElement: FC<{ addressSmall?: string }> = ({
addressSmall,
}) => {
Expand Down
4 changes: 2 additions & 2 deletions apps/mobile_app/src/screens/spaces/Info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const SpaceInfoScreen: FC<{ spaceId: Uuid }> = ({ spaceId }) => {
</Section>
<Section headingText="Location">
<View style={{ gap: 10 }}>
<Text>Thulestr. 32, 131389 Berlin</Text>
<Text>Baumbachstr. 5, 13189 Berlin</Text>
<Map
style={{
width: "100%",
Expand Down Expand Up @@ -130,7 +130,7 @@ export const SpaceInfoScreen: FC<{ spaceId: Uuid }> = ({ spaceId }) => {
<Section headingText="Admin">
<View style={{ flexDirection: "row", alignItems: "center", gap: 10 }}>
<Avatar />
<Text style={{ fontWeight: template.fontWeight.bold }}>nikoko</Text>
<Text style={{ fontWeight: template.fontWeight.bold }}>niko</Text>
</View>
</Section>
<Section headingText="Category">
Expand Down
2 changes: 1 addition & 1 deletion apps/mobile_app/src/utils/get_api_url.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const getApiUrl = () => {
return `${process.env.EXPO_PUBLIC_API_URL}/api`;
return `${process.env.EXPO_PUBLIC_API_URL}/v1`;
};
4 changes: 2 additions & 2 deletions services/server/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ unit:
test: unit integration e2e

develop:
air
docker compose --profile dev up --build

migrate:
migrate -path=./pkg/postgres/migrations/ -database "postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:5432/${DB_NAME}?sslmode=disable" up

.PHONY: seed clean build develop migrate
.PHONY: seed clean build e2e integration unit test develop migrate
8 changes: 4 additions & 4 deletions services/server/fixtures/users.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
"email": "[email protected]"
},
{
"username": "przemi",
"firstName": "Przemek",
"lastName": "Borucki",
"email": "przemi@gmail.com"
"username": "pia",
"firstName": "Pia",
"lastName": "Multhaupt",
"email": "pia@gmail.com"
}
]

0 comments on commit 03f7842

Please sign in to comment.