Twitter in C

Hello everyone this is Madhurima again, a Computer Science Student (going to pursue my 5th semester soon ). This post is about my project Twitter in C for C Project Showcase. This project is developed under the guidance of Mr. Abhijith Ravuri. Its is a Twitter clone which is completely developed using C and C++. I used one file of fixed size 130 MB to act as a database for storing the data throughout the project. The file size can be increased or decreased by chagning few lines of code. This project is mostly focused on file space utilization (includes free space management) and aims at accessing data at lowest number of seeks and reads from file.

By running this project code one can sign up or sign in into application where your crdentials are stored in file in an encrypted form. After sign in, you can make a tweet, view the 100 most recent tweets tweeted by different users, view tweets of a person by entering their username, view your own tweets, like a tweet, unlike a tweet, view who liked the particular tweet, delete personal tweets, delete personal account and finally you can logout. After logout you get sign up and sign in options again.

Here are some screenshots of project output :






As I already mentioned, this project concentrates on file space utilization and accessing data in efficient ways from file. I used  data structures like Inodes, unsigned character array ( bit vector ), Inode etc.. 

A small intro to Unsigned character : Unsigned character contains all positive values which has a range from 0 to 255. Where as a signed char is same as an ordinary char has range from -128 to +127. As one char occupies 1 byte = 8 bits, 8 block statuses can be represented in one char. For example if a character value is 3 it is represented as 00000011 in bits which means first two blocks are occupied and other six blocks are empty. By using bit manipulation operators on unsigned character array we can develop a bit vector which is used for free space memory management in file. In bit vector, 0 bit represents empty block, 1 bit represents occupied block.

Inode is a data structure used to hold and maintain the growing data in file. I used inodes to store the file addresses/indexes of collection of data structures. Using arrays to store index information and inodes as extensions represents behaviour of indexed file allocation which helps in accessing only required data from required positions directly. 

I divided the file into six parts/segments as mentioned below. I divided the file into blocks, each of size 600 bytes after the bit vector.

Unsigned Character array-Bit vector
(30400 bytes)
Array of pointers pointing to all struct record
(600 bytes)
Array of pointers pointing to all struct tweet
(600 bytes)
Array of pointers to recent tweets
(600 bytes)
Array of pointers to usernames who made recent tweets
(600 bytes)
Struct tweets,Struct records, Inode extension arrays for 1x,2x indirect mapping
(n * 600 bytes)


You can find a better description about how the whole project is working and how it is managing all the data and its features in the link below :

You can find the code repo for this project through the link below :
All the code is written in one file, as I was facing hardware constraints due to which I used older versions of Visual Studio Community, where imports didn't work well between header files and C files.

Here is the video showing the working of Twitter in C (The video is little slow initially due to recording while executing the program)


I developed this project by breaking the most complex things that I thought to simpler tasks which helped me not to give up. Initially, we (our coders club batch) all did a plane Twitter clone using structure arrays or by storing in files.  When we were asked to submit the project idea for C project showcase, I thought of developing paint using mouse events, but Abhijith annayha( mentor) said it was easy to develop. Then decided to develop Blogger clone (similar to twitter but with mouse click events) and sent a proposal on it. After reviewing the proposal, Abhijith annayha suggested some more modifications on previously implemented Twitter. Earlier I used 3-4 files with growing size to store each structure. For this project it is converted to one file of fixed size created using fsutil(). Now the actual problem arised , how do I store and recognise where all the tweets are stored, where the usernames and passwords are stored in one file and how do I access them. How do I store tweets related to a user and likes related to a tweet if there count is in lakhs, how do I maintain relationship between data so that I can access them with less fseeks() and freads(). How do I reduce no of freads() and fseeks() to perform any operation in application .What if one user deletes his/her account or tweets. What do I do with that memory, do I leave it as it is, but memory which is left is wasted. I need to keep track of  each and every memory block, able to use or reuse them and able  to identify what type of data stored in those memory blocks. This all things together sounded so complex to me initially to develop as it was also exams time. Abhijith annayha suggested to develop the existing Twitter project to scale for more users instead of blogger and also said it's not for showing to people it's for learning purpose. So I broke my work to simple tasks and started working on my twitter again freshly because the previous code was a mess due to improper use of functions. I was into giving it up many times thinking I can't finish the basic working of my  project anyway by deadline and why wasting my exam prep time as I can complete my project even after exams. But talking to my coding mates helped me. I was confused at lots of places, took my mentors and seniors help to remove bugs from it. And finally I did it on time. It has lots of scope to make improvement like refactoring, using threads, making it to work like a server app etc...

Thank you for all who guided and supported me for this project .

Thank you :)

Comments

  1. Well , to be frank , I am very much surprised with the project . I really like it . keep it up .

    ReplyDelete
  2. Awesome work. Really impressed.

    ReplyDelete
  3. Do you only work in c madhurima ji ??
    why dont you try other mvc frameworks like ruby on rails or django

    ReplyDelete
    Replies
    1. No. I work with other languages as well like c++, python, php etc....
      Yes, I am looking forward to learn django web framework as I am familiar with python.
      Thank you for the suggestion.

      Delete

Post a Comment

Popular Posts